Skip to content
Open
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
114 changes: 114 additions & 0 deletions .pre-commit-config.yaml
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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The version of ruff specified (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.

    rev: "v0.9.7"

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The local eslint hook uses language: node with npx but does not define additional_dependencies. This configuration will likely fail in the pre-commit managed environment. If the intention is to use the tools installed in the project's local node_modules, language: system should be used instead.

        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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For the scss-lint hook, the $@ placeholder is unnecessary as pre-commit automatically appends the file list to the command. Additionally, similar to the eslint hook, language: system should be used if you intend to rely on the local node_modules via npx.

        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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The drf-serializer-orm-check hook is missing the --baseline argument. Based on the PR description and the inclusion of drf_lint_baseline.json, this argument is required for the linter to ignore existing violations. Without it, the hook will report all pre-existing issues on every commit, defeating the purpose of the baseline.

      - 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
Comment thread
sentry[bot] marked this conversation as resolved.
11 changes: 11 additions & 0 deletions drf_lint_baseline.json
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"
]
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ dev = [
"testfixtures",
"isort",
"semantic-version",
"mitol-drf-lint==2026.4.2",
]
Loading
Loading