|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import argparse |
| 4 | +import re |
4 | 5 | from collections.abc import Sequence |
5 | 6 |
|
6 | 7 | import ruamel.yaml |
7 | 8 |
|
8 | | -SUPPORTED = frozenset(('black', 'flake8', 'mypy')) |
| 9 | +SUPPORTED = frozenset({ |
| 10 | + 'black', 'flake8', 'mypy', 'eslint', 'csslint', 'fixmyjs', 'jshint', |
| 11 | + 'prettier', |
| 12 | +}) |
9 | 13 |
|
| 14 | +_SEPS = ('==', '@') |
| 15 | +_RE_SEP = re.compile(rf'^(.+)({"|".join(_SEPS)})(.+)$') |
10 | 16 |
|
11 | 17 | _ARGUMENT_HELP_TEMPLATE = ( |
12 | 18 | 'The `{}` argument to the YAML dumper. ' |
@@ -56,21 +62,23 @@ def main(argv: Sequence[str] | None = None) -> int: |
56 | 62 | if repo['repo'] not in ('local', 'meta'): |
57 | 63 | for hook in repo['hooks']: |
58 | 64 | if (hid := hook['id']) in SUPPORTED: |
59 | | - # `mirrors-mypy` uses versions with a 'v' prefix, so we |
60 | | - # have to strip it out to get the mypy version. |
| 65 | + # `mirrors-mypy` and various node revs have a 'v' prefix, |
| 66 | + # so # we have to strip that out to get the |
| 67 | + # additional_dependency version. |
61 | 68 | cleaned_rev = repo['rev'].removeprefix('v') |
62 | 69 | versions[hid] = cleaned_rev |
63 | 70 |
|
64 | 71 | updated = [] |
65 | 72 | for repo in loaded['repos']: |
66 | 73 | for hook in repo['hooks']: |
67 | 74 | for i, dep in enumerate(hook.get('additional_dependencies', ())): |
68 | | - name, _, cur_version = dep.partition('==') |
69 | | - target_version = versions.get(name, cur_version) |
70 | | - if target_version != cur_version: |
71 | | - name_and_version = f'{name}=={target_version}' |
72 | | - hook['additional_dependencies'][i] = name_and_version |
73 | | - updated.append((hook['id'], name)) |
| 75 | + if match := _RE_SEP.match(dep): |
| 76 | + name, sep, cur_version = match.groups() |
| 77 | + target_version = versions.get(name, cur_version) |
| 78 | + if target_version != cur_version: |
| 79 | + updated_dep = f'{name}{sep}{target_version}' |
| 80 | + hook['additional_dependencies'][i] = updated_dep |
| 81 | + updated.append((hook['id'], name)) |
74 | 82 |
|
75 | 83 | if updated: |
76 | 84 | print(f'Writing updates to {filename}:') |
|
0 commit comments