# loki.lint.rules module

Base class for linter rules and available rule types

class RuleType(*values)

  Bases: `Enum`

  Available types for rules with increasing severity.

  INFO = 1
  WARN = 2
  SERIOUS = 3
  ERROR = 4

class GenericRule

  Bases: `object`

  Generic 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 `GenericRule` and define `type` and provide `title` (and `id`, if applicable) in `docs`. Optional configuration values can be defined in `config` together with the default value for this option. Only the relevant entry points to a rule must be implemented.

  type = None

    The rule type as one of the categories in `RuleType`

  docs = None

    `dict` with description of the rule

    Typically, this should include `"id"` and `"title"`. Allows for Python’s format specification mini-language in `"title"` to fill values using data from `config`, 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()` and `check_file()` as applicable for all entities in the given IR object.

    Parameters:

      - ast (`Sourcefile` or `Module` or `Subroutine`) – 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.