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:
objectOperater 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
parentattributes untilSourcefileis encountered.- Parameters:
obj (
Sourcefile,SubroutineorModule) – 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 (
NodeorProgramUnit) – 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
RuleNameis one of the providedidentifiers.If
iris aLeafNode, only any attached in-line comments are checked. Ifiris any other IR object, the entire subtree below this object is searched.- Parameters:
ir (
NodeorProgramUnit) – 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
ircorresponding 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: