loki.lint.rules
Base class for linter rules and available rule types
Classes
Generic interface for linter rules providing default values and the general |
|
|
Available types for rules with increasing severity. |
- class RuleType(value)
Bases:
EnumAvailable types for rules with increasing severity.
- INFO = 1
- WARN = 2
- SERIOUS = 3
- ERROR = 4
- class GenericRule
Bases:
objectGeneric interface for linter rules providing default values and the general
check()routine that calls the specific entry points to rules (subroutines, modules, and the source file).When adding a new rule, it must inherit from
GenericRuleand definetypeand providetitle(andid, if applicable) indocs. Optional configuration values can be defined inconfigtogether with the default value for this option. Only the relevant entry points to a rule must be implemented.- docs = None
dictwith description of the ruleTypically, this should include
"id"and"title". Allows for Python’s format specification mini-language in"title"to fill values using data fromconfig, with the field name corresponding to the config key.
- config = {}
Dict of configuration keys and their default values
These values can be overriden externally in the linter config file and are passed automatically to the
check()routine.
- fixable = False
Indicator for a fixable rule that implements a corresponding
fix()routine
- deprecated = False
Indicator for a deprecated rule
- replaced_by = ()
List of rules that replace the deprecated rule, where applicable
- classmethod identifiers()
Return list of strings that identify this rule
- classmethod check_module(module, rule_report, config)
Perform rule checks on module level
Must be implemented by a rule if applicable.
- classmethod check_subroutine(subroutine, rule_report, config, **kwargs)
Perform rule checks on subroutine level
Must be implemented by a rule if applicable.
- classmethod check_file(sourcefile, rule_report, config)
Perform rule checks on file level
Must be implemented by a rule if applicable.
- classmethod check(ast, rule_report, config, **kwargs)
Perform checks on all entities in the given IR object
This routine calls
check_module(),check_subroutine()andcheck_file()as applicable for all entities in the given IR object.- Parameters:
ast (
SourcefileorModuleorSubroutine) – The IR object to be checked.rule_report (
RuleReport) – The reporter object in which rule violations should be registered.config (dict) – The rule configuration, filled with externally provided configuration values or the rule’s default configuration.
- classmethod fix_module(module, rule_report, config)
Fix rule violations on module level
Must be implemented by a rule if applicable.
- classmethod fix_subroutine(subroutine, rule_report, config)
Fix rule violations on subroutine level
Must be implemented by a rule if applicable.
- classmethod fix_sourcefile(sourcefile, rule_report, config)
Fix rule violations on sourcefile level
Must be implemented by a rule if applicable.