diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aab66aec..1f2f8c10 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -10,34 +10,33 @@ repos: - id: name-tests-test - id: requirements-txt-fixer - repo: https://github.com/asottile/reorder-python-imports - rev: v3.13.0 + rev: v3.16.0 hooks: - id: reorder-python-imports - args: [--py38-plus, --add-import, 'from __future__ import annotations'] + args: [--py310-plus, --add-import, 'from __future__ import annotations'] - id: reorder-python-imports - repo: https://github.com/asottile/add-trailing-comma - rev: v3.1.0 + rev: v4.0.0 hooks: - id: add-trailing-comma - repo: https://github.com/asottile/pyupgrade - rev: v3.17.0 + rev: v3.21.2 hooks: - id: pyupgrade - args: [--py38-plus] + args: [--py310-plus] - repo: https://github.com/hhatto/autopep8 - rev: v2.3.1 + rev: v2.3.2 hooks: - id: autopep8 - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 + rev: 7.3.0 hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.2 + rev: v2.1.0 hooks: - id: mypy - repo: https://github.com/biomejs/pre-commit - rev: v0.4.0 + rev: v2.5.0 hooks: - id: biome-check - additional_dependencies: ["@biomejs/biome@1.8.1"] diff --git a/all-repos.yaml b/all-repos.yaml deleted file mode 100644 index 90eecf56..00000000 --- a/all-repos.yaml +++ /dev/null @@ -1,249 +0,0 @@ -# This file is used to generate all-hooks.json -- https://github.com/pre-commit/pre-commit-hooks -- https://github.com/pre-commit/mirrors-clang-format -- https://github.com/pre-commit/mirrors-csslint -- https://github.com/pre-commit/mirrors-eslint -- https://github.com/pre-commit/mirrors-fixmyjs -- https://github.com/pre-commit/mirrors-jshint -- https://github.com/pre-commit/mirrors-mypy -- https://github.com/pre-commit/mirrors-puppet-lint -- https://github.com/pre-commit/mirrors-scss-lint -- https://github.com/pre-commit/mirrors-yapf -- https://github.com/pre-commit/pygrep-hooks -- https://github.com/pre-commit/sync-pre-commit-deps -- https://github.com/FalconSocial/pre-commit-mirrors-pep257 -- https://github.com/FalconSocial/pre-commit-python-sorter -- https://github.com/MarketSquare/robotframework-tidy -- https://github.com/guykisel/prospector-mirror -- https://github.com/asottile/add-trailing-comma -- https://github.com/asottile/pyupgrade -- https://github.com/asottile/reorder-python-imports -- https://github.com/asottile/yesqa -- https://github.com/asottile/dead -- https://github.com/asottile/setup-cfg-fmt -- https://github.com/asottile/cheetah_lint -- https://github.com/digitalpulp/pre-commit-php -- https://github.com/elidupuis/mirrors-jscs -- https://github.com/elidupuis/mirrors-sass-lint -# - https://github.com/jumanjihouse/pre-commit-hooks -- https://github.com/jumanjihouse/pre-commit-hook-yamlfmt -- https://github.com/Lucas-C/pre-commit-hooks -# - https://github.com/Lucas-C/pre-commit-hooks-java -- https://github.com/Lucas-C/pre-commit-hooks-lxml -# - https://github.com/Lucas-C/pre-commit-hooks-markup -# - https://github.com/Lucas-C/pre-commit-hooks-nodejs -- https://github.com/Lucas-C/pre-commit-hooks-safety -- https://github.com/chriskuehl/puppet-pre-commit-hooks -- https://github.com/golangci/golangci-lint -- https://github.com/Bahjat/pre-commit-golang -- https://github.com/dnephin/pre-commit-golang -- https://github.com/troian/pre-commit-golang -- https://github.com/jstewmon/check-swagger -- https://github.com/detailyang/pre-commit-shell -- https://github.com/lovesegfault/beautysh -- https://github.com/antonbabenko/pre-commit-terraform -- https://github.com/ansible-community/ansible-lint -- https://github.com/doublify/pre-commit-clang-format -- https://github.com/doublify/pre-commit-go -- https://github.com/doublify/pre-commit-hindent -- https://github.com/doublify/pre-commit-rust -- https://github.com/awebdeveloper/pre-commit-stylelint -- https://github.com/awebdeveloper/pre-commit-tslint -- https://github.com/adrienverge/yamllint -- https://github.com/thlorenz/doctoc -- https://github.com/noahsark769/xcodeproj-sort-pre-commit-hook -- https://github.com/jorisroovers/gitlint -- https://github.com/psf/black -- https://github.com/IamTheFij/ansible-pre-commit -- https://github.com/IamTheFij/docker-pre-commit -- https://github.com/mattlqx/pre-commit-ruby -- https://github.com/mattlqx/pre-commit-sign -- https://github.com/mattlqx/pre-commit-search-and-replace -- https://github.com/pryorda/dockerfilelint-precommit-hooks -- https://github.com/alessandrojcm/commitlint-pre-commit-hook -- https://github.com/henryykt/pre-commit-perl -- https://github.com/juancarlospaco/pre-commit-nim -- https://github.com/aws-cloudformation/cfn-lint -- https://github.com/thoughtworks/talisman -- https://github.com/PyCQA/flake8 -- https://github.com/PyCQA/bandit -- https://github.com/PyCQA/pydocstyle -- https://github.com/PyCQA/pylint -- https://github.com/PyCQA/doc8 -- https://github.com/PyCQA/prospector -- https://github.com/PyCQA/isort -- https://github.com/PyCQA/docformatter -- https://github.com/PyCQA/autoflake -- https://github.com/miki725/importanize -- https://github.com/motet-a/jinjalint -- https://github.com/milin/giticket -- https://github.com/milin/gitown -- https://github.com/sqlalchemyorg/zimports -- https://github.com/peterdemin/pip-compile-multi -- https://github.com/homebysix/pre-commit-macadmin -- https://github.com/fortman/pre-commit-prometheus -- https://github.com/syntaqx/git-hooks -- https://github.com/lunarmodules/luacheck -- https://github.com/Koihik/LuaFormatter -- https://github.com/Calinou/pre-commit-luacheck -- https://github.com/belminf/pre-commit-chef -- https://github.com/pocc/pre-commit-hooks -- https://github.com/dwightgunning/pre-commit-nglint -- https://github.com/codespell-project/codespell -- https://gitlab.com/smop/pre-commit-hooks -- https://github.com/seddonym/import-linter -- https://github.com/marco-c/taskcluster_yml_validator -- https://github.com/rstcheck/rstcheck -- https://github.com/lorenzwalthert/precommit -- https://github.com/lorenzwalthert/gitignore-tidy -- https://github.com/FelixSeptem/pre-commit-golang -- https://gitlab.com/daverona/pre-commit/cpp -- https://github.com/codingjoe/relint -- https://github.com/nix-community/nixpkgs-fmt -- https://github.com/d6e/beancount-check -- https://gitlab.com/iamlikeme/nbhooks -- https://github.com/Vimjas/vint -- https://github.com/eschulte/lisp-format -- https://github.com/shellcheck-py/shellcheck-py -- https://github.com/APIDevTools/swagger-cli -- https://github.com/kynan/nbstripout -- https://gitlab.com/devopshq/gitlab-ci-linter -- https://github.com/bmorcos/pre-commit-hooks-cpp -- https://github.com/igorshubovych/markdownlint-cli -- https://github.com/TekWizely/pre-commit-golang -- https://github.com/markdownlint/markdownlint -- https://github.com/jguttman94/pre-commit-gradle -- https://github.com/Yelp/detect-secrets -- https://github.com/dmitri-lerko/pre-commit-docker-kustomize -- https://github.com/perltidy/perltidy -- https://github.com/talos-systems/conform -- https://github.com/twu/skjold -- https://github.com/commitizen-tools/commitizen -- https://github.com/gherynos/pre-commit-java -- https://github.com/lietu/go-pre-commit -- https://github.com/macisamuele/language-formatters-pre-commit-hooks -- https://github.com/jlebar/pre-commit-hooks -- https://github.com/jazzband/pip-tools -- https://github.com/pappasam/toml-sort -- https://github.com/arenadotio/pre-commit-ocamlformat -- https://github.com/hcodes/yaspeller -- https://github.com/maltzj/google-style-precommit-hook -- https://github.com/jvstein/pre-commit-dotnet-format -- https://github.com/PeterMosmans/jenkinslint -- https://github.com/nicklockwood/SwiftFormat -- https://github.com/executablebooks/mdformat -- https://gitlab.com/daverona/pre-commit/php -- https://github.com/anderseknert/pre-commit-opa -- https://github.com/radix-ai/auto-smart-commit -- https://github.com/thibaudcolas/curlylint -- https://github.com/cheshirekow/cmake-format-precommit -- https://github.com/aorumbayev/pydantic-to-schema -- https://github.com/hadialqattan/pycln -- https://github.com/nbQA-dev/nbQA -- https://github.com/Scony/godot-gdscript-toolkit -- https://github.com/avilaton/add-msg-issue-prefix-hook -- https://github.com/dustinsand/pre-commit-jvm -- https://github.com/alan-turing-institute/CleverCSV-pre-commit -- https://gitlab.com/jvenom/elixir-pre-commit-hooks -- https://github.com/Cretezy/flutter-format-pre-commit -- https://github.com/dluksza/flutter-analyze-pre-commit -- https://github.com/fluttercommunity/import_sorter -- https://github.com/editorconfig-checker/editorconfig-checker.python -- https://gitlab.com/pablodiehl/pre-commit-lua-formatter -- https://github.com/frnmst/md-toc -- https://github.com/mgedmin/check-manifest -# - https://github.com/ecugol/pre-commit-hooks-django -- https://github.com/PrincetonUniversity/blocklint -- https://github.com/python-jsonschema/check-jsonschema -- https://github.com/sirosen/texthooks -- https://github.com/snok/pep585-upgrade -- https://github.com/jendrikseipp/vulture -- https://github.com/mwouts/jupytext -- https://github.com/ejba/pre-commit-maven -- https://github.com/tfsec/tfsec -- https://github.com/yoheimuta/protolint -- https://github.com/hadolint/hadolint -- https://github.com/google/go-jsonnet -- https://github.com/google/yamlfmt -- https://github.com/guid-empty/flutter-dependency-validation-pre-commit -- https://github.com/cpplint/cpplint -- https://github.com/MarcoGorelli/absolufy-imports -- https://github.com/MarcoGorelli/auto-walrus -- https://github.com/MarcoGorelli/cython-lint -- https://github.com/domdfcoding/flake2lint -- https://github.com/dotnet/format -- https://github.com/ashwin153/pre-commit-vagrant -- https://github.com/AleksaC/hadolint-py -- https://github.com/AleksaC/circleci-cli-py -- https://github.com/AleksaC/mirrors-cfn-nag -- https://github.com/cmake-lint/cmake-lint -- https://github.com/priv-kweihmann/oelint-adv -- https://github.com/jggomez/pre-commit-android-kotlin -- https://github.com/Carreau/velin -- https://github.com/chrismgrayftsinc/jsonnetfmt -- https://github.com/zricethezav/gitleaks -- https://github.com/hugoh/pre-commit-fish -# - https://github.com/nbyl/pre-commit-license-checks -# - https://github.com/jonasbb/pre-commit-latex-hooks -- https://github.com/dfm/black_nbconvert -- https://github.com/crate-ci/typos -- https://github.com/snakemake/snakefmt -- https://github.com/regebro/pyroma -- https://github.com/tox-dev/tox-ini-fmt -- https://github.com/janosh/format-ipy-cells -- https://github.com/FalcoSuessgott/lint-gitlab-ci -- https://github.com/comkieffer/xml-linter-hook -- https://github.com/jackdewinter/pymarkdown -- https://github.com/klieret/jekyll-relative-url-check -- https://github.com/tarioch/flux-check-hook -- https://github.com/streetsidesoftware/cspell-cli -- https://github.com/rapidsai/frigate -- https://github.com/norwoodj/helm-docs -- https://github.com/sqlfluff/sqlfluff -- https://github.com/adamchainz/blacken-docs -- https://github.com/adamchainz/django-upgrade -- https://github.com/scop/pre-commit-shfmt -- https://github.com/scop/pre-commit-perlcritic -- https://github.com/BlankSpruce/gersemi -- https://github.com/realm/SwiftLint -- https://gitlab.com/bmares/check-json5 -- https://github.com/semaphor-dk/dansabel -- https://github.com/gitguardian/gg-shield -- https://github.com/JohnnyMorganz/StyLua -- https://github.com/shssoichiro/oxipng -- https://github.com/datarootsio/databooks -- https://github.com/standard/standard -- https://github.com/Sceptre/sceptrelint -- https://github.com/lyz-code/yamlfix -- https://github.com/dannysepler/rm_unneeded_f_str -- https://github.com/cmhughes/latexindent.pl -- https://github.com/sirwart/ripsecrets -- https://github.com/bagerard/graphviz-dot-hooks -- https://github.com/omnilib/ufmt -- https://github.com/daveshanley/vacuum -- https://github.com/nuztalgia/botstrap -- https://gitlab.com/adam-moss/pre-commit-trailer -- https://gitlab.com/adam-moss/pre-commit-ssh-git-signing-key -- https://github.com/astral-sh/ruff-pre-commit -- https://github.com/mrtazz/checkmake -- https://github.com/jshwi/docsig -- https://github.com/finsberg/clang-format-docs -- https://github.com/rubocop/rubocop -- https://github.com/dbt-checkpoint/dbt-checkpoint -- https://gitlab.com/engmark/vcard -- https://github.com/Data-Liberation-Front/csvlint.rb -- https://github.com/christopher-hacker/enforce-notebook-run-order -- https://github.com/mxr/unkey -- https://github.com/Mateusz-Grzelinski/actionlint-py -- https://github.com/andrewring/github-distributed-owners -- https://github.com/Mermeid-Designs/pydantic-hooks -- https://github.com/igrr/astyle_py -- https://gitlab.com/codementors/pre-commit/add-issue-number-to-conventional-commit -- https://github.com/numpy/numpydoc -- https://github.com/hakancelikdev/unimport -- https://github.com/hakancelikdev/unexport -- https://github.com/KindDragon/gn-build-py -- https://github.com/stefmolin/exif-stripper -- https://github.com/hhatto/autopep8 -- https://github.com/rhysd/actionlint -- https://github.com/hija/clean-dotenv diff --git a/biome.json b/biome.json index 03e2df98..e99b718f 100644 --- a/biome.json +++ b/biome.json @@ -1,7 +1,11 @@ { - "$schema": "https://biomejs.dev/schemas/1.4.0/schema.json", - "organizeImports": { - "enabled": false + "$schema": "https://biomejs.dev/schemas/2.4.15/schema.json", + "assist": { + "actions": { + "source": { + "organizeImports": "off" + } + } }, "formatter": { "indentStyle": "space", diff --git a/sections/advanced.md b/sections/advanced.md index cc272103..646f2ac1 100644 --- a/sections/advanced.md +++ b/sections/advanced.md @@ -101,8 +101,6 @@ aborted if there is a nonzero exit code. ### post-checkout -_new in 2.2.0_ - [git post-checkout docs](https://git-scm.com/docs/githooks#_post_checkout) post-checkout hooks run *after* a `checkout` has occurred and can be used to @@ -118,8 +116,6 @@ environment variables: ### post-commit -_new in 2.4.0_ - [git post-commit docs](https://git-scm.com/docs/githooks#_post_commit) `post-commit` runs after the commit has already succeeded so it cannot be used @@ -130,8 +126,6 @@ to prevent the commit from happening. ### post-merge -_new in 2.11.0_ - [git post-merge docs](https://git-scm.com/docs/githooks#_post_merge) `post-merge` runs after a successful `git merge`. @@ -144,8 +138,6 @@ environment variables: ### post-rewrite -_new in 2.15.0_ - [git post-rewrite docs](https://git-scm.com/docs/githooks#_post_rewrite) `post-rewrite` runs after a git command which modifies history such as @@ -280,7 +272,7 @@ For example: hooks: - id: check-requirements name: check requirements files - language: system + language: unsupported entry: python -m scripts.check_requirements --compare files: ^requirements.*\.txt$ ``` @@ -299,7 +291,7 @@ You can configure repository-local hooks by specifying the [`repo`](#repos-repo) sentinel `local`. local hooks can use any language which supports [`additional_dependencies`](#config-additional_dependencies) -or [`docker_image`](#docker_image) / [`fail`](#fail) / [`pygrep`](#pygrep) / [`script`](#script) / [`system`](#system). +or [`docker_image`](#docker_image) / [`fail`](#fail) / [`pygrep`](#pygrep) / [`unsupported`](#unsupported) / [`unsupported_script`](#unsupported_script). This enables you to install things which previously would require a trivial mirror repository. @@ -315,13 +307,13 @@ Here's an example configuration with a few `local` hooks: - id: pylint name: pylint entry: pylint - language: system + language: unsupported types: [python] require_serial: true - id: check-x name: Check X entry: ./bin/check-x.sh - language: script + language: unsupported_script files: \.x$ - id: scss-lint name: scss-lint @@ -360,8 +352,173 @@ The currently available `meta` hooks: debugging. ``` +## `pre-commit hazmat` + +"hazardous materials" + +pre-commit provides a few `entry` prefix "helpers" for unusual situations. + +in case it's not clear, using these is _usually_ a bad idea. + +_note_: hazmat helpers do not work on languages which adjust `entry` (`docker` +/ `docker_image` / `fail` / `julia` / `pygrep` / `r` / `unsupported_script`). + +### `pre-commit hazmat cd` + +_new in 4.5.0_ + +for "monorepo" usage one can use this to target a subdirectory. + +this entry prefix will cd to the target subdir and adjust filename arguments + +example usage: + +```yaml +# recommended: +# minimum_pre_commit_version: 4.5.0 +repos: +- repo: ... + rev: ... + hooks: + - id: example + alias: example-repo1 + name: example (repo1) + files: ^repo1/ + # important! ends with `--` + # important! copy `args: [...]` to entry and blank out `args: []` + entry: pre-commit hazmat cd repo1 example-bin --arg1 -- + args: [] + + - id: example + alias: example-repo2 + name: example (repo2) + files: ^repo2/ + entry: pre-commit hazmat cd repo2 example-bin --arg1 -- + args: [] + + # ... etc. +``` + +### `pre-commit hazmat ignore-exit-code` + +_new in 4.5.0_ + +it's a bad idea to introduce warning noise but this gives you a way to do it. + +example: + +```yaml +# recommended: +# minimum_pre_commit_version: 4.5.0 +repos: +- repo: ... + rev: ... + hooks: + - id: example + # important! copy `args: [...]` to entry and blank out `args: []` + entry: pre-commit hazmat ignore-exit-code example-bin --arg1 -- + args: [] + # otherwise the output will always be hidden + verbose: true +``` + +### `pre-commit hazmat n1` + +_new in 4.5.0_ + +some hooks only take one filename argument. this runs them one at a time +(which is super slow!) + +example: + +```yaml +# recommended: +# minimum_pre_commit_version: 4.5.0 +repos: +- repo: ... + rev: ... + hooks: + - id: example + # important! ends with `--` + # important! copy `args: [...]` to entry and blank out `args: []` + entry: pre-commit hazmat n1 example-bin --arg1 -- + args: [] +``` + +## usage with git 2.54+ hook configuration + +_new in 4.6.0_: pre-commit improved support for `git config`-based hooks. +a later version will change `pre-commit install` to use this approach. + +[git 2.54] introduced a new way to install git hook tools via `git config`. + +the basic gist is the following enables a hook in a git repo: + +```bash +git config set hook..event pre-push +git config set hook..command 'some command here' +``` + +an example setup with `pre-commit` might look like: + +```bash +# note, the "hook" name here is `pre-commit.pre-commit` +# for the `pre-commit` "tool" and the `pre-commit` "event" +git config set hook.pre-commit.pre-commit.event pre-commit +git config set hook.pre-commit.pre-commit.command 'pre-commit hook-impl --hook-type pre-commit --' + +# please follow that naming scheme for future compatibility with `pre-commit install` + +# an example with pre-push: +# +# git config set hook.pre-commit.pre-push.event pre-push +# git config set hook.pre-commit.pre-push.command 'pre-commit hook-impl --hook-type pre-push --' +``` + +`pre-commit hook-impl` is a "hidden" implementation command with these options: +- `--hook-type ...`: the [hook type](#supported-git-hooks) to use +- `--config ...`: (optional) path to `.pre-commit-config.yaml` +- `--skip-on-missing-config`: silently pass when a config is missing + +some interesting applications of this: + +### "global" installation of pre-commit + +with `git config set --global ...` this can automatically enable pre-commit +for all repositories: + +```bash +git config set --global hook.pre-commit.pre-commit.event pre-commit +git config set --global hook.pre-commit.pre-commit.command 'pre-commit hook-impl --hook-type pre-commit --skip-on-missing-config --' +``` + +- this setup **not recommended** as it can lead to accidentally running hooks + when interacting with an untrusted repository. +- `--skip-on-missing-config` is recommended here as arbitrary git repositories + may not have a `.pre-commit-config.yaml`. + +### always running a hook on all files + +since you can configure pre-commit as many times as you want you *could* invoke +pre-commit to run a particular hook always and on all files + +```bash +git config set hook.pre-commit.pre-commit-always.event pre-commit +git config set hook.pre-commit.pre-commit-always.command 'pre-commit run hookid --hook-stage pre-commit --all-files' +``` + +*note*: this is not recommended as it has the tendancy to be slow and deviates +from the normal expectations of pre-commit. + +[git 2.54]: https://github.blog/open-source/git/highlights-from-git-2-54/#h-config-based-hooks + ## automatically enabling pre-commit on repositories +*note*: if you are on a new-enough version of `git` you may want to use +[this approach](#global-installation-of-pre-commit) instead. + +___ + `pre-commit init-templatedir` can be used to set up a skeleton for `git`'s `init.templateDir` option. This means that any newly cloned repository will automatically have the hooks set up without the need to run @@ -463,7 +620,7 @@ If a file extension you use is not supported, please `types`, `types_or`, and `files` are evaluated together with `AND` when filtering. Tags within `types` are also evaluated using `AND`. -_new in 2.9.0_: Tags within `types_or` are evaluated using `OR`. +Tags within `types_or` are evaluated using `OR`. For example: @@ -555,7 +712,7 @@ Valid values for specific languages are listed below: windows. - node: See [nodeenv](https://github.com/ekalinin/nodeenv#advanced). - ruby: See [ruby-build](https://github.com/sstephenson/ruby-build/tree/master/share/ruby-build). -- _new in 2.21.0_ rust: `language_version` is passed to `rustup` +- rust: `language_version` is passed to `rustup` - _new in 3.0.0_ golang: use the versions on [go.dev/dl](https://go.dev/dl/) such as `1.19.5` you can set [`default_language_version`](#top_level-default_language_version) diff --git a/sections/cli.md b/sections/cli.md index 0529ae5c..56b74d76 100644 --- a/sections/cli.md +++ b/sections/cli.md @@ -6,7 +6,7 @@ All pre-commit commands take the following options: - `-c CONFIG`, `--config CONFIG`: path to alternate config file - `-h`, `--help`: show help and available options. -_new in 2.8.0_: `pre-commit` now exits with more specific codes: +`pre-commit` exits with specific codes: - `1`: a detected / expected error - `3`: an unexpected error - `130`: the process was interrupted by `^C` @@ -68,8 +68,7 @@ $ grep rev: .pre-commit-config.yaml rev: 34a269fd7650d264e4de7603157c10d0a9bb8211 # frozen: v1.25.2 ``` -_new in 2.18.0_: pre-commit will preferentially pick tags containing a `.` if -there are ties. +pre-commit will preferentially pick tags containing a `.` if there are ties. ## pre-commit clean [options] #pre-commit-clean @@ -143,7 +142,7 @@ Some example useful invocations: existing git hook scripts with pre-commit, and also installs hook environments. -_new in 2.18.0_: `pre-commit install` will now install hooks from +`pre-commit install` will install hooks from [`default_install_hook_types`](#top_level-default_install_hook_types) if `--hook-type` is not specified on the command line. @@ -178,8 +177,6 @@ Options: - `--files [FILES [FILES ...]]`: specific filenames to run hooks on. - `--from-ref FROM_REF` + `--to-ref TO_REF`: run against the files changed between `FROM_REF...TO_REF` in git. - - _new in 2.2.0_: prior to 2.2.0 the arguments were `--source` and - `--origin`. - `--hook-stage STAGE`: select a [`stage` to run](#confining-hooks-to-run-at-certain-stages). - `--show-diff-on-failure`: when hooks fail, run `git diff` directly afterward. - `-v`, `--verbose`: produce hook output independent of success. Include hook @@ -236,3 +233,11 @@ Uninstall the pre-commit script. Options: - `-t HOOK_TYPE, --hook-type HOOK_TYPE`: which hook type to uninstall. + +## pre-commit validate-config [options] [filenames ...] #pre-commit-validate-config + +Validate .pre-commit-config.yaml files + +## pre-commit validate-manifest [options] [filenames ...] #pre-commit-validate-manifest + +Validate .pre-commit-hooks.yaml files diff --git a/sections/hooks.md b/sections/hooks.md index 703bb5d3..a045f6f6 100644 --- a/sections/hooks.md +++ b/sections/hooks.md @@ -54,11 +54,11 @@ for shell scripts: for the web: - [biomejs/pre-commit]: a fast formatter / fixer written in rust - [standard/standard]: linter / fixer -- [shssoichiro/oxipng]: optimize png files +- [oxipng/oxipng]: optimize png files [biomejs/pre-commit]: https://github.com/biomejs/pre-commit [standard/standard]: https://github.com/standard/standard -[shssoichiro/oxipng]: https://github.com/shssoichiro/oxipng +[oxipng/oxipng]: https://github.com/oxipng/oxipng for configuration files: - [python-jsonschema/check-jsonschema]: check many common configurations with jsonschema @@ -75,13 +75,15 @@ for text / docs / prose: - [crate-ci/typos]: find and fix common typographical errors - [thlorenz/doctoc]: generate a table-of-contents in markdown files - [amperser/proselint]: A linter for prose. -- [markdownlint/markdownlint]: a Markdown lint tool +- [markdownlint/markdownlint]: a Markdown lint tool in Ruby +- [DavidAnson/markdownlint-cli2]: a Markdown lint tool in Node - [codespell-project/codespell]: check code for common misspellings [crate-ci/typos]: https://github.com/crate-ci/typos [thlorenz/doctoc]: https://github.com/thlorenz/doctoc [amperser/proselint]: https://github.com/amperser/proselint [markdownlint/markdownlint]: https://github.com/markdownlint/markdownlint +[DavidAnson/markdownlint-cli2]: https://github.com/DavidAnson/markdownlint-cli2 [codespell-project/codespell]: https://github.com/codespell-project/codespell for linting commit messages: @@ -112,6 +114,7 @@ for other programming languages: - [JohnnyMorganz/StyLua]: an opinionated Lua code formatter - [Koihik/LuaFormatter]: a formatter for Lua code - [mrtazz/checkmake]: linter for Makefile syntax +- [nbqa-dev/nbqa]: run common linters on Jupyter Notebooks [realm/SwiftLint]: https://github.com/realm/SwiftLint [nicklockwood/SwiftFormat]: https://github.com/nicklockwood/SwiftFormat @@ -124,6 +127,7 @@ for other programming languages: [JohnnyMorganz/StyLua]: https://github.com/JohnnyMorganz/StyLua [Koihik/LuaFormatter]: https://github.com/Koihik/LuaFormatter [mrtazz/checkmake]: https://github.com/mrtazz/checkmake +[nbqa-dev/nbqa]: https://github.com/nbQA-dev/nbQA ## finding hooks @@ -134,7 +138,7 @@ for example, here's some searches you may find useful using [sourcegraph]: - hooks which run on python files: [`file:^\.pre-commit-hooks\.yaml$ "types: [python]"`](https://sourcegraph.com/search?q=context:global+file:^\.pre-commit-hooks\.yaml%24+%22types:+[python]%22) - hooks which run on shell files: [`file:^\.pre-commit-hooks\.yaml$ "types: [shell]"`](https://sourcegraph.com/search?q=context:global+file:^\.pre-commit-hooks\.yaml%24+"types:+[shell]") -- pre-commit configurations in popular projects: [`file:^\.pre-commit-config\.yaml$`](https://sourcegraph.com/search?q=context:global+file:^\.pre-commit-hooks\.yaml%24+"types:+[shell]") +- pre-commit configurations in popular projects: [`file:^\.pre-commit-config\.yaml$`](https://sourcegraph.com/search?q=context:global+file:^\.pre-commit-hooks\.yaml) [sourcegraph]: https://sourcegraph.com/search @@ -157,7 +161,7 @@ you may send [a pull request] to expand this list however there are a few requirements you *must* follow or your PR will be closed without comment: - the tool must already be fairly popular (>500 stars) -- the tool must use a managed language (no `system` / `script` / `docker` hooks) +- the tool must use a managed language (no `unsupported` / `unsupported_script` / `docker` hooks) - the tool must operate on files [a pull request]: https://github.com/pre-commit/pre-commit.com/blob/main/sections/hooks.md diff --git a/sections/new-hooks.md b/sections/new-hooks.md index 5d8c50e3..7f21d439 100644 --- a/sections/new-hooks.md +++ b/sections/new-hooks.md @@ -4,6 +4,9 @@ installable package (gem, npm, pypi, etc.) or exposes an executable, it can be used with pre-commit. Each git repo can support as many languages/hooks as you want. +_new in 2.5.0_: `pre-commit` sets the `PRE_COMMIT=1` environment variable +during hook execution. + The hook must exit nonzero on failure or modify files. A git repo containing pre-commit plugins must contain a `.pre-commit-hooks.yaml` @@ -37,7 +40,6 @@ file that tells pre-commit: =c= [`types_or`](_#hooks-types_or) =c= (optional: default `[]`) list of file types to run on (OR). See [Filtering files with types](#filtering-files-with-types). - _new in 2.9.0_. =r= =c= [`exclude_types`](_#hooks-exclude_types) =c= (optional: default `[]`) the pattern of files to exclude. @@ -48,7 +50,7 @@ file that tells pre-commit: =r= =c= [`fail_fast`](_#hooks-fail_fast) =c= (optional: default `false`) if `true` pre-commit will stop running - hooks if this hook fails. _new in 2.16.0_. + hooks if this hook fails. =r= =c= [`verbose`](_#hooks-verbose) =c= (optional: default `false`) if `true`, forces the output of the hook to be printed even when @@ -147,18 +149,18 @@ Hello from foo hook! - [fail](#fail) - [golang](#golang) - [haskell](#haskell) +- [julia](#julia) - [lua](#lua) - [node](#node) - [perl](#perl) - [python](#python) -- [python_venv](#python_venv) - [r](#r) - [ruby](#ruby) - [rust](#rust) - [swift](#swift) - [pygrep](#pygrep) -- [script](#script) -- [system](#system) +- [unsupported](#unsupported) +- [unsupported_script](#unsupported_script) ### conda @@ -169,7 +171,7 @@ The `conda` language also supports [`additional_dependencies`](#config-additiona and will pass any of the values directly into `conda install`. This language can therefore be used with [local](#repository-local-hooks) hooks. -_new in 2.17.0_: `mamba` or `micromamba` can be used to install instead via the +`mamba` or `micromamba` can be used to install instead via the `PRE_COMMIT_USE_MAMBA=1` or `PRE_COMMIT_USE_MICROMAMBA=1` environment variables. @@ -179,8 +181,6 @@ It has been tested on linux, macOS, and windows. ### coursier -_new in 2.8.0_ - The hook repository must have a `.pre-commit-channel` folder and that folder must contain the coursier [application descriptors](https://get-coursier.io/docs/2.0.0-RC6-10/cli-install.html#application-descriptor-reference) @@ -193,16 +193,14 @@ __Support:__ `coursier` hooks are known to work on any system which has the applications you install may depend on various versions of the JVM, consult the hooks' documentation for clarification. It has been tested on linux. -_new in 2.18.0_: pre-commit now supports the `coursier` naming of the package -manager executable. +pre-commit also supports the `coursier` naming of the package manager +executable. _new in 3.0.0_: `language: coursier` hooks now support `repo: local` and `additional_dependencies`. ### dart -_new in 2.15.0_ - The hook repository must have a `pubspec.yaml` -- this must contain an `executables` section which will list the binaries that will be available after installation. Match the [`entry`](#hooks-entry) to an executable. @@ -274,8 +272,6 @@ For example: ### dotnet -_new in 2.8.0_ - dotnet hooks are installed using the system installation of the dotnet CLI. Hook repositories must contain a dotnet CLI tool which can be `pack`ed and @@ -338,9 +334,46 @@ This language supports `additional_dependencies` so it can be used as a __Support:__ haskell hooks are known to work on any system which has `cabal` installed. It has been tested on linux, macOS, and windows. -### lua +### julia + +_new in 4.1.0_ + +For configuring julia hooks, your [`entry`](#hooks-entry) should be a path to a julia source +file relative to the hook repository (optionally with arguments). + +Hooks run in an isolated package environment defined by a `Project.toml` file (optionally +with a `Manifest.toml` file) in the hook repository. If no `Project.toml` file is found the +hook is run in an empty environment. + +Julia hooks support [`additional_dependencies`](#config-additional_dependencies) which can +be used to augment, or override, the existing environment in the hooks repository. This also +means that julia can be used as a `repo: local` hook. `additional_dependencies` are passed +to `pkg> add` and should be specified using +[Pkg REPL mode syntax](https://pkgdocs.julialang.org/v1/repl/#repl-add). -_new in 2.17.0_ +Examples: + +```yaml +- id: foo-without-args + name: ... + language: julia + entry: bin/foo.jl +- id: bar-with-args + name: ... + language: julia + entry: bin/bar.jl --arg1 --arg2 +- id: baz-with-extra-deps + name: ... + language: julia + entry: bin/baz.jl + additional_dependencies: + - 'ExtraDepA@1' + - 'ExtraDepB@2.4' +``` + +__Support:__ julia hooks are known to work on any system which has `julia` installed. + +### lua Lua hooks are installed with the version of Lua that is used by Luarocks. @@ -358,8 +391,6 @@ been tested on linux, windows, and macOS and _may_ work under cygwin. ### perl -_new in 2.1.0_ - Perl hooks are installed using the system installation of [cpan](https://perldoc.perl.org/cpan), the CPAN package installer that comes with Perl. @@ -391,24 +422,8 @@ The specified dependencies will be appended to the `pip install` command. __Support:__ python hooks work without any system-level dependencies. It has been tested on linux, macOS, windows, and cygwin. -### python_venv - -_new in 2.4.0_: The `python_venv` language is now an alias to `python` since -`virtualenv>=20` creates equivalently structured environments. Previously, -this [`language`](#hooks-language) created environments using the [venv] module. - -This [`language`](#hooks-language) will be removed eventually so it is suggested to use `python` -instead. - -[venv]: https://docs.python.org/3/library/venv.html - -__Support:__ python hooks work without any system-level dependencies. It -has been tested on linux, macOS, windows, and cygwin. - ### r -_new in 2.11.0_ - This hook repository must have a `renv.lock` file that will be restored with [`renv::restore()`](https://rstudio.github.io/renv/reference/restore.html) on hook installation. If the repository is an R package (i.e. has `Type: Package` @@ -452,8 +467,8 @@ build _your_ hook repo), or the special syntax `cli:{package_name}:{package_version}` for a CLI dependency (built separately, with binaries made available for use by hooks). -_new in 2.21.0_: pre-commit will bootstrap `rust` if it is not present. -`language: rust` also now supports `language_version` +pre-commit will bootstrap `rust` if it is not present. +`language: rust` also supports `language_version` __Support:__ It has been tested on linux, Windows, and macOS. @@ -476,28 +491,32 @@ can apply the `(?i)` flag as the start of your entry, or use `args: [-i]`. For multiline matches, use `args: [--multiline]`. -_new in 2.8.0_: To require all files to match, use `args: [--negate]`. +To require all files to match, use `args: [--negate]`. __Support:__ pygrep hooks are supported on all platforms which pre-commit runs on. -### script +### unsupported -Script hooks provide a way to write simple scripts which validate files. The -[`entry`](#hooks-entry) should be a path relative to the root of the hook repository. +[anchor](__#system) +_new in 4.4.0_: previously `language: system`. the alias will be removed in a +future version + +System hooks provide a way to write hooks for system-level executables which +don't have a supported language above (or have special environment +requirements that don't allow them to run in isolation such as pylint). This hook type will not be given a virtual environment to work with – if it needs additional dependencies the consumer must install them manually. -__Support:__ the support of script hooks depend on the scripts themselves. +### unsupported_script -### system +[anchor](__#script) +_new in 4.4.0_: previously `language: script`. the alias will be removed in a +future version -System hooks provide a way to write hooks for system-level executables which -don't have a supported language above (or have special environment -requirements that don't allow them to run in isolation such as pylint). +Script hooks provide a way to write simple scripts which validate files. The +[`entry`](#hooks-entry) should be a path relative to the root of the hook repository. This hook type will not be given a virtual environment to work with – if it needs additional dependencies the consumer must install them manually. - -__Support:__ the support of system hooks depend on the executables. diff --git a/sections/plugins.md b/sections/plugins.md index 663d7f67..96cb213c 100644 --- a/sections/plugins.md +++ b/sections/plugins.md @@ -15,8 +15,6 @@ pre-commit config file describes what repositories and hooks are installed. =c= (optional: default `[pre-commit]`) a list of `--hook-type`s which will be used by default when running [`pre-commit install`](#pre-commit-install). - - _new in 2.18.0_ =r= =c= [`default_language_version`](_#top_level-default_language_version) =c= (optional: default `{}`) a mapping from language to the default @@ -129,7 +127,6 @@ repository's configuration. =c= [`types_or`](_#config-types_or) =c= (optional) override the default file types to run on (OR). See [Filtering files with types](#filtering-files-with-types). - _new in 2.9.0_. =r= =c= [`exclude_types`](_#config-exclude_types) =c= (optional) file types to exclude. diff --git a/template_lib.py b/template_lib.py index 05a26c61..72286d70 100644 --- a/template_lib.py +++ b/template_lib.py @@ -12,7 +12,7 @@ ID_RE = re.compile(r' #([a-z0-9-]+)$') -SPECIAL_CHARS_RE = re.compile('[^a-z0-9 _-]') +SPECIAL_CHARS_RE = re.compile('(&[a-z]+;|[^a-z0-9 _-])') ROW = '=r='