summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-09 06:25:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-09 06:25:58 +0000
commitab5b91c265d1b7a1273e0a68fdf87b2ee1d7eb6a (patch)
tree8d5133377d8bf60dbfa05f25872aa6f51227a821
parentAdding upstream version 4.6.0+dfsg. (diff)
downloadpre-commit-hooks-ab5b91c265d1b7a1273e0a68fdf87b2ee1d7eb6a.tar.xz
pre-commit-hooks-ab5b91c265d1b7a1273e0a68fdf87b2ee1d7eb6a.zip
Adding upstream version 5.0.0+dfsg.upstream/5.0.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--.pre-commit-config.yaml13
-rw-r--r--.pre-commit-hooks.yaml21
-rw-r--r--CHANGELOG.md24
-rw-r--r--README.md5
-rw-r--r--pre_commit_hooks/check_executables_have_shebangs.py2
-rw-r--r--pre_commit_hooks/check_yaml.py2
-rw-r--r--pre_commit_hooks/pretty_format_json.py22
-rw-r--r--pre_commit_hooks/requirements_txt_fixer.py5
-rw-r--r--setup.cfg2
-rw-r--r--tests/check_illegal_windows_names_test.py63
-rw-r--r--tests/pretty_format_json_test.py18
-rw-r--r--tests/requirements_txt_fixer_test.py2
12 files changed, 153 insertions, 26 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 937696b..315c420 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.6.0
+ rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
@@ -14,7 +14,7 @@ repos:
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/asottile/reorder-python-imports
- rev: v3.12.0
+ rev: v3.13.0
hooks:
- id: reorder-python-imports
args: [--py38-plus, --add-import, 'from __future__ import annotations']
@@ -23,20 +23,19 @@ repos:
hooks:
- id: add-trailing-comma
- repo: https://github.com/asottile/pyupgrade
- rev: v3.15.2
+ rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/hhatto/autopep8
- rev: v2.1.0
+ rev: v2.3.1
hooks:
- id: autopep8
- repo: https://github.com/PyCQA/flake8
- rev: 7.0.0
+ rev: 7.1.1
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
- rev: v1.9.0
+ rev: v1.11.2
hooks:
- id: mypy
- additional_dependencies: [types-all]
diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml
index 4b4d0cf..b71169b 100644
--- a/.pre-commit-hooks.yaml
+++ b/.pre-commit-hooks.yaml
@@ -3,7 +3,8 @@
description: prevents giant files from being committed.
entry: check-added-large-files
language: python
- stages: [commit, push, manual]
+ stages: [pre-commit, pre-push, manual]
+ minimum_pre_commit_version: 3.2.0
- id: check-ast
name: check python ast
description: simply checks whether the files parse as valid python.
@@ -39,7 +40,13 @@
entry: check-executables-have-shebangs
language: python
types: [text, executable]
- stages: [commit, push, manual]
+ stages: [pre-commit, pre-push, manual]
+ minimum_pre_commit_version: 3.2.0
+- id: check-illegal-windows-names
+ name: check illegal windows names
+ entry: Illegal Windows filenames detected
+ language: fail
+ files: '(?i)((^|/)(CON|PRN|AUX|NUL|COM[\d¹²³]|LPT[\d¹²³])(\.|/|$)|[<>:\"\\|?*\x00-\x1F]|/[^/]*[\.\s]/|[^/]*[\.\s]$)'
- id: check-json
name: check json
description: checks json files for parseable syntax.
@@ -52,7 +59,8 @@
entry: check-shebang-scripts-are-executable
language: python
types: [text]
- stages: [commit, push, manual]
+ stages: [pre-commit, pre-push, manual]
+ minimum_pre_commit_version: 3.2.0
- id: pretty-format-json
name: pretty format json
description: sets a standard for formatting json files.
@@ -107,6 +115,7 @@
entry: destroyed-symlinks
language: python
types: [file]
+ stages: [pre-commit, pre-push, manual]
- id: detect-aws-credentials
name: detect aws credentials
description: detects *your* aws credentials from the aws cli credentials file.
@@ -131,7 +140,8 @@
entry: end-of-file-fixer
language: python
types: [text]
- stages: [commit, push, manual]
+ stages: [pre-commit, pre-push, manual]
+ minimum_pre_commit_version: 3.2.0
- id: file-contents-sorter
name: file contents sorter
description: sorts the lines in specified files (defaults to alphabetical). you must provide list of target files as input in your .pre-commit-config.yaml file.
@@ -198,4 +208,5 @@
entry: trailing-whitespace-fixer
language: python
types: [text]
- stages: [commit, push, manual]
+ stages: [pre-commit, pre-push, manual]
+ minimum_pre_commit_version: 3.2.0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bf99d9f..e165574 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,27 @@
+5.0.0 - 2024-10-05
+==================
+
+### Features
+- `requirements-txt-fixer`: also remove `pkg_resources==...`.
+ - #850 PR by @ericfrederich.
+ - #1030 issue by @ericfrederich.
+- `check-illegal-windows-names`: new hook!
+ - #1044 PR by @ericfrederich.
+ - #589 issue by @ericfrederich.
+ - #1049 PR by @Jeffrey-Lim.
+- `pretty-format-json`: continue processing even if a file has a json error.
+ - #1039 PR by @amarvin.
+ - #1038 issue by @amarvin.
+
+### Fixes
+- `destroyed-symlinks`: set `stages` to `[pre-commit, pre-push, manual]`
+ - PR #1085 by @AdrianDC.
+
+### Migrating
+- pre-commit-hooks now requires `pre-commit>=3.2.0`.
+- use non-deprecated names for `stages`.
+ - #1093 PR by @asottile.
+
4.6.0 - 2024-04-06
==================
diff --git a/README.md b/README.md
index 4992baf..c0f678f 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ Add this to your `.pre-commit-config.yaml`
```yaml
- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v4.6.0 # Use the ref you want to point at
+ rev: v5.0.0 # Use the ref you want to point at
hooks:
- id: trailing-whitespace
# - id: ...
@@ -51,6 +51,9 @@ Checks for a common error of placing code before the docstring.
#### `check-executables-have-shebangs`
Checks that non-binary executables have a proper shebang.
+#### `check-illegal-windows-names`
+Check for files that cannot be created on Windows.
+
#### `check-json`
Attempts to load all json files to verify syntax.
diff --git a/pre_commit_hooks/check_executables_have_shebangs.py b/pre_commit_hooks/check_executables_have_shebangs.py
index d8e4f49..7c984d3 100644
--- a/pre_commit_hooks/check_executables_have_shebangs.py
+++ b/pre_commit_hooks/check_executables_have_shebangs.py
@@ -35,7 +35,7 @@ class GitLsFile(NamedTuple):
filename: str
-def git_ls_files(paths: Sequence[str]) -> Generator[GitLsFile, None, None]:
+def git_ls_files(paths: Sequence[str]) -> Generator[GitLsFile]:
outs = cmd_output('git', 'ls-files', '-z', '--stage', '--', *paths)
for out in zsplit(outs):
metadata, filename = out.split('\t')
diff --git a/pre_commit_hooks/check_yaml.py b/pre_commit_hooks/check_yaml.py
index 9563347..0187392 100644
--- a/pre_commit_hooks/check_yaml.py
+++ b/pre_commit_hooks/check_yaml.py
@@ -11,7 +11,7 @@ import ruamel.yaml
yaml = ruamel.yaml.YAML(typ='safe')
-def _exhaust(gen: Generator[str, None, None]) -> None:
+def _exhaust(gen: Generator[str]) -> None:
for _ in gen:
pass
diff --git a/pre_commit_hooks/pretty_format_json.py b/pre_commit_hooks/pretty_format_json.py
index 627a11c..5c0292b 100644
--- a/pre_commit_hooks/pretty_format_json.py
+++ b/pre_commit_hooks/pretty_format_json.py
@@ -115,16 +115,20 @@ def main(argv: Sequence[str] | None = None) -> int:
f'Input File {json_file} is not a valid JSON, consider using '
f'check-json',
)
- return 1
-
- if contents != pretty_contents:
- if args.autofix:
- _autofix(json_file, pretty_contents)
- else:
- diff_output = get_diff(contents, pretty_contents, json_file)
- sys.stdout.buffer.write(diff_output.encode())
-
status = 1
+ else:
+ if contents != pretty_contents:
+ if args.autofix:
+ _autofix(json_file, pretty_contents)
+ else:
+ diff_output = get_diff(
+ contents,
+ pretty_contents,
+ json_file,
+ )
+ sys.stdout.buffer.write(diff_output.encode())
+
+ status = 1
return status
diff --git a/pre_commit_hooks/requirements_txt_fixer.py b/pre_commit_hooks/requirements_txt_fixer.py
index 261acc9..07b57e1 100644
--- a/pre_commit_hooks/requirements_txt_fixer.py
+++ b/pre_commit_hooks/requirements_txt_fixer.py
@@ -115,7 +115,10 @@ def fix_requirements(f: IO[bytes]) -> int:
# which is automatically added by broken pip package under Debian
requirements = [
req for req in requirements
- if req.value != b'pkg-resources==0.0.0\n'
+ if req.value not in [
+ b'pkg-resources==0.0.0\n',
+ b'pkg_resources==0.0.0\n',
+ ]
]
# sort the requirements and remove duplicates
diff --git a/setup.cfg b/setup.cfg
index 82a5457..a0d67f8 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = pre_commit_hooks
-version = 4.6.0
+version = 5.0.0
description = Some out-of-the-box hooks for pre-commit.
long_description = file: README.md
long_description_content_type = text/markdown
diff --git a/tests/check_illegal_windows_names_test.py b/tests/check_illegal_windows_names_test.py
new file mode 100644
index 0000000..82d7532
--- /dev/null
+++ b/tests/check_illegal_windows_names_test.py
@@ -0,0 +1,63 @@
+from __future__ import annotations
+
+import os.path
+import re
+
+import pytest
+
+from pre_commit_hooks.check_yaml import yaml
+
+
+@pytest.fixture(scope='module')
+def hook_re():
+ here = os.path.dirname(__file__)
+ with open(os.path.join(here, '..', '.pre-commit-hooks.yaml')) as f:
+ hook_defs = yaml.load(f)
+ hook, = (
+ hook
+ for hook in hook_defs
+ if hook['id'] == 'check-illegal-windows-names'
+ )
+ yield re.compile(hook['files'])
+
+
+@pytest.mark.parametrize(
+ 's',
+ (
+ pytest.param('aux.txt', id='with ext'),
+ pytest.param('aux', id='without ext'),
+ pytest.param('AuX.tXt', id='capitals'),
+ pytest.param('com7.dat', id='com with digit'),
+ pytest.param(':', id='bare colon'),
+ pytest.param('file:Zone.Identifier', id='mid colon'),
+ pytest.param('path/COM¹.json', id='com with superscript'),
+ pytest.param('dir/LPT³.toml', id='lpt with superscript'),
+ pytest.param('with < less than', id='with less than'),
+ pytest.param('Fast or Slow?.md', id='with question mark'),
+ pytest.param('with "double" quotes', id='with double quotes'),
+ pytest.param('with_null\x00byte', id='with null byte'),
+ pytest.param('ends_with.', id='ends with period'),
+ pytest.param('ends_with ', id='ends with space'),
+ pytest.param('ends_with\t', id='ends with tab'),
+ pytest.param('dir/ends./with.txt', id='directory ends with period'),
+ pytest.param('dir/ends /with.txt', id='directory ends with space'),
+ ),
+)
+def test_check_illegal_windows_names_matches(hook_re, s):
+ assert hook_re.search(s)
+
+
+@pytest.mark.parametrize(
+ 's',
+ (
+ pytest.param('README.md', id='standard file'),
+ pytest.param('foo.aux', id='as ext'),
+ pytest.param('com.dat', id='com without digit'),
+ pytest.param('.python-version', id='starts with period'),
+ pytest.param(' pseudo nan', id='with spaces'),
+ pytest.param('!@#$%^&;=≤\'~`¡¿€🤗', id='with allowed characters'),
+ pytest.param('path.to/file.py', id='standard path'),
+ ),
+)
+def test_check_illegal_windows_names_does_not_match(hook_re, s):
+ assert hook_re.search(s) is None
diff --git a/tests/pretty_format_json_test.py b/tests/pretty_format_json_test.py
index 5ded724..68b6d7a 100644
--- a/tests/pretty_format_json_test.py
+++ b/tests/pretty_format_json_test.py
@@ -82,6 +82,24 @@ def test_autofix_main(tmpdir):
assert ret == 0
+def test_invalid_main(tmpdir):
+ srcfile1 = tmpdir.join('not_valid_json.json')
+ srcfile1.write(
+ '{\n'
+ ' // not json\n'
+ ' "a": "b"\n'
+ '}',
+ )
+ srcfile2 = tmpdir.join('to_be_json_formatted.json')
+ srcfile2.write('{ "a": "b" }')
+
+ # it should have skipped the first file and formatted the second one
+ assert main(['--autofix', str(srcfile1), str(srcfile2)]) == 1
+
+ # confirm second file was formatted (shouldn't trigger linter again)
+ assert main([str(srcfile2)]) == 0
+
+
def test_orderfile_get_pretty_format():
ret = main((
'--top-keys=alist', get_resource_path('pretty_formatted_json.json'),
diff --git a/tests/requirements_txt_fixer_test.py b/tests/requirements_txt_fixer_test.py
index c400be1..c0d2c65 100644
--- a/tests/requirements_txt_fixer_test.py
+++ b/tests/requirements_txt_fixer_test.py
@@ -82,6 +82,8 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement
),
(b'bar\npkg-resources==0.0.0\nfoo\n', FAIL, b'bar\nfoo\n'),
(b'foo\npkg-resources==0.0.0\nbar\n', FAIL, b'bar\nfoo\n'),
+ (b'bar\npkg_resources==0.0.0\nfoo\n', FAIL, b'bar\nfoo\n'),
+ (b'foo\npkg_resources==0.0.0\nbar\n', FAIL, b'bar\nfoo\n'),
(
b'git+ssh://git_url@tag#egg=ocflib\nDjango\nijk\n',
FAIL,