Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more linting #181

Merged
merged 1 commit into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/actions/check-links/check_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def log(*outputs, **kwargs):
print(*outputs, **kwargs)


def check_links(ignore_glob, ignore_links, links_expire):
def check_links(ignore_glob, ignore_links, links_expire): # noqa
"""Check URLs for HTML-containing files."""
python = sys.executable.replace(os.sep, "/")
cmd = f"{python} -m pytest --noconftest --check-links --check-links-cache "
Expand All @@ -29,7 +29,8 @@ def check_links(ignore_glob, ignore_links, links_expire):
cmd += f' --ignore-glob "{spec}"'
ignored.extend(glob(spec, recursive=True))

ignore_links = list(ignore_links) + [
ignore_links = [
*list(ignore_links),
"https://github.com/.*/(pull|issues)/.*",
"https://github.com/search?",
"http://localhost.*",
Expand Down Expand Up @@ -61,14 +62,14 @@ def check_links(ignore_glob, ignore_links, links_expire):
subprocess.check_output(file_cmd, shell=False)
except Exception as e:
# Return code 5 means no tests were run (no links found)
if e.returncode != 5: # type:ignore[attr-defined]
if e.returncode != 5: # type:ignore[attr-defined] # noqa
try:
log(f"\n{f} (second attempt)...\n")
subprocess.check_output(file_cmd + ["--lf"], shell=False)
subprocess.check_output([*file_cmd, "--lf"], shell=False)
except subprocess.CalledProcessError as e:
log(e.output.decode("utf-8"))
fails += 1
if fails == 3:
if fails == 3: # noqa
msg = "Found three failed links, bailing"
raise RuntimeError(msg) from e
if fails:
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/pr-script/pr_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run(cmd, **kwargs):
raise e


def run_script():
def run_script(): # noqa
"""Run a script on the target pull request URL"""
# e.g. https://github.com/foo/bar/pull/81

Expand All @@ -51,7 +51,7 @@ def run_script():
try:
script = json.loads(script)
except Exception:
pass
pass # noqa
if not isinstance(script, list):
script = [script]
if os.environ.get("PRE_COMMIT") == "true":
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repos:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.206
rev: v0.0.237
hooks:
- id: ruff
args: ["--fix"]
41 changes: 10 additions & 31 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = ["mypy>=0.990"]
test = "mypy --install-types --non-interactive {args:.}"

[tool.hatch.envs.lint]
dependencies = ["black==22.12.0", "mdformat>0.7", "ruff==0.0.206"]
dependencies = ["black==22.12.0", "mdformat>0.7", "ruff==0.0.237"]
detached = true
[tool.hatch.envs.lint.scripts]
style = [
Expand Down Expand Up @@ -75,42 +75,21 @@ target-version = ["py38"]
target-version = "py38"
line-length = 100
select = [
"A", "B", "C", "E","EM", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
"UP", "W", "YTT",
"A", "B", "C", "DTZ", "E", "EM", "F", "FBT", "I", "ICN", "ISC", "N",
"PLC", "PLE", "PLR", "PLW", "Q", "RUF", "S", "SIM", "T", "TID", "UP",
"W", "YTT",
]
ignore = [
# Allow non-abstract empty methods in abstract base classes
"B027",
# Ignore McCabe complexity
"C901",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Use of `assert` detected
"S101",
# Line too long
"E501",
# Relative imports are banned
"TID252",
# Boolean ... in function definition
"FBT001", "FBT002",
# Module level import not at top of file
"E402",
# A001/A002/A003 .. is shadowing a python builtin
"A001", "A002", "A003",
# Possible hardcoded password
"S105", "S106",
# Q000 Single quotes found but double quotes preferred
"Q000",
# N806 Variable `B` in function should be lowercase
"N806",
# FBT001 Boolean positional arg in function definition
"FBT001", "FBT002", "FBT003",
# E501 Line too long (158 > 100 characters)
"E501",
# SIM105 Use `contextlib.suppress(...)`
"SIM105",
# T201 `print` found
"T201",
# N802 Function name `CreateWellKnownSid` should be lowercase
"N802", "N803",
# C408 Unnecessary `dict` call (rewrite as a literal)
"C408",
# N801 Class name `directional_link` should use CapWords convention
"N801",
]
unfixable = [
# Don't touch print statements
Expand Down