-
Notifications
You must be signed in to change notification settings - Fork 17
chore: add drf-lint pre-commit hook with baseline #5498
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| --- | ||
| # See https://pre-commit.com for more information | ||
| # See https://pre-commit.com/hooks.html for more hooks | ||
| ci: | ||
| skip: | ||
| - prettier-django | ||
| # Because these are local hooks it seems like they won't easily run in pre-commit CI | ||
| - eslint | ||
| - scss-lint | ||
| repos: | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v4.4.0 | ||
| hooks: | ||
| - id: trailing-whitespace | ||
| - id: end-of-file-fixer | ||
| exclude: ".hbs$" | ||
| - id: check-yaml | ||
| - id: check-added-large-files | ||
| - id: check-merge-conflict | ||
| - id: check-toml | ||
| - id: debug-statements | ||
| - repo: https://github.com/pre-commit/mirrors-prettier | ||
| rev: v3.0.3 | ||
| hooks: | ||
| - id: prettier | ||
| types_or: | ||
| [javascript, jsx, ts, tsx, json, scss, sass, css, yaml, markdown] | ||
| args: | ||
| - --no-config | ||
| - --no-semi | ||
| - id: prettier | ||
| alias: prettier-django | ||
| name: prettier-django | ||
| types: [html] | ||
| additional_dependencies: | ||
| - prettier | ||
| - prettier-plugin-django-alpine | ||
| - repo: https://github.com/psf/black | ||
| rev: 23.7.0 | ||
| hooks: | ||
| - id: black | ||
| - repo: https://github.com/scop/pre-commit-shfmt | ||
| rev: v3.7.0-1 | ||
| hooks: | ||
| - id: shfmt | ||
| - repo: https://github.com/adrienverge/yamllint.git | ||
| rev: v1.32.0 | ||
| hooks: | ||
| - id: yamllint | ||
| args: [--format, parsable, -d, relaxed] | ||
| - repo: https://github.com/Yelp/detect-secrets | ||
| rev: v1.4.0 | ||
| hooks: | ||
| - id: detect-secrets | ||
| args: | ||
| - --baseline | ||
| - .secrets.baseline | ||
| - --exclude-files | ||
| - .yarn/ | ||
| - --exclude-files | ||
| - cassettes/ | ||
| - --exclude-files | ||
| - test_json/ | ||
| - --exclude-files | ||
| - ".*_test.py" | ||
| - --exclude-files | ||
| - "test_.*.py" | ||
| - --exclude-files | ||
| - poetry.lock | ||
| - --exclude-files | ||
| - yarn.lock | ||
| - --exclude-files | ||
| - ".*/generated/" | ||
| - repo: https://github.com/astral-sh/ruff-pre-commit | ||
| rev: "v0.0.287" | ||
| hooks: | ||
| - id: ruff | ||
| args: [--extend-ignore=D1, --fix] | ||
| - repo: local | ||
| hooks: | ||
| - id: eslint | ||
| name: eslint | ||
| description: "Lint JS/TS files and apply automatic fixes" | ||
| entry: npx eslint --fix | ||
| language: node | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The local language: system |
||
| types_or: [javascript, jsx, ts, tsx] | ||
| args: [] | ||
| exclude: "(node_modules/|.yarn/)" | ||
| require_serial: false | ||
| - id: scss-lint | ||
| name: scss-lint | ||
| description: "Lint SCSS files" | ||
| entry: npx stylelint --allow-empty-input --fix $@ | ||
| language: node | ||
|
Comment on lines
+93
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the entry: npx stylelint --allow-empty-input --fix
language: system |
||
| types: [scss] | ||
| args: [] | ||
| exclude: node_modules/ | ||
| require_serial: false | ||
| - repo: https://github.com/shellcheck-py/shellcheck-py | ||
| rev: v0.9.0.5 | ||
| hooks: | ||
| - id: shellcheck | ||
| args: ["--severity=warning"] | ||
| - repo: local | ||
| hooks: | ||
| - id: drf-serializer-orm-check | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - id: drf-serializer-orm-check
args: ["--baseline", "drf_lint_baseline.json"] |
||
| name: DRF Serializer ORM Check | ||
| description: "Detects Django ORM queries inside DRF serializer methods (N+1 risk)" | ||
| entry: drf-lint | ||
| args: [--baseline, drf_lint_baseline.json] | ||
| language: python | ||
| files: 'serializers\.py$' | ||
| additional_dependencies: | ||
| - mitol-drf-lint | ||
|
sentry[bot] marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [ | ||
| "cms/serializers.py:64:30:ORM002", | ||
| "cms/serializers.py:71:12:ORM002", | ||
| "courses/catalog_serializers.py:102:17:ORM002", | ||
| "courses/catalog_serializers.py:113:17:ORM002", | ||
| "courses/catalog_serializers.py:124:17:ORM002", | ||
| "courses/serializers.py:105:27:ORM001", | ||
| "courses/serializers.py:106:19:ORM001", | ||
| "courses/serializers.py:55:15:ORM001", | ||
| "micromasters/serializers.py:75:20:ORM002" | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,4 +77,5 @@ dev = [ | |
| "testfixtures", | ||
| "isort", | ||
| "semantic-version", | ||
| "mitol-drf-lint==2026.4.2", | ||
| ] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version of
ruffspecified (v0.0.287) is significantly outdated. It is recommended to update to a more recent version (e.g.,v0.9.7) to benefit from numerous bug fixes, new linting rules, and performance improvements.