Skip to content

Commit 6e48012

Browse files
committed
Sync @eslint/js with eslint
1 parent b296474 commit 6e48012

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

sync_pre_commit_deps.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
'black', 'flake8', 'mypy', 'eslint', 'csslint', 'fixmyjs', 'jshint',
1111
'prettier',
1212
})
13+
SYNCED_DEPENDENCIES = {
14+
'@eslint/js': 'eslint',
15+
}
1316

1417
_SEPS = ('==', '@')
1518
_RE_SEP = re.compile(rf'^(.+)({"|".join(_SEPS)})(.+)$')
@@ -74,16 +77,20 @@ def main(argv: Sequence[str] | None = None) -> int:
7477
for i, dep in enumerate(hook.get('additional_dependencies', ())):
7578
if match := _RE_SEP.match(dep):
7679
name, sep, cur_version = match.groups()
77-
target_version = versions.get(name, cur_version)
80+
target_version = versions.get(
81+
SYNCED_DEPENDENCIES.get(name, name), cur_version,
82+
)
7883
if target_version != cur_version:
7984
updated_dep = f'{name}{sep}{target_version}'
8085
hook['additional_dependencies'][i] = updated_dep
81-
updated.append((hook['id'], name))
86+
updated.append((hook['id'], dep, updated_dep))
8287

8388
if updated:
8489
print(f'Writing updates to {filename}:')
85-
for hid, name in updated:
86-
print(f'\tSetting {hid!r} dependency {name!r} to {versions[name]}')
90+
for hid, old_dep, updated_dep in updated:
91+
print(
92+
f'\tSetting {hid!r} dependency {old_dep!r} to {updated_dep!r}',
93+
)
8794

8895
with open(filename, 'w+') as f:
8996
yaml.dump(loaded, f)

tests/sync_pre_commit_deps_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_main_noop(tmpdir, s):
9898
assert f.read() == s
9999

100100

101-
def test_main_writes_all(tmpdir):
101+
def test_main_writes_all(tmpdir, capsys):
102102
cfg = tmpdir.join('.pre-commit-config.yaml')
103103
cfg.write(
104104
'repos:\n'
@@ -130,6 +130,7 @@ def test_main_writes_all(tmpdir):
130130
' - id: eslint\n'
131131
' additional_dependencies:\n'
132132
' - eslint@8.38.0\n'
133+
' - "@eslint/js==8.38.0"\n'
133134
# all repos below should have their additional_dependencies rewritten
134135
'- repo: https://github.com/asottile/yesqa\n'
135136
' rev: v1.5.0\n'
@@ -185,6 +186,7 @@ def test_main_writes_all(tmpdir):
185186
' - id: eslint\n'
186187
' additional_dependencies:\n'
187188
' - eslint@8.39.0\n'
189+
' - "@eslint/js==8.39.0"\n'
188190
'- repo: https://github.com/asottile/yesqa\n'
189191
' rev: v1.5.0\n'
190192
' hooks:\n'
@@ -213,6 +215,10 @@ def test_main_writes_all(tmpdir):
213215
' - mypy==1.13.0\n'
214216
)
215217

218+
out = capsys.readouterr().out
219+
assert "'eslint@8.38.0' to 'eslint@8.39.0'" in out
220+
assert "'@eslint/js==8.38.0' to '@eslint/js==8.39.0'" in out
221+
216222

217223
def test_main_no_dep_on_one_and_writes_other(tmpdir):
218224
cfg = tmpdir.join('.pre-commit-config.yaml')

0 commit comments

Comments
 (0)