зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1647265 - mozlint: when type is 'regex', add the capability to ignore the case r=ahal
Differential Revision: https://phabricator.services.mozilla.com/D80477
This commit is contained in:
Родитель
b6a9a2ecdf
Коммит
56fbafd822
|
@ -83,6 +83,7 @@ Each ``.yml`` file must have at least one linter defined in it. Here are the sup
|
|||
* setup - A function that sets up external dependencies (optional)
|
||||
* support-files - A list of glob patterns matching configuration files (optional)
|
||||
* find-dotfiles - If set to ``true``, run on dot files (.*) (optional)
|
||||
* ignore-case - If set to ``true`` and ``type`` is regex, ignore the case (optional)
|
||||
|
||||
In addition to the above, some ``.yml`` files correspond to a single lint rule. For these, the
|
||||
following additional keys may be specified:
|
||||
|
|
|
@ -78,7 +78,7 @@ class LineType(BaseType):
|
|||
__metaclass__ = ABCMeta
|
||||
|
||||
@abstractmethod
|
||||
def condition(payload, line):
|
||||
def condition(payload, line, config):
|
||||
pass
|
||||
|
||||
def _lint_dir(self, path, config, **lintargs):
|
||||
|
@ -106,7 +106,7 @@ class LineType(BaseType):
|
|||
|
||||
errors = []
|
||||
for i, line in enumerate(lines):
|
||||
if self.condition(payload, line):
|
||||
if self.condition(payload, line, config):
|
||||
errors.append(result.from_config(config, path=path, lineno=i+1))
|
||||
|
||||
return errors
|
||||
|
@ -115,15 +115,19 @@ class LineType(BaseType):
|
|||
class StringType(LineType):
|
||||
"""Linter type that checks whether a substring is found."""
|
||||
|
||||
def condition(self, payload, line):
|
||||
def condition(self, payload, line, config):
|
||||
return payload in line
|
||||
|
||||
|
||||
class RegexType(LineType):
|
||||
"""Linter type that checks whether a regex match is found."""
|
||||
|
||||
def condition(self, payload, line):
|
||||
return re.search(payload, line)
|
||||
def condition(self, payload, line, config):
|
||||
flags = 0
|
||||
if config.get("ignore-case"):
|
||||
flags |= re.IGNORECASE
|
||||
|
||||
return re.search(payload, line, flags)
|
||||
|
||||
|
||||
class ExternalType(BaseType):
|
||||
|
|
|
@ -20,9 +20,10 @@ class MinGWCapitalization(LineType):
|
|||
self.headers = fh.read().strip().splitlines()
|
||||
self.regex = re.compile("^#include\s*<(" + "|".join(self.headers) + ")>")
|
||||
|
||||
def condition(self, payload, line):
|
||||
def condition(self, payload, line, config):
|
||||
if not line.startswith("#include"):
|
||||
return False
|
||||
|
||||
if self.regex.search(line, re.I):
|
||||
return not self.regex.search(line)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ avoid-blacklist-and-whitelist:
|
|||
include: ['.']
|
||||
type: regex
|
||||
payload: (black|white)[-_]?list
|
||||
ignore-case: true
|
||||
# same as codespell
|
||||
extensions:
|
||||
- js
|
||||
|
|
Загрузка…
Ссылка в новой задаче