diff --git a/sync_pre_commit_deps.py b/sync_pre_commit_deps.py index 569f17c..a0821fb 100644 --- a/sync_pre_commit_deps.py +++ b/sync_pre_commit_deps.py @@ -10,6 +10,9 @@ 'black', 'flake8', 'mypy', 'eslint', 'csslint', 'fixmyjs', 'jshint', 'prettier', }) +SYNCED_DEPENDENCIES = { + '@eslint/js': 'eslint', +} _SEPS = ('==', '@') _RE_SEP = re.compile(rf'^(.+)({"|".join(_SEPS)})(.+)$') @@ -74,16 +77,20 @@ def main(argv: Sequence[str] | None = None) -> int: for i, dep in enumerate(hook.get('additional_dependencies', ())): if match := _RE_SEP.match(dep): name, sep, cur_version = match.groups() - target_version = versions.get(name, cur_version) + target_version = versions.get( + SYNCED_DEPENDENCIES.get(name, name), cur_version, + ) if target_version != cur_version: updated_dep = f'{name}{sep}{target_version}' hook['additional_dependencies'][i] = updated_dep - updated.append((hook['id'], name)) + updated.append((hook['id'], dep, updated_dep)) if updated: print(f'Writing updates to {filename}:') - for hid, name in updated: - print(f'\tSetting {hid!r} dependency {name!r} to {versions[name]}') + for hid, old_dep, updated_dep in updated: + print( + f'\tSetting {hid!r} dependency {old_dep!r} to {updated_dep!r}', + ) with open(filename, 'w+') as f: yaml.dump(loaded, f) diff --git a/tests/sync_pre_commit_deps_test.py b/tests/sync_pre_commit_deps_test.py index 9038628..4a55ad2 100644 --- a/tests/sync_pre_commit_deps_test.py +++ b/tests/sync_pre_commit_deps_test.py @@ -98,7 +98,7 @@ def test_main_noop(tmpdir, s): assert f.read() == s -def test_main_writes_all(tmpdir): +def test_main_writes_all(tmpdir, capsys): cfg = tmpdir.join('.pre-commit-config.yaml') cfg.write( 'repos:\n' @@ -130,6 +130,7 @@ def test_main_writes_all(tmpdir): ' - id: eslint\n' ' additional_dependencies:\n' ' - eslint@8.38.0\n' + ' - "@eslint/js==8.38.0"\n' # all repos below should have their additional_dependencies rewritten '- repo: https://github.com/asottile/yesqa\n' ' rev: v1.5.0\n' @@ -185,6 +186,7 @@ def test_main_writes_all(tmpdir): ' - id: eslint\n' ' additional_dependencies:\n' ' - eslint@8.39.0\n' + ' - "@eslint/js==8.39.0"\n' '- repo: https://github.com/asottile/yesqa\n' ' rev: v1.5.0\n' ' hooks:\n' @@ -213,6 +215,10 @@ def test_main_writes_all(tmpdir): ' - mypy==1.13.0\n' ) + out = capsys.readouterr().out + assert "'eslint@8.38.0' to 'eslint@8.39.0'" in out + assert "'@eslint/js==8.38.0' to '@eslint/js==8.39.0'" in out + def test_main_no_dep_on_one_and_writes_other(tmpdir): cfg = tmpdir.join('.pre-commit-config.yaml')