diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index 3d1615fa..00000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,10 +0,0 @@ - - - - -my new repository: - -- [ ] is added to the bottom *or* with existing repos from the same account -- [ ] contains a license -- [ ] is not `language: system`, `language: script`, `language: docker`, or `language: docker_image` -- [ ] does not contain "pre-commit" in the name diff --git a/.gitignore b/.gitignore index 8a877944..8658b840 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ *.html *.pyc -*.swp -/all-hooks.json /build /node_modules diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ac94e2cd..d9af6322 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.5.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -10,42 +10,34 @@ repos: - id: name-tests-test - id: requirements-txt-fixer - repo: https://github.com/asottile/reorder-python-imports - rev: v3.12.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.15.0 + rev: v3.21.2 hooks: - id: pyupgrade - args: [--py38-plus] + args: [--py310-plus] - repo: https://github.com/hhatto/autopep8 - rev: v2.0.4 + rev: v2.3.2 hooks: - id: autopep8 - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 + rev: 7.3.0 hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.7.1 + rev: v1.19.1 hooks: - id: mypy - additional_dependencies: [types-all] -- repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.55.0 - hooks: - - id: eslint - args: [--fix] -- repo: local - hooks: - - id: no-github-dot-git - name: No need for .git for github/gitlab urls - entry: '(github|gitlab).*\.git' - files: all-repos.yaml - language: pygrep +- repo: https://github.com/biomejs/pre-commit + rev: v2.4.9 + hooks: + - id: biome-check + additional_dependencies: ["@biomejs/biome@1.8.1"] diff --git a/Makefile b/Makefile index c4a58357..81533eda 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: install-hooks build/main_bs5.css all-hooks.json index.html hooks.html +all: install-hooks build/main_bs5.css index.html hooks.html .PHONY: install-hooks install-hooks: venv @@ -7,10 +7,7 @@ install-hooks: venv build/main_bs5.css: node_modules build scss/main_bs5.scss scss/_variables.scss node_modules/.bin/sass --style=compressed --load-path=. scss/main_bs5.scss build/main_bs5.css -all-hooks.json: venv make_all_hooks.py all-repos.yaml - venv/bin/python make_all_hooks.py - -index.html hooks.html: venv all-hooks.json base.mako index.mako hooks.mako make_templates.py template_lib.py sections/*.md +index.html hooks.html: venv base.mako index.mako hooks.mako make_templates.py template_lib.py sections/*.md venv/bin/python make_templates.py venv: requirements-dev.txt Makefile @@ -28,11 +25,10 @@ node_modules: package.json push: venv venv/bin/markdown-to-presentation push \ .nojekyll README.md CNAME \ - build assets *.html *.png *.svg favicon.ico \ - all-hooks.json install-local.py + build assets *.html *.png *.svg favicon.ico clean: - rm -rf venv build node_modules *.html all-hooks.json + rm -rf venv build node_modules *.html build: mkdir -p build diff --git a/all-repos.yaml b/all-repos.yaml deleted file mode 100644 index 3d4643dd..00000000 --- a/all-repos.yaml +++ /dev/null @@ -1,244 +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-autopep8 -- 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-prettier -- 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-go -# - 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/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/charliermarsh/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 diff --git a/assets/copyable.js b/assets/copyable.js index 8aba102f..7d18e25b 100644 --- a/assets/copyable.js +++ b/assets/copyable.js @@ -1,6 +1,8 @@ -(function () { +'use strict'; + +(() => { function copyTextToClipboard(text) { - var textArea = document.createElement('textarea'); + const textArea = document.createElement('textarea'); textArea.value = text; textArea.style.position = 'fixed'; textArea.style.left = '-1'; @@ -11,17 +13,15 @@ document.execCommand('copy'); document.body.removeChild(textArea); } - var codeBlockElements = document.getElementsByClassName('copyable'); - for (var i = 0; i < codeBlockElements.length; i++) { - var block = codeBlockElements[i]; - var copyIcon = new Image(16, 16); + for (const block of document.getElementsByClassName('copyable')) { + const copyIcon = new Image(16, 16); copyIcon.setAttribute('src', './assets/copy-icon.svg'); copyIcon.setAttribute('alt', 'copy'); copyIcon.setAttribute('title', 'copy to clipboard'); block.insertBefore(copyIcon, block.children[0]); - copyIcon.addEventListener('click', function(block) { - var text = block.getElementsByTagName('pre')[0].innerText; + copyIcon.addEventListener('click', () => { + const text = block.getElementsByTagName('pre')[0].innerText; copyTextToClipboard(text); - }.bind(null, block)); + }); } })(); diff --git a/assets/filter_repos.js b/assets/filter_repos.js deleted file mode 100644 index 718cb73d..00000000 --- a/assets/filter_repos.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -(() => { - const searchInput = document.getElementById('search-hook-id'); - const selectInput = document.getElementById('select-hook-type'); - - const hooks = document.getElementById('hooks'); - const repos = hooks.getElementsByTagName('ul'); - - const filterHooks = () => { - const id = searchInput.value.toLowerCase(); - const type = selectInput.value; - - for (let i = 0; i < repos.length; i += 1) { - const repo = repos[i]; - let hasVisibleHooks = false; - const repoHooks = repo.getElementsByTagName('li'); - - if (repoHooks) { - for (let j = 0; j < repoHooks.length; j += 1) { - const repoHook = repoHooks[j]; - const hookId = repoHook.dataset.id.toLowerCase(); - const hookTypes = repoHook.dataset.types.split(', '); - - if (hookId.includes(id) && (type === '' || hookTypes.includes(type))) { - repoHook.hidden = false; - hasVisibleHooks = true; - } else { - repoHook.hidden = true; - } - } - } - - repo.hidden = !hasVisibleHooks; - hooks.querySelector(`h3[data-repo="${repo.dataset.repo}"]`).hidden = !hasVisibleHooks; - } - }; - - searchInput.addEventListener('input', filterHooks); - selectInput.addEventListener('change', filterHooks); -})(); diff --git a/base.mako b/base.mako index 72cd221f..77ba61f4 100644 --- a/base.mako +++ b/base.mako @@ -67,7 +67,7 @@ - pre-commit logo + pre-commit logo @@ -81,7 +81,7 @@
 
- + +${body} diff --git a/install-local.py b/install-local.py deleted file mode 100644 index 74bac876..00000000 --- a/install-local.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env python3 -from __future__ import annotations - -import contextlib -import hashlib -import io -import os.path -import shutil -import subprocess -import sys -import tarfile -import urllib.request -from typing import Generator - - -TGZ = ( - 'https://files.pythonhosted.org/packages/a4/e3/' - '1f067de470e3a86875ed915438dc3bd781fb0346254f541190a09472b677/' - 'virtualenv-16.7.10.tar.gz' -) -CHECKSUM = 'e88fdcb08b0ecb11da97868f463dd06275923f50d87f4b9c8b2fc0994eec40f4' -PKG_PATH = '/tmp/.virtualenv-pkg' - - -def clean(dirname: str) -> None: - if os.path.exists(dirname): - shutil.rmtree(dirname) - - -@contextlib.contextmanager -def clean_path() -> Generator[None, None, None]: - try: - yield - finally: - clean(PKG_PATH) - - -def virtualenv(path: str) -> int: - clean(PKG_PATH) - clean(path) - - print(f'Downloading {TGZ}') - tar_bytes = urllib.request.urlopen(TGZ).read() - checksum = hashlib.sha256(tar_bytes).hexdigest() - if checksum != CHECKSUM: - print( - f'Checksums did not match. ' - f'Got {checksum}, expected {CHECKSUM}.', - file=sys.stderr, - ) - return 1 - - tar_stream = io.BytesIO(tar_bytes) - with contextlib.closing(tarfile.open(fileobj=tar_stream)) as tarfile_obj: - # Chop off the first path segment to avoid having the version in - # the path - for member in tarfile_obj.getmembers(): - _, _, member.name = member.name.partition('/') - if member.name: - tarfile_obj.extract(member, PKG_PATH) - print('Done.') - - with clean_path(): - return subprocess.call(( - sys.executable, os.path.join(PKG_PATH, 'virtualenv.py'), path, - )) - - -def main() -> int: - print('*** install-local.py: this script is deprecated ***') - print('=> https://pre-commit.com/#install') - - venv_path = os.path.join(os.environ['HOME'], '.pre-commit-venv') - bin_dir = os.path.join(os.environ['HOME'], 'bin') - script_src = os.path.join(venv_path, 'bin', 'pre-commit') - script_dest = os.path.join(bin_dir, 'pre-commit') - - if sys.argv[1:] == ['uninstall']: - clean(PKG_PATH) - clean(venv_path) - if os.path.lexists(script_dest): - os.remove(script_dest) - print('Cleaned ~/.pre-commit-venv ~/bin/pre-commit') - return 0 - - if virtualenv(venv_path): - return 1 - - subprocess.check_call(( - os.path.join(venv_path, 'bin', 'pip'), 'install', 'pre-commit', - )) - - print('*' * 79) - print(f'Installing pre-commit to {script_dest}') - print('*' * 79) - - if not os.path.exists(bin_dir): - os.mkdir(bin_dir) - - # os.symlink is not idempotent - if os.path.exists(script_dest): - os.remove(script_dest) - - os.symlink(script_src, script_dest) - - if not shutil.which('pre-commit'): - print(f'It looks like {bin_dir} is not on your path') - print('You may want to add it.') - print('Often this does the trick: source ~/.profile') - - return 0 - - -if __name__ == '__main__': - raise SystemExit(main()) diff --git a/make_all_hooks.py b/make_all_hooks.py deleted file mode 100644 index 32182634..00000000 --- a/make_all_hooks.py +++ /dev/null @@ -1,62 +0,0 @@ -from __future__ import annotations - -import functools -import json -import multiprocessing -import os.path -import subprocess -import tempfile -from typing import Any - -import yaml -from pre_commit.clientlib import load_manifest - -Loader = getattr(yaml, 'CSafeLoader', yaml.SafeLoader) -fast_load = functools.partial(yaml.load, Loader=Loader) - - -def get_manifest(repo_path: str) -> tuple[bool, str, list[dict[str, Any]]]: - print(f'*** {repo_path}') - with tempfile.TemporaryDirectory() as directory: - repo_dir = os.path.join(directory, 'repo') - cmd = ('git', 'clone', '--depth', '1', '-q', repo_path, repo_dir) - subprocess.check_call(cmd) - manifest_path = os.path.join(repo_dir, '.pre-commit-hooks.yaml') - # Validate the manifest just to make sure it's ok. - manifest = load_manifest(manifest_path) - for hook in manifest: - # hooks should not set debugging `verbose: true` flag - if hook['verbose']: - print(f'{repo_path} ({hook["id"]}) sets `verbose: true`') - return False, repo_path, [] - # hooks should not set `fail-fast` breaking user expectations - if hook['fail_fast']: - print(f'{repo_path} ({hook["id"]}) sets `fail_fast: true`') - return False, repo_path, [] - # hook names should be short and not cause wrapping by default - if len(hook['name']) > 50: - print(f'{repo_path} ({hook["id"]}) has too long `name` (>50)') - return False, repo_path, [] - - with open(manifest_path) as f: - return True, repo_path, fast_load(f) - - -def main() -> int: - with open('all-repos.yaml') as f: - repos = fast_load(f) - - hooks_json = {} - with multiprocessing.Pool(4) as pool: - for ok, path, manifest in pool.imap(get_manifest, repos): - if not ok: - return 1 - hooks_json[path] = manifest - - with open('all-hooks.json', 'w') as hooks_json_file: - json.dump(hooks_json, hooks_json_file, indent=4) - return 0 - - -if __name__ == '__main__': - raise SystemExit(main()) diff --git a/make_templates.py b/make_templates.py index 2e5c2de8..aca62aed 100644 --- a/make_templates.py +++ b/make_templates.py @@ -1,9 +1,6 @@ from __future__ import annotations -import collections -import json import os.path -from typing import Any import mako.lookup import markupsafe @@ -29,13 +26,7 @@ ) -ALL_TEMPLATES = [ - filename for filename in os.listdir('.') - if filename.endswith('.mako') and filename != 'base.mako' -] - - -def get_env() -> dict[str, Any]: +def index_body() -> markupsafe.Markup: body_parts = [] for title, filename in SECTIONS: div_id, _ = os.path.splitext(os.path.basename(filename)) @@ -50,30 +41,22 @@ def get_env() -> dict[str, Any]: f'\n', ), ) - body = markupsafe.Markup().join(body_parts) + return markupsafe.Markup().join(body_parts) - all_hooks = json.loads( - open('all-hooks.json').read(), - object_pairs_hook=collections.OrderedDict, - ) - all_types = { - hook_type - for properties in all_hooks.values() - for hook_type in ( - properties[0].get('types', []) + properties[0].get('types_or', []) - ) - } - return {'all_hooks': all_hooks, 'all_types': all_types, 'body': body} + +def hooks_body() -> markupsafe.Markup: + with open('sections/hooks.md') as f: + return md(f.read()) def main() -> int: - env = get_env() - for template in ALL_TEMPLATES: - template_name, _ = os.path.splitext(template) - env['template_name'] = template_name - with open(f'{template_name}.html', 'w') as html_file: - template_obj = template_lookup.get_template(template) - html_file.write(template_obj.render(**env)) + with open('index.html', 'w') as f: + tmpl = template_lookup.get_template('index.mako') + f.write(tmpl.render(body=index_body(), template_name='index')) + + with open('hooks.html', 'w') as f: + tmpl = template_lookup.get_template('hooks.mako') + f.write(tmpl.render(body=hooks_body(), template_name='hooks')) return 0 diff --git a/package.json b/package.json index a4bd6cb4..8a5f9f53 100644 --- a/package.json +++ b/package.json @@ -2,30 +2,7 @@ "repository": "github.com/pre-commit/pre-commit.com", "license": "MIT", "dependencies": { - "bootstrap": "^5.0.0", + "bootstrap": "5.0.2", "sass": "^1.32.13" - }, - "eslintConfig": { - "extends": "eslint:recommended", - "rules": { - "indent": [ - "error", - 4 - ], - "quotes": [ - "error", - "single" - ], - "semi": [ - "error", - "always" - ] - }, - "parserOptions": { - "ecmaVersion": 6 - }, - "env": { - "browser": true - } } } diff --git a/sections/advanced.md b/sections/advanced.md index 65d30ac5..442dbff1 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` / `fail` / `pygrep` / `script` / `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,6 +352,99 @@ 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: [] +``` + ## automatically enabling pre-commit on repositories `pre-commit init-templatedir` can be used to set up a skeleton for `git`'s @@ -463,7 +548,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 +640,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 new file mode 100644 index 00000000..a045f6f6 --- /dev/null +++ b/sections/hooks.md @@ -0,0 +1,167 @@ +## featured hooks + +here are a few hand-picked repositories which provide pre-commit integrations. + +these are fairly popular and are generally known to work well in most setups! + +_this list is not intended to be exhaustive_ + +provided by the pre-commit team: +- [pre-commit/pre-commit-hooks]: a handful of language-agnostic hooks which + are universally useful! +- [pre-commit/pygrep-hooks]: a few quick regex-based hooks for a handful of + quick syntax checks +- [pre-commit/sync-pre-commit-deps]: sync pre-commit hook dependencies based + on other installed hooks +- [pre-commit/mirrors-*]: pre-commit mirrors of a handful of popular tools + +[pre-commit/pre-commit-hooks]: https://github.com/pre-commit/pre-commit-hooks +[pre-commit/pygrep-hooks]: https://github.com/pre-commit/pygrep-hooks +[pre-commit/sync-pre-commit-deps]: https://github.com/pre-commit/sync-pre-commit-deps +[pre-commit/mirrors-*]: https://github.com/orgs/pre-commit/repositories?language=&q=%22mirrors-%22+archived%3AFalse&sort= + +for python projects: +- [asottile/pyupgrade]: automatically upgrade syntax for newer versions of the + language +- [asottile/(others)]: a few other repos by the pre-commit creator +- [psf/black]: The uncompromising Python code formatter +- [hhatto/autopep8]: automatically fixes PEP8 violations +- [astral-sh/ruff-pre-commit]: the ruff linter and formatter for python +- [google/yapf]: a highly configurable python formatter +- [PyCQA/flake8]: a linter framework for python +- [PyCQA/isort]: an import sorter for python +- [PyCQA/(others)]: a few other python code quality tools +- [adamchainz/django-upgrade]: automatically upgrade your Django project code + +[asottile/pyupgrade]: https://github.com/asottile/pyupgrade +[asottile/(others)]: https://sourcegraph.com/search?q=context:global+file:%5E%5C.pre-commit-hooks%5C.yaml%24+repo:%5Egithub.com/asottile/ +[psf/black]: https://github.com/psf/black +[hhatto/autopep8]: https://github.com/hhatto/autopep8 +[astral-sh/ruff-pre-commit]: https://github.com/astral-sh/ruff-pre-commit +[google/yapf]: https://github.com/google/yapf +[PyCQA/flake8]: https://github.com/PyCQA/flake8 +[PyCQA/isort]: https://github.com/PyCQA/isort +[PyCQA/(others)]: https://sourcegraph.com/search?q=context:global+file:%5E%5C.pre-commit-hooks%5C.yaml%24+repo:%5Egithub.com/PyCQA/ +[adamchainz/django-upgrade]: https://github.com/adamchainz/django-upgrade + +for shell scripts: +- [shellcheck-py/shellcheck-py]: runs shellcheck on your scripts +- [openstack/bashate]: code style enforcement for bash programs + +[shellcheck-py/shellcheck-py]: https://github.com/shellcheck-py/shellcheck-py +[openstack/bashate]: https://github.com/openstack/bashate + +for the web: +- [biomejs/pre-commit]: a fast formatter / fixer written in rust +- [standard/standard]: linter / fixer +- [oxipng/oxipng]: optimize png files + +[biomejs/pre-commit]: https://github.com/biomejs/pre-commit +[standard/standard]: https://github.com/standard/standard +[oxipng/oxipng]: https://github.com/oxipng/oxipng + +for configuration files: +- [python-jsonschema/check-jsonschema]: check many common configurations with jsonschema +- [rhysd/actionlint]: lint your GitHub Actions workflow files +- [google/yamlfmt]: a formatter for yaml files +- [adrienverge/yamllint]: a linter for YAML files + +[python-jsonschema/check-jsonschema]: https://github.com/python-jsonschema/check-jsonschema +[rhysd/actionlint]: https://github.com/rhysd/actionlint +[google/yamlfmt]: https://github.com/google/yamlfmt +[adrienverge/yamllint]: https://github.com/adrienverge/yamllint + +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 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: +- [jorisroovers/gitlint] +- [commitizen-tools/commitizen] + +[jorisroovers/gitlint]: https://github.com/jorisroovers/gitlint +[commitizen-tools/commitizen]: https://github.com/commitizen-tools/commitizen + +for secret scanning / security: +- [gitleaks/gitleaks] +- [trufflesecurity/truffleHog] +- [thoughtworks/talisman] + +[gitleaks/gitleaks]: https://github.com/gitleaks/gitleaks +[trufflesecurity/truffleHog]: https://github.com/trufflesecurity/truffleHog +[thoughtworks/talisman]: https://github.com/thoughtworks/talisman + +for other programming languages: +- [realm/SwiftLint]: enforce Swift style and conventions +- [nicklockwood/SwiftFormat]: a formatter for Swift +- [AleksaC/terraform-py]: format and validate terraform syntax +- [rubocop/rubocop]: static analysis and formatting for Ruby +- [bufbuild/buf]: tooling for Protocol Buffers +- [sqlfluff/sqlfluff]: a modular linter and auto formatter for SQL +- [aws-cloudformation/cfn-lint]: aws CloudFormation linter +- [google/go-jsonnet]: linter / formatter for jsonnet +- [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 +[AleksaC/terraform-py]: https://github.com/AleksaC/terraform-py +[rubocop/rubocop]: https://github.com/rubocop/rubocop +[bufbuild/buf]: https://github.com/bufbuild/buf +[sqlfluff/sqlfluff]: https://github.com/sqlfluff/sqlfluff +[aws-cloudformation/cfn-lint]: https://github.com/aws-cloudformation/cfn-lint +[google/go-jsonnet]: https://github.com/google/go-jsonnet +[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 + +it's recommended to use your favorite searching tool to find existing hooks to +use in your project. + +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) + +[sourcegraph]: https://sourcegraph.com/search + +you may also find [github's search] useful as well, though its querying and +sorting capabilities are quite limited plus it requires a login: + +- repositories providing hooks: [`path:.pre-commit-hooks.yaml language:YAML`](https://github.com/search?q=path%3A.pre-commit-hooks.yaml+language%3AYAML&type=code&l=YAML) + +[github's search]: https://github.com/search + + +## adding to this page + +the previous iteration of this page was a laundry list of hooks and maintaining +quality of the listed tools was cumbersome. + +**this page is not intended to be exhaustive** + +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 `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/install.md b/sections/install.md index a7a4715f..3d6d4d85 100644 --- a/sections/install.md +++ b/sections/install.md @@ -22,18 +22,6 @@ As a 0-dependency [zipapp]: [zipapp]: https://docs.python.org/3/library/zipapp.html [github releases]: https://github.com/pre-commit/pre-commit/releases -Using [homebrew](https://brew.sh): - -```bash -brew install pre-commit -``` - -Using [conda](https://conda.io) (via [conda-forge](https://conda-forge.org)): - -```bash -conda install -c conda-forge pre-commit -``` - ## Quick start ### 1. Install pre-commit diff --git a/sections/new-hooks.md b/sections/new-hooks.md index 631d260f..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 @@ -314,6 +310,9 @@ The hook repository must contain go source code. It will be installed via and the [`entry`](#hooks-entry) should match an executable which will get installed into the `GOPATH`'s `bin` directory. +This language supports `additional_dependencies` and will pass any of the values directly to `go +install`. It can be used as a `repo: local` hook. + _changed in 2.17.0_: previously `go get ./...` was used _new in 3.0.0_: pre-commit will bootstrap `go` if it is not present. `language: golang` @@ -335,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. -_new in 2.17.0_ +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). + +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. @@ -355,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. @@ -381,27 +415,15 @@ The hook repository must be installable via `pip install .` (usually by either executable that will match the [`entry`](#hooks-entry) – usually through `console_scripts` or `scripts` in setup.py. -__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 +This language also supports `additional_dependencies` +so it can be used with [local](#repository-local-hooks) hooks. +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. ### 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` @@ -445,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. @@ -469,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 f1e660e4..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 @@ -73,6 +71,9 @@ from. =r= =c= [`repo`](_#repos-repo) =c= the repository url to `git clone` from + or one of the special sentinel values: + [`local`](#repository-local-hooks), + [`meta`](#meta-hooks). =r= =c= [`rev`](_#repos-rev) =c= the revision or tag to clone at. @@ -126,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 376f196a..05a26c61 100644 --- a/template_lib.py +++ b/template_lib.py @@ -153,7 +153,7 @@ def block_code(self, code: str, info: str | None = None) -> str: return ret -def md(s: str) -> str: +def md(s: str) -> markupsafe.Markup: html = markdown_code_blocks.highlight(s, Renderer=Renderer) # manually bless the highlighted output. return markupsafe.Markup(html)