Skip to content

Commit 7930491

Browse files
committed
Propagate/hack sourcefile information to 'fix_...' functions
1 parent d5a8e6c commit 7930491

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

loki/lint/rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ def check(cls, ast, rule_report, config, **kwargs):
175175
cls.check(member, rule_report, config, **kwargs)
176176

177177
@classmethod
178-
def fix_module(cls, module, rule_report, config):
178+
def fix_module(cls, module, rule_report, config, sourcefile=None):
179179
"""
180180
Fix rule violations on module level
181181
182182
Must be implemented by a rule if applicable.
183183
"""
184184

185185
@classmethod
186-
def fix_subroutine(cls, subroutine, rule_report, config):
186+
def fix_subroutine(cls, subroutine, rule_report, config, sourcefile=None):
187187
"""
188188
Fix rule violations on subroutine level
189189

loki/lint/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Fixer:
2323
"""
2424

2525
@classmethod
26-
def fix_module(cls, module, reports, config): # pylint: disable=unused-argument
26+
def fix_module(cls, module, reports, config, sourcefile): # pylint: disable=unused-argument
2727
"""
2828
Call `fix_module` for all rules and apply the transformations.
2929
"""
@@ -33,14 +33,14 @@ def fix_module(cls, module, reports, config): # pylint: disable=unused-argument
3333
return module
3434

3535
@classmethod
36-
def fix_subroutine(cls, subroutine, reports, config):
36+
def fix_subroutine(cls, subroutine, reports, config, sourcefile):
3737
"""
3838
Call `fix_subroutine` for all rules and apply the transformations.
3939
"""
4040
mapper = {}
4141
for report in reports:
4242
rule_config = config[report.rule.__name__]
43-
mapper.update(report.rule.fix_subroutine(subroutine, report, rule_config) or {})
43+
mapper.update(report.rule.fix_subroutine(subroutine, report, rule_config, sourcefile) or {})
4444

4545
if mapper:
4646
# Apply the changes and invalidate source objects
@@ -87,10 +87,10 @@ def fix(cls, ast, reports, config):
8787
# Depth-first traversal
8888
if hasattr(ast, 'subroutines') and ast.subroutines is not None:
8989
for routine in ast.subroutines:
90-
cls.fix_subroutine(routine, reports, config)
90+
cls.fix_subroutine(routine, reports, config, ast)
9191
if hasattr(ast, 'modules') and ast.modules is not None:
9292
for module in ast.modules:
93-
cls.fix_module(module, reports, config)
93+
cls.fix_module(module, reports, config, ast)
9494

9595
cls.fix_sourcefile(ast, reports, config)
9696

@@ -99,18 +99,18 @@ def fix(cls, ast, reports, config):
9999
# Depth-first traversal
100100
if hasattr(ast, 'subroutines') and ast.subroutines is not None:
101101
for routine in ast.subroutines:
102-
cls.fix_subroutine(routine, reports, config)
102+
cls.fix_subroutine(routine, reports, config, ast)
103103

104-
cls.fix_module(ast, reports, config)
104+
cls.fix_module(ast, reports, config, ast)
105105

106106
# Fix on subroutine level
107107
elif isinstance(ast, Subroutine):
108108
# Depth-first traversal
109109
if hasattr(ast, 'members') and ast.members is not None:
110110
for routine in ast.members:
111-
cls.fix_subroutine(routine, reports, config)
111+
cls.fix_subroutine(routine, reports, config, ast)
112112

113-
cls.fix_subroutine(ast, reports, config)
113+
cls.fix_subroutine(ast, reports, config, ast)
114114

115115
return ast
116116

0 commit comments

Comments
 (0)