loki.lint.utils
Functions
Try to determine filename of the source file for an IR object |
|
|
Utility routine that produces an identifier hash for a location in the IR |
|
Check if a Linter rule is disabled in the provided context via user annotations |
Classes
|
Operater class to fix problems reported by fixable rules. |
- class Fixer
Bases:
object
Operater class to fix problems reported by fixable rules.
- classmethod fix_module(module, reports, config, sourcefile)
Call fix_module for all rules and apply the transformations.
- classmethod fix_subroutine(subroutine, reports, config, sourcefile)
Call fix_subroutine for all rules and apply the transformations.
- classmethod fix_sourcefile(sourcefile, reports, config)
Call fix_sourcefile for all rules and apply the transformations.
- classmethod fix(ast, reports, config)
Attempt to fix problems flagged by fixable rules in the given IR object.
This routine calls fix_module, fix_subroutine and fix_file as applicable for all rules on all entities in the given IR object.
- get_filename_from_parent(obj)
Try to determine filename of the source file for an IR object
It follows
parent
attributes untilSourcefile
is encountered.- Parameters:
obj (
Sourcefile
,Subroutine
orModule
) – A source file, module or subroutine object.- Returns:
The filename if found, else None.
- Return type:
str or NoneType
- get_location_hash(location)
Utility routine that produces an identifier hash for a location in the IR
- Parameters:
location (
Node
orProgramUnit
) – The IR object for which to produce the hash- Returns:
The hash as a string or, if no hash can be created for
location
, None is returned.- Return type:
str or None
- is_rule_disabled(ir, identifiers, disabled_line_hashes=None)
Check if a Linter rule is disabled in the provided context via user annotations
This looks for comments of the form
Where
RuleName
is one of the providedidentifiers
.If
ir
is aLeafNode
, only any attached in-line comments are checked. Ifir
is any other IR object, the entire subtree below this object is searched.- Parameters:
ir (
Node
orProgramUnit
) – The IR object for which to check if a rule is disabledidentifiers (list) – A list of string identifiers via which the rule can be disabled
disabled_line_hashes (list, optional) – A list of hashes. If the first line of
ir
corresponding to the violation matches a hash in this list, the rule is disabled
- Returns:
Returns True if a rule is disabled, otherwise False
- Return type: