mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
lint: Move shebang_rules out of RuleList class to generalize it.
shebang_rules was moved to custom_check.py. Also add shebang_rules only to those rules which need it.
This commit is contained in:
@@ -54,6 +54,20 @@ FILES_WITH_LEGACY_SUBJECT = {
|
||||
'zerver/tests/test_narrow.py',
|
||||
}
|
||||
|
||||
shebang_rules = [
|
||||
{'pattern': '^#!',
|
||||
'description': "zerver library code shouldn't have a shebang line.",
|
||||
'include_only': set(['zerver/'])},
|
||||
# /bin/sh and /usr/bin/env are the only two binaries
|
||||
# that NixOS provides at a fixed path (outside a
|
||||
# buildFHSUserEnv sandbox).
|
||||
{'pattern': '^#!(?! *(?:/usr/bin/env|/bin/sh)(?: |$))',
|
||||
'description': "Use `#!/usr/bin/env foo` instead of `#!/path/foo`"
|
||||
" for interpreters other than sh."},
|
||||
{'pattern': '^#!/usr/bin/env python$',
|
||||
'description': "Use `#!/usr/bin/env python3` instead of `#!/usr/bin/env python`."}
|
||||
] # type: Rule
|
||||
|
||||
trailing_whitespace_rule = {
|
||||
'pattern': r'\s+$',
|
||||
'strip': '\n',
|
||||
@@ -505,6 +519,7 @@ python_rules = RuleList(
|
||||
},
|
||||
]) + whitespace_rules + comma_whitespace_rule,
|
||||
max_length=110,
|
||||
shebang_rules=shebang_rules,
|
||||
)
|
||||
|
||||
bash_rules = RuleList(
|
||||
@@ -521,6 +536,7 @@ bash_rules = RuleList(
|
||||
'scripts/setup/configure-rabbitmq'
|
||||
]), },
|
||||
]) + whitespace_rules[0:1],
|
||||
shebang_rules=shebang_rules,
|
||||
)
|
||||
|
||||
css_rules = RuleList(
|
||||
|
||||
@@ -18,12 +18,14 @@ if False:
|
||||
class RuleList:
|
||||
"""Defines and runs custom linting rules for the specified language."""
|
||||
|
||||
def __init__(self, langs, rules, max_length=None, length_exclude=[], exclude_files_in=None):
|
||||
def __init__(self, langs, rules, max_length=None, length_exclude=[], shebang_rules=[],
|
||||
exclude_files_in=None):
|
||||
# type: (List[str], Rule, Optional[int], List[str], Rule, Optional[str]) -> None
|
||||
self.langs = langs
|
||||
self.rules = rules
|
||||
self.max_length = max_length
|
||||
self.length_exclude = length_exclude
|
||||
self.shebang_rules = shebang_rules
|
||||
# Exclude the files in this folder from rules
|
||||
self.exclude_files_in = "\\"
|
||||
|
||||
@@ -184,20 +186,7 @@ class RuleList:
|
||||
failed = True
|
||||
|
||||
if firstline:
|
||||
shebang_rules = [
|
||||
{'pattern': '^#!',
|
||||
'description': "zerver library code shouldn't have a shebang line.",
|
||||
'include_only': set(['zerver/'])},
|
||||
# /bin/sh and /usr/bin/env are the only two binaries
|
||||
# that NixOS provides at a fixed path (outside a
|
||||
# buildFHSUserEnv sandbox).
|
||||
{'pattern': '^#!(?! *(?:/usr/bin/env|/bin/sh)(?: |$))',
|
||||
'description': "Use `#!/usr/bin/env foo` instead of `#!/path/foo`"
|
||||
" for interpreters other than sh."},
|
||||
{'pattern': '^#!/usr/bin/env python$',
|
||||
'description': "Use `#!/usr/bin/env python3` instead of `#!/usr/bin/env python`."}
|
||||
] # type: Rule
|
||||
shebang_rules_to_apply = self.get_rules_applying_to_fn(fn=fn, rules=shebang_rules)
|
||||
shebang_rules_to_apply = self.get_rules_applying_to_fn(fn=fn, rules=self.shebang_rules)
|
||||
for rule in shebang_rules_to_apply:
|
||||
if re.search(rule['pattern'], firstline):
|
||||
print_err(identifier, color,
|
||||
|
||||
Reference in New Issue
Block a user