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'-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'-r', u'--rev'], {u'default': None, u'help': u'Lint files touched by the given revision(s). Works with mercurial or git.'}], [[u'-w', u'--workdir'], {u'default': False, u'action': u'store_true', u'help': u"Lint files touched by changes in the working directory (i.e haven't been committed yet). Works with mercurial or git."}]]¶
-
-
mozlint.cli.
find_linters
(linters=None)¶
-
mozlint.cli.
run
(paths, linters, fmt, rev, 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 files.
-
parse
(path)¶ Read a linter and return its LINTER definition.
Parameters: path – Path to the linter. Returns: Linter definition (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.
-
contains
(other)¶ Return True if other is a subdirectory of self or equals self.
-
exists
¶
-
finder
¶
-
isdir
¶
-
isfile
¶
-
join
(*args)¶
-
match
(patterns)¶
-
-
mozlint.pathutils.
filterpaths
(paths, include=None, exclude=None)¶ Filters a list of paths.
Given a list of paths, and a list of include and exclude directives, return the set of paths that should be linted.
Parameters: - paths – A starting list of paths to possibly lint.
- include – A list of include directives. May contain glob patterns.
- exclude – A list of exclude directives. May contain glob patterns.
Returns: A tuple containing a list of file paths to lint, and a list of file paths that should be excluded (but that the algorithm was unable to apply).
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.
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.JSONEncoder
Class for encoding :class:`~result.ResultContainer`s to json.
Usage:
json.dumps(results, cls=ResultEncoder)-
default
(o)¶
-
-
mozlint.result.
from_linter
(lintobj, **kwargs)¶ Create a
ResultContainer
from a LINTER definition.Convenience method that pulls defaults from a LINTER definition and forwards them.
Parameters: - lintobj – LINTER obj as defined in a .lint file
- kwargs – same as
ResultContainer
Returns: ResultContainer
object
mozlint.roller module¶
-
class
mozlint.roller.
LintRoller
(**lintargs)¶ Bases:
object
Registers and runs linters.
Parameters: 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, 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.
- 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:
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.
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)¶
-
-
mozlint.types.
supported_types
= {u'regex': <mozlint.types.RegexType object at 0x7ff4feff6150>, u'string': <mozlint.types.StringType object at 0x7ff4feff6110>, u'external': <mozlint.types.ExternalType object at 0x7ff4feff6190>}¶ Mapping of type string to an associated instance.