mirror of https://github.com/zulip/zulip.git
lint: Add --fix option to ./tools/lint.
Linters with the fix option are stylelint, eslint and puppet-lint.
This commit is contained in:
parent
c0ecd06f31
commit
a2de8ab44f
|
@ -22,6 +22,9 @@ def run():
|
|||
parser.add_argument('--full',
|
||||
action='store_true',
|
||||
help='Check some things we typically ignore')
|
||||
parser.add_argument('--fix',
|
||||
action='store_true',
|
||||
help='Automatically fix problems where supported')
|
||||
add_default_linter_arguments(parser)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -54,10 +57,12 @@ def run():
|
|||
linter_config.external_linter('add_class', ['tools/find-add-class'], ['js'],
|
||||
description="Compares addClass() between JavaSsript and CSS.")
|
||||
linter_config.external_linter('css', ['node', 'node_modules/.bin/stylelint'], ['css', 'scss'],
|
||||
fix_arg='--fix',
|
||||
description="Standard CSS style and formatting linter "
|
||||
"(config: .stylelintrc)")
|
||||
linter_config.external_linter('eslint', ['node', 'node_modules/.bin/eslint',
|
||||
'--quiet', '--cache', '--ext', '.js,.ts'], ['js', 'ts'],
|
||||
fix_arg='--fix',
|
||||
description="Standard JavaScript style and formatting linter"
|
||||
"(config: .eslintrc).")
|
||||
linter_config.external_linter('puppet', ['puppet', 'parser', 'validate'], ['pp'],
|
||||
|
@ -65,6 +70,7 @@ def run():
|
|||
"checking for syntax errors.")
|
||||
linter_config.external_linter('puppet-lint',
|
||||
['puppet-lint'] + PUPPET_CHECK_RULES_TO_EXCLUDE, ['pp'],
|
||||
fix_arg='--fix',
|
||||
description="Standard puppet linter"
|
||||
"(config: tools/linter_lib/exclude.py)")
|
||||
linter_config.external_linter('templates', ['tools/check-templates'], ['handlebars', 'html'],
|
||||
|
|
|
@ -11,7 +11,7 @@ import sys
|
|||
|
||||
if False:
|
||||
# See https://zulip.readthedocs.io/en/latest/testing/mypy.html#mypy-in-production-scripts
|
||||
from typing import Callable, Dict, List
|
||||
from typing import Callable, Dict, List, Optional
|
||||
|
||||
from zulint.printer import print_err, colors, BOLDRED, BLUE, GREEN, ENDC
|
||||
from zulint import lister
|
||||
|
@ -101,9 +101,9 @@ class LinterConfig:
|
|||
self.lint_descriptions[func.__name__] = func.__doc__ if func.__doc__ else "External Linter"
|
||||
return func
|
||||
|
||||
def external_linter(self, name, command, target_langs=[], pass_targets=True,
|
||||
def external_linter(self, name, command, target_langs=[], pass_targets=True, fix_arg=None,
|
||||
description="External Linter"):
|
||||
# type: (str, List[str], List[str], bool, str) -> None
|
||||
# type: (str, List[str], List[str], bool, Optional[str], str) -> None
|
||||
"""Registers an external linter program to be run as part of the
|
||||
linter. This program will be passed the subset of files being
|
||||
linted that have extensions in target_langs. If there are no
|
||||
|
@ -126,6 +126,9 @@ class LinterConfig:
|
|||
# invoking the external linter.
|
||||
return 0
|
||||
|
||||
if self.args.fix and fix_arg:
|
||||
command.append(fix_arg)
|
||||
|
||||
if pass_targets:
|
||||
full_command = command + targets
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue