-
-
Notifications
You must be signed in to change notification settings - Fork 336
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
β― Playground Link
Playground link with relevant code
π» Code
Code:
class A(object):
# comment
def replace(self, *args, **kwargs):
print(selfa)
class C(object):
''' doc string '''
def replace(self, *args, **kwargs):
print(selfa)
if something:
class B(A):
""" class docstring """
def replace(self, *args, **kwargs):
""" sfgsfd self """
print(self1)
else:
class B(A):
def replace(self, *args, **kwargs):
""" sfgsfd self """
print(self1)Pattern:
id: batch-mode-pattern
message: Class "$CN" can be batch mode pattern
severity: info
# Add batch_mode=True as a class variable (after any docstrings)
rule:
kind: class_definition
pattern: |-
class $CN($$$CBS):
$$$CBS1
utils:
is-docstring:
kind: expression_statement
has:
kind: string
not:
has:
nthChild: 2
inside:
kind: block
inside:
any:
- kind: class_definition
- kind: function_definition
nthChild: 1
transform:
CBS1R:
rewrite:
rewriters:
- add_batch_mode_no_docstring
- add_batch_mode_with_docstring
source: $$$CBS1
rewriters:
- id: add_batch_mode_no_docstring
rule:
pattern: $A
inside:
inside:
kind: class_definition
not:
matches: is-docstring
nthChild: 1
fix: |-
batch_mode = True
$A
- id: add_batch_mode_with_docstring
rule:
pattern: $A
inside:
inside:
kind: class_definition
matches: is-docstring
fix: |-
$A
batch_mode = True
fix: |-
class $CN($$$CBS):
$CBS1Rπ Actual behavior
class A(object):
# comment
batch_mode = True
def replace(self, *args, **kwargs):
print(selfa)
class C(object):
''' doc string '''
batch_mode = True
def replace(self, *args, **kwargs):
print(selfa)
if something:
class B(A):
""" class docstring """
batch_mode = True
def replace(self, *args, **kwargs):
""" sfgsfd self """
print(self1)
else:
class B(A):
batch_mode = True
def replace(self, *args, **kwargs):
""" sfgsfd self """
print(self1)Indentation of 2nd and subsequent lines is incorrect in the indented classes within if something and else
π Expected behavior
class A(object):
# comment
batch_mode = True
def replace(self, *args, **kwargs):
print(selfa)
class C(object):
''' doc string '''
batch_mode = True
def replace(self, *args, **kwargs):
print(selfa)
if something:
class B(A):
""" class docstring """
batch_mode = True
def replace(self, *args, **kwargs):
""" sfgsfd self """
print(self1)
else:
class B(A):
batch_mode = True
def replace(self, *args, **kwargs):
""" sfgsfd self """
print(self1)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working