Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions sync_pre_commit_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@

import ruamel.yaml

SUPPORTED = frozenset({
'black', 'flake8', 'mypy', 'eslint', 'csslint', 'fixmyjs', 'jshint',
'prettier',
})
SUPPORTED = {
Copy link
Copy Markdown
Member Author

@mxr mxr May 17, 2026

Choose a reason for hiding this comment

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

Although I had to change the implementation for biomejs, I wonder if this list should change to be hook args, so we don't need to update this each time we want to add a newly supported dep.

'black': 'black',
'flake8': 'flake8',
'mypy': 'mypy',
'eslint': 'eslint',
'csslint': 'csslint',
'fixmyjs': 'fixmyjs',
'jshint': 'jshint',
'prettier': 'prettier',
'biome-check': '@biomejs/biome',
}

_SEPS = ('==', '@')
_RE_SEP = re.compile(rf'^(.+)({"|".join(_SEPS)})(.+)$')
Expand Down Expand Up @@ -61,12 +68,12 @@ def main(argv: Sequence[str] | None = None) -> int:
for repo in loaded['repos']:
if repo['repo'] not in ('local', 'meta'):
for hook in repo['hooks']:
if (hid := hook['id']) in SUPPORTED:
if (dep := SUPPORTED.get(hook['id'])) is not None:
# `mirrors-mypy` and various node revs have a 'v' prefix,
# so we have to strip that out to get the
# additional_dependency version.
cleaned_rev = repo['rev'].removeprefix('v')
versions[hid] = cleaned_rev
versions[dep] = cleaned_rev

updated = []
for repo in loaded['repos']:
Expand Down
14 changes: 14 additions & 0 deletions tests/sync_pre_commit_deps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ def test_main_writes_all(tmpdir):
' - id: eslint\n'
' additional_dependencies:\n'
' - eslint@8.38.0\n'
# gives the `@biomejs/biome` version and also has its
# additional_dependencies rewritten
'- repo: https://github.com/biomejs/pre-commit\n'
' rev: v2.4.15\n'
' hooks:\n'
' - id: biome-check\n'
' additional_dependencies:\n'
' - "@biomejs/biome@1.8.1"\n'
# all repos below should have their additional_dependencies rewritten
'- repo: https://github.com/asottile/yesqa\n'
' rev: v1.5.0\n'
Expand Down Expand Up @@ -185,6 +193,12 @@ def test_main_writes_all(tmpdir):
' - id: eslint\n'
' additional_dependencies:\n'
' - eslint@8.39.0\n'
'- repo: https://github.com/biomejs/pre-commit\n'
' rev: v2.4.15\n'
' hooks:\n'
' - id: biome-check\n'
' additional_dependencies:\n'
' - "@biomejs/biome@2.4.15"\n'
'- repo: https://github.com/asottile/yesqa\n'
' rev: v1.5.0\n'
' hooks:\n'
Expand Down
Loading