Skip to content

Commit

Permalink
DX: ban Ruff F821 and ISC003 in ipynb exceptions (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Dec 6, 2023
1 parent 21a1daf commit 9eceaee
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/repoma/check_dev_files/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,21 @@ def __update_ruff_settings(has_notebooks: bool) -> None:
raise PrecommitError(msg)


def __ban(
rules: Iterable[str], banned_rules: Iterable[str], enforce_multiline: bool = False
) -> Array:
"""Extend Ruff rules with new rules and filter out redundant ones.
>>> __ban(["C90", "B018"], banned_rules=["D10", "C"])
['B018']
"""
banned_set = tuple(banned_rules)
filtered = {
rule for rule in rules if not any(rule.startswith(r) for r in banned_set)
}
return to_toml_array(sorted(filtered), enforce_multiline)


def __merge_rules(*rule_sets: Iterable[str], enforce_multiline: bool = False) -> Array:
"""Extend Ruff rules with new rules and filter out redundant ones.
Expand Down Expand Up @@ -445,11 +460,16 @@ def _update_ruff_per_file_ignores(has_notebooks: bool) -> None:
"T20", # print found
"TCH00", # type-checking block
}
minimal_settings[key] = __merge_rules(
expected_rules = __merge_rules(
default_ignores,
__get_existing_nbqa_ignores(pyproject),
settings.get(key, []),
)
banned_rules = {
"F821", # identify variables that are not defined
"ISC003", # explicit-string-concatenation
}
minimal_settings[key] = __ban(expected_rules, banned_rules)
docs_dir = "docs"
if os.path.exists(docs_dir) and os.path.isdir(docs_dir):
key = f"{docs_dir}/*"
Expand Down

0 comments on commit 9eceaee

Please sign in to comment.