From 86cf27a7ed10f6855ac4c884c7cbb27a78aa7a4b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 26 Oct 2023 11:39:55 -0700 Subject: [PATCH] Add a command-line flag to disable rules. Signed-off-by: Danila Fedorin --- tools/chapel-py/chplcheck/__init__.py | 8 +++++--- tools/chapel-py/chplcheck/driver.py | 10 +++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tools/chapel-py/chplcheck/__init__.py b/tools/chapel-py/chplcheck/__init__.py index b014be04b238..aaa4f7d15fd1 100755 --- a/tools/chapel-py/chplcheck/__init__.py +++ b/tools/chapel-py/chplcheck/__init__.py @@ -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: diff --git a/tools/chapel-py/chplcheck/driver.py b/tools/chapel-py/chplcheck/driver.py index 686bb3b74223..c9fe2907a94b 100644 --- a/tools/chapel-py/chplcheck/driver.py +++ b/tools/chapel-py/chplcheck/driver.py @@ -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