From 091ca2c5394218bf4b08bd97328aada563f3343c Mon Sep 17 00:00:00 2001 From: Adam Zapletal Date: Thu, 19 Dec 2024 17:09:02 -0600 Subject: [PATCH] Run `prettier` on JavaScript via `pre-commit` This patch removes the global `djangoproject/static/*` exclude rule in `.pre-commit-config.yaml` to enable `prettier` to run on this project's JavaScript files. The `djangoproject/static/js/lib/` directory is now excluded in the `prettier` hook because there is no value in reformatting a minified JavaScript file. I also added a `.prettierrc` file to the root of the project to control JavaScript formatting. --- .pre-commit-config.yaml | 4 +++- .prettierrc | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .prettierrc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5a9e918f0..ab794f30d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -exclude: '(^djangoproject\/static\/.*$)' +exclude: '^djangoproject\/static\/(css\/|fonts\/|img\/|robots).*$' default_language_version: python: python3 repos: @@ -19,6 +19,7 @@ repos: - id: debug-statements - id: detect-private-key - id: end-of-file-fixer + exclude: '(^djangoproject\/static\/js\/lib\/.*$)' exclude_types: [json, sql] - id: file-contents-sorter files: ^(requirements/\w*.txt)$ @@ -46,6 +47,7 @@ repos: hooks: - id: prettier exclude_types: [html, json, scss] + exclude: '(^djangoproject\/static\/js\/lib\/.*$)' - repo: https://github.com/pycqa/isort rev: "5.13.2" hooks: diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..6962fc73f --- /dev/null +++ b/.prettierrc @@ -0,0 +1,11 @@ +{ + "overrides": [ + { + "files": "*.js", + "options": { + "tabWidth": 2, + "singleQuote": true + } + } + ] +}