# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os from collections import defaultdict from itertools import chain from json import JSONEncoder
import attr import mozpack.path as mozpath
class ResultSummary(object): """Represents overall result state from an entire lint run."""
# Store the repository root folder to be able to build # Issues relative paths to that folder if ResultSummary.root isNone:
ResultSummary.root = mozpath.normpath(root)
def has_issues_failure(self): """Returns true in case issues were detected during the lint run. Do not
consider warning issues in case `self.fail_on_warnings` is set to False. """ if self.fail_on_warnings isFalse: return any(
result.level != "warning"for result in chain(*self.issues.values())
) return len(self.issues) >= 1
@property def returncode(self): if self.has_issues_failure() or self.failed: return 1 return 0
def update(self, other): """Merge results from another ResultSummary into this one.""" for path, obj in other.issues.items():
self.issues[path].extend(obj)
self.failed_run |= other.failed_run
self.failed_setup |= other.failed_setup
self.fixed += other.fixed for k, v in other.suppressed_warnings.items():
self.suppressed_warnings[k] += v
@attr.s(slots=True, kw_only=True) class Issue(object): """Represents a single lint issue and its related metadata.
:param linter: name of the linter that flagged this error
:param path: path to the file containing the error
:param message: text describing the error
:param lineno: line number that contains the error
:param column: column containing the error
:param level: severity of the error, either 'warning'or'error' (default 'error')
:param hint: suggestion for fixing the error (optional)
:param source: source code context of the error (optional)
:param rule: name of the rule that was violated (optional)
:param lineoffset: denotes an error spans multiple lines, of the form
(<lineno offset>, <num lines>) (optional)
:param diff: a diff describing the changes that need to be made to the code """
def from_config(config, **kwargs): """Create a :class:`~result.Issue` from a linter config.
Convenience method that pulls defaults from a linter
config and forwards them.
:param config: linter config as defined in a .yml file
:param kwargs: same as :class:`~result.Issue`
:returns: :class:`~result.Issue` object """
args = {} for arg in attr.fields(Issue): if arg.init:
args[arg.name] = kwargs.get(arg.name, config.get(arg.name))
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.