mozlint package¶
Subpackages¶
Submodules¶
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'--list'], {u'dest': u'list_linters', u'default': False, u'action': u'store_true', u'help': u'List all available linters and exit.'}], [[u'-f', u'--format'], {u'dest': u'fmt', u'default': u'stylish', u'help': u"Formatter to use. Defaults to 'stylish'.", u'choices': ['compact', 'stylish', 'json', 'treeherder', 'unix']}], [[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'--fix'], {u'action': u'store_true', u'default': False, u'help': u'Fix lint errors if possible. Any errors that could not be fixed will be printed as normal.'}], [[u'--edit'], {u'action': u'store_true', u'default': False, u'help': u'Each file containing lint errors will be opened in $EDITOR one after the other.'}], [[u'extra_args'], {u'nargs': '...', u'help': u'Extra arguments that will be forwarded to the underlying linter.'}]]¶ 
- 
parse_known_args(*args, **kwargs)¶ 
- 
validate(args)¶ 
- 
 
- 
mozlint.cli.find_linters(linters=None)¶ 
- 
mozlint.cli.run(paths, linters, fmt, outgoing, workdir, edit, list_linters=None, **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:
objectReads and validates lint configuration files.
- 
parse(path)¶ 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:
objectHelper class to make comparing and matching file paths easier.
- 
contains(other)¶ Return True if other is a subdirectory of self or equals self.
- 
exists¶ 
- 
ext¶ 
- 
finder¶ 
- 
isdir¶ 
- 
isfile¶ 
- 
join(*args)¶ 
- 
match(patterns)¶ 
- 
 
- 
mozlint.pathutils.ancestors(path)¶ 
- 
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.
Parameters: - paths – A starting list of paths to possibly lint.
 - linter – A linter definition.
 - lintargs – Extra arguments passed to the linter.
 
Returns: A list of file paths to lint.
- 
mozlint.pathutils.findobject(path)¶ 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.pathutils.get_ancestors_by_name(name, path, root)¶ Returns a list of files called name in path’s ancestors, sorted from closest->furthest. This can be useful for finding relevant configuration files.
mozlint.result module¶
- 
class 
mozlint.result.ResultContainer(linter, path, message, lineno, column=None, hint=None, source=None, level=None, rule=None, lineoffset=None)¶ Bases:
objectRepresents a single lint error and its related metadata.
Parameters: - 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)
 
- 
column¶ 
- 
hint¶ 
- 
level¶ 
- 
lineno¶ 
- 
lineoffset¶ 
- 
linter¶ 
- 
message¶ 
- 
path¶ 
- 
rule¶ 
- 
source¶ 
- 
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.JSONEncoderClass for encoding :class:`~result.ResultContainer`s to json.
Usage:
json.dumps(results, cls=ResultEncoder)- 
default(o)¶ 
- 
 
- 
mozlint.result.from_config(config, **kwargs)¶ Create a
ResultContainerfrom a linter config.Convenience method that pulls defaults from a linter config and forwards them.
Parameters: - config – linter config as defined in a .yml file
 - kwargs – same as 
ResultContainer 
Returns: ResultContainerobject
mozlint.roller module¶
- 
class 
mozlint.roller.LintRoller(root, **lintargs)¶ Bases:
objectRegisters and runs linters.
Parameters: - 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).
 
- 
read(paths)¶ 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.
Parameters: - 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
 
Returns: 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:
objectAbstract base class for all types of linters.
- 
batch= False¶ 
- 
 
- 
class 
mozlint.types.ExternalType¶ Bases:
mozlint.types.BaseTypeLinter type that runs an external function.
The function is responsible for properly formatting the results into a list of
ResultContainerobjects.- 
batch= True¶ 
- 
 
- 
class 
mozlint.types.LineType¶ Bases:
mozlint.types.BaseTypeAbstract 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- 
lint(data)¶ 
- 
 
- 
class 
mozlint.types.RegexType¶ Bases:
mozlint.types.LineTypeLinter type that checks whether a regex match is found.
- 
condition(payload, line)¶ 
- 
 
- 
class 
mozlint.types.StringType¶ Bases:
mozlint.types.LineTypeLinter 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.