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 support for .gitignore to scripts/lint.py #2666

Merged
merged 2 commits into from
Jul 11, 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
5 changes: 4 additions & 1 deletion .github/workflows/reusable_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ jobs:
with:
python-version: "3.8"

- name: Install dependencies
run: |
pip install gitignore_parser

- name: Rerun lints
run: |
./scripts/lint.py
Expand Down Expand Up @@ -325,4 +329,3 @@ jobs:
shell: bash
id: expected_version
run: ./scripts/ci/cargo_deny.sh

11 changes: 8 additions & 3 deletions scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import sys
from typing import Any

from gitignore_parser import parse_gitignore

# -----------------------------------------------------------------------------

todo_pattern = re.compile(r"TODO([^(]|$)")
Expand Down Expand Up @@ -443,8 +445,6 @@ def main() -> None:

extensions = ["c", "cpp", "fbs", "h", "hpp" "html", "js", "md", "py", "rs", "sh", "toml", "txt", "wgsl", "yml"]

exclude_dirs = {"env", "renv", "venv", "venv3.10", "target", "target_ra", "target_wasm", ".nox"}

exclude_paths = {
"./CODE_STYLE.md",
"./crates/re_types_builder/src/reflection.rs", # auto-generated
Expand All @@ -454,12 +454,17 @@ def main() -> None:
"./web_viewer/re_viewer_debug.js", # auto-generated by wasm_bindgen
}

matches = parse_gitignore(".gitignore")

for root, dirs, files in os.walk(".", topdown=True):
dirs[:] = [d for d in dirs if d not in exclude_dirs]
dirs[:] = [d for d in dirs if not matches(d)]

for filename in files:
extension = filename.split(".")[-1]
if extension in extensions:
filepath = os.path.join(root, filename)
if matches(filepath):
continue
if filepath not in exclude_paths:
num_errors += lint_file(filepath, args)

Expand Down
1 change: 1 addition & 0 deletions scripts/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ PyGithub==1.58.2 # for scripts/ci/generate_pr_summary.py and scripts/ci/update_p
Pillow # for scripts/upload_image.py
tqdm
requests
gitignore_parser # handle .gitignore