mozlint package


mozlint.cli module

class mozlint.cli.MozlintParser(**kwargs)

Bases: argparse.ArgumentParser

arguments = [[[u'paths'], {u'default': None, u'nargs': u'*', u'help': u"Paths to file or directories to lint, like 'browser/components/loop' or 'mobile/android'. Defaults to the current directory if not given."}], [[u'-l', u'--linter'], {u'dest': u'linters', u'default': [], u'action': u'append', u'help': u"Linters to run, e.g 'eslint'. By default all linters are run for all the appropriate files."}], [[u'-f', u'--format'], {u'dest': u'fmt', u'default': u'stylish', u'help': u"Formatter to use. Defaults to 'stylish'."}], [[u'-n', u'--no-filter'], {u'dest': u'use_filters', u'default': True, u'action': u'store_false', u'help': u"Ignore all filtering. This is useful for quickly testing a directory that otherwise wouldn't be run, without needing to modify the config file."}], [[u'-o', u'--outgoing'], {u'nargs': u'?', u'const': u'default', u'help': u'Lint files touched by commits that are not on the remote repository. Without arguments, finds the default remote that would be pushed to. The remote branch can also be specified manually. Works with mercurial or git.'}], [[u'-w', u'--workdir'], {u'nargs': u'?', u'const': u'all', u'help': u"Lint files touched by changes in the working directory (i.e haven't been committed yet). On git, --workdir=staged can be used to only consider staged files. Works with mercurial or git.", u'choices': [u'staged', u'all']}], [[u'extra_args'], {u'nargs': '...', u'help': u'Extra arguments that will be forwarded to the underlying linter.'}]]
parse_known_args(*args, **kwargs)
mozlint.cli.find_linters(linters=None), linters, fmt, outgoing, workdir, **lintargs)

mozlint.errors module

exception mozlint.errors.LintException

Bases: exceptions.Exception

exception mozlint.errors.LinterNotFound(path)

Bases: mozlint.errors.LintException

exception mozlint.errors.LinterParseError(path, message)

Bases: mozlint.errors.LintException

exception mozlint.errors.LintersNotConfigured

Bases: mozlint.errors.LintException

mozlint.parser module

class mozlint.parser.Parser

Bases: object

Reads and validates lint configuration files.


Read a linter and return its LINTER definition.

Parameters:path – Path to the linter.
Returns:List of linter definitions ([dict])
Raises:LinterNotFound, LinterParseError
required_attributes = ('name', 'description', 'type', 'payload')

mozlint.pathutils module

class mozlint.pathutils.FilterPath(path, exclude=None)

Bases: object

Helper class to make comparing and matching file paths easier.


Return True if other is a subdirectory of self or equals self.

mozlint.pathutils.filterpaths(paths, linter, **lintargs)

Filters a list of paths.

Given a list of paths, and a linter definition plus extra arguments, return the set of paths that should be linted.

  • paths – A starting list of paths to possibly lint.
  • linter – A linter definition.
  • lintargs – Extra arguments passed to the linter.

A list of file paths to lint.


Find a Python object given a path of the form <modulepath>:<objectpath>. Conceptually equivalent to

def find_object(modulepath, objectpath):
import <modulepath> as mod return mod.<objectpath>

mozlint.result module

class mozlint.result.ResultContainer(linter, path, message, lineno, column=None, hint=None, source=None, level=None, rule=None, lineoffset=None)

Bases: object

Represents a single lint error and its related metadata.

  • linter – name of the linter that flagged this error
  • path – path to the file containing the error
  • message – text describing the error
  • lineno – line number that contains the error
  • column – column containing the error
  • level – severity of the error, either ‘warning’ or ‘error’ (default ‘error’)
  • hint – suggestion for fixing the error (optional)
  • source – source code context of the error (optional)
  • rule – name of the rule that was violated (optional)
  • lineoffset – denotes an error spans multiple lines, of the form (<lineno offset>, <num lines>) (optional)
class mozlint.result.ResultEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)

Bases: json.encoder.JSONEncoder

Class for encoding :class:`~result.ResultContainer`s to json.


json.dumps(results, cls=ResultEncoder)
mozlint.result.from_config(config, **kwargs)

Create a ResultContainer from a linter config.

Convenience method that pulls defaults from a linter config and forwards them.

  • config – linter config as defined in a .yml file
  • kwargs – same as ResultContainer

ResultContainer object

mozlint.roller module

class mozlint.roller.LintRoller(root=None, **lintargs)

Bases: object

Registers and runs linters.

  • root – Path to which relative paths will be joined. If unspecified, root will either be determined from version control or cwd.
  • lintargs – Arguments to pass to the underlying linter(s).

Parse one or more linters and add them to the registry.

Parameters:paths – A path or iterable of paths to linter definitions.
roll(paths=None, outgoing=None, workdir=None, num_procs=None)

Run all of the registered linters against the specified file paths.

  • paths – An iterable of files and/or directories to lint.
  • outgoing – Lint files touched by commits that are not on the remote repository.
  • workdir – Lint all files touched in the working directory.
  • num_procs – The number of processes to use. Default: cpu count

A dictionary with file names as the key, and a list of :class:`~result.ResultContainer`s as the value.

mozlint.types module

class mozlint.types.BaseType

Bases: object

Abstract base class for all types of linters.

batch = False
class mozlint.types.ExternalType

Bases: mozlint.types.BaseType

Linter type that runs an external function.

The function is responsible for properly formatting the results into a list of ResultContainer objects.

batch = True
class mozlint.types.LineType

Bases: mozlint.types.BaseType

Abstract base class for linter types that check each line individually.

Subclasses of this linter type will read each file and check the provided payload against each line one by one.

condition(payload, line)
class mozlint.types.LintHandler(config)

Bases: mozlog.reader.LogHandler

class mozlint.types.RegexType

Bases: mozlint.types.LineType

Linter type that checks whether a regex match is found.

condition(payload, line)
class mozlint.types.StringType

Bases: mozlint.types.LineType

Linter type that checks whether a substring is found.

condition(payload, line)
class mozlint.types.StructuredLogType

Bases: mozlint.types.BaseType

batch = True
mozlint.types.supported_types = {u'regex': <mozlint.types.RegexType object>, u'structured_log': <mozlint.types.StructuredLogType object>, u'string': <mozlint.types.StringType object>, u'external': <mozlint.types.ExternalType object>}

Mapping of type string to an associated instance.

mozlint.vcs module

class mozlint.vcs.GitHelper(root)

Bases: mozlint.vcs.VCSHelper

A helper to find files to lint from Git.

class mozlint.vcs.HgHelper(root)

Bases: mozlint.vcs.VCSHelper

A helper to find files to lint from Mercurial.

class mozlint.vcs.VCSHelper(root)

Bases: object

A base VCS helper that always returns an empty list for the case when no version control was found.

classmethod create()
classmethod find_vcs()

Module contents