Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Abraham <[email protected]>
  • Loading branch information
jabraham17 committed Oct 31, 2024
1 parent 966c4a8 commit 9063d24
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 0 additions & 1 deletion tools/chplcheck/src/chplcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ def main():
print(f" {r}")
return 2


if args.lsp:
run_lsp(driver)
return 0
Expand Down
10 changes: 8 additions & 2 deletions tools/chplcheck/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@
import argparse
import re


@dataclass(frozen=True)
class RuleSetting:
"""
Settings for an rules, these can optionally be namespaced to a specific rule
"""

setting_name: str
rule_name: Optional[str] = None

def __str__(self):
return f"{self.rule_name}.{self.setting_name}" if self.rule_name else self.setting_name
return (
f"{self.rule_name}.{self.setting_name}"
if self.rule_name
else self.setting_name
)


class RuleSettingAction(argparse.Action):
Expand Down Expand Up @@ -61,6 +67,7 @@ def __call__(self, parser, namespace, values, option_string=None):
setting_dict[setting] = setting_value
setattr(namespace, self.dest, setting_dict)


@dataclass
class Config:
"""
Expand All @@ -74,7 +81,6 @@ class Config:
add_rules: List[str]
rule_settings: Dict[RuleSetting, str]


@classmethod
def add_arguments(cls, parser: argparse.ArgumentParser, prefix: str = ""):
parser.add_argument(
Expand Down
6 changes: 4 additions & 2 deletions tools/chplcheck/src/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _check_rule(

yield from rule.check(context, root)

def basic_rule(self, pat, default:bool=True, settings: List[str]=[]):
def basic_rule(self, pat, default: bool = True, settings: List[str] = []):
"""
This method is a decorator factory for adding 'basic' rules to the
driver. A basic rule is a function returning a boolean that gets called
Expand Down Expand Up @@ -209,7 +209,9 @@ def wrapper_basic_rule(*args, **kwargs):

return decorator_fixit

def advanced_rule(self, _func=None, *, default=True, settings: List[str]=[]):
def advanced_rule(
self, _func=None, *, default=True, settings: List[str] = []
):
"""
This method is a decorator for adding 'advanced' rules to the driver.
An advanced rule is a function that gets called on a root AST node,
Expand Down
17 changes: 14 additions & 3 deletions tools/chplcheck/src/rule_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ def __init__(self, driver, name: str, settings: typing.List[str]) -> None:
self.settings = self._parse_settings(settings)
self.fixit_funcs: typing.List[FixitHook[VarResultType]] = []

def _parse_settings(self, settings_from_user: typing.List[str]) -> typing.List[RuleSetting]:
def _parse_settings(
self, settings_from_user: typing.List[str]
) -> typing.List[RuleSetting]:
settings: typing.List[RuleSetting] = []
for s in settings_from_user:
if s.startswith("."):
Expand Down Expand Up @@ -226,7 +228,12 @@ class BasicRule(Rule[BasicRuleResult]):
"""

def __init__(
self, driver, name: str, pattern: typing.Any, check_func: BasicRuleCheck, settings: typing.List[str]
self,
driver,
name: str,
pattern: typing.Any,
check_func: BasicRuleCheck,
settings: typing.List[str],
) -> None:
super().__init__(driver, name, settings)
self.pattern = pattern
Expand Down Expand Up @@ -275,7 +282,11 @@ class AdvancedRule(Rule[AdvancedRuleResult]):
"""

def __init__(
self, driver, name: str, check_func: AdvancedRuleCheck, settings: typing.List[str]
self,
driver,
name: str,
check_func: AdvancedRuleCheck,
settings: typing.List[str],
) -> None:
super().__init__(driver, name, settings)
self.check_func = check_func
Expand Down

0 comments on commit 9063d24

Please sign in to comment.