Skip to content

Commit

Permalink
Add a command-line flag to disable rules.
Browse files Browse the repository at this point in the history
Signed-off-by: Danila Fedorin <[email protected]>
  • Loading branch information
DanilaFe committed Oct 26, 2023
1 parent 5ac308c commit 86cf27a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions tools/chapel-py/chplcheck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ def print_violation(node, name):
def main():
parser = argparse.ArgumentParser( prog='chplcheck', description='A linter for the Chapel language')
parser.add_argument('filenames', nargs='*')
parser.add_argument('--ignore-rule', action='append', dest='ignored_rules', default=[])
parser.add_argument('--disable-rule', action='append', dest='disabled_rules', default=[])
parser.add_argument('--enable-rule', action='append', dest='enabled_rules', default=[])
parser.add_argument('--lsp', action='store_true', default=False)
args = parser.parse_args()

driver = LintDriver()
driver.silence_rules("CamelCaseVariables", "ConsecutiveDecls")
driver.silence_rules(*args.ignored_rules)
driver.disable_rules("CamelCaseVariables", "ConsecutiveDecls")
driver.disable_rules(*args.disabled_rules)
driver.enable_rules(*args.enabled_rules)
register_rules(driver)

if args.lsp:
Expand Down
10 changes: 9 additions & 1 deletion tools/chapel-py/chplcheck/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ def __init__(self):
self.BasicRules = []
self.AdvancedRules = []

def silence_rules(self, *rules):
def disable_rules(self, *rules):
"""
Tell the driver to silence / skip warning for the given rules.
"""

self.SilencedRules.extend(rules)

def enable_rules(self, *rules):
"""
Tell the driver to warning for the given rules even if they were
previously disabled.
"""

self.SilencedRules = list(set(self.SilencedRules) - set(rules))

def _should_check_rule(self, node, rulename):
if rulename in self.SilencedRules:
return False
Expand Down

0 comments on commit 86cf27a

Please sign in to comment.