Skip to content

Commit

Permalink
refactor: apply nitpick settings
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed May 17, 2024
1 parent fcdd03b commit 520fa2d
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 104 deletions.
10 changes: 8 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ root = true

# All files.
[*]
end_of_line = LF
end_of_line = lf
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{yml,yaml}]
[*.{bat,cmd,ps1}]
end_of_line = crlf

[*.{js,json,json5,yml,yaml,md,rb}]
indent_size = 2

[Makefile]
indent_style = tab
179 changes: 94 additions & 85 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,86 +1,95 @@
repos:
- hooks:
- args:
- --markdown-linebreak-ext=md,markdown
id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-ast
- id: fix-byte-order-marker
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- args:
- --fix=lf
id: mixed-line-ending
- exclude: ^\.(vscode|devcontainer)/
id: check-json
- args:
- --indent
- '4'
- --autofix
- --no-sort-keys
exclude: ^\.(vscode|devcontainer)/
id: pretty-format-json
- id: check-toml
repo: https://github.com/pre-commit/pre-commit-hooks
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c
- repo: https://github.com/bwhmather/ssort
rev: dcb59fdb9b46ed1bb8e6ca2107e35f76cdc9c97e # frozen: 0.12.4
hooks:
- id: ssort
- hooks:
- id: black
repo: https://github.com/psf/black
rev: 8fe627072f15ff2e3d380887b92f7868efaf6d05
- hooks:
- id: isort
repo: https://github.com/pycqa/isort
rev: c235f5e450b4b84e58d114ed4c589cbf454175a3
- hooks:
- id: python-no-eval
- id: python-no-log-warn
repo: https://github.com/pre-commit/pygrep-hooks
rev: 3a6eb0fadf60b3cccfd80bad9dbb6fae7e47b316
- hooks:
- id: flynt
repo: https://github.com/ikamensh/flynt
rev: 651c822fdcf45fffcf9743dc755085f32acb65e3
- hooks:
- args:
- --py38-plus
id: pyupgrade
repo: https://github.com/asottile/pyupgrade
rev: 12af25eb252deaaecb6b259df40d01f42e716dc3
- hooks:
- additional_dependencies:
- tomli ; python_version < '3.11'
id: auto-walrus
repo: https://github.com/MarcoGorelli/auto-walrus
rev: 7855759486496a3248e9ff37dce7c6d57d39bfce
- hooks:
- additional_dependencies:
- tomli ; python_version < '3.11'
id: codespell
repo: https://github.com/codespell-project/codespell
rev: 6e41aba91fb32e9feb741a6258eefeb9c6e4a482
- hooks:
- id: commitizen
repo: https://github.com/commitizen-tools/commitizen
rev: 7c0bc1591103b1f089aab9810fc2a201ccb0552b
- hooks:
- entry: hatch run python3 -m mypy
exclude: tests/.*
id: mypy
language: system
name: mypy
types:
- python
repo: local
- hooks:
- args:
- --markdown-linebreak-ext=md,markdown
id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-ast
- id: fix-byte-order-marker
- id: check-merge-conflict
- id: debug-statements
- id: detect-private-key
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- args:
- --fix=lf
id: mixed-line-ending
- exclude: ^\.(vscode|devcontainer)/
id: check-json
- args:
- --indent
- '4'
- --autofix
- --no-sort-keys
exclude: ^\.(vscode|devcontainer)/
id: pretty-format-json
- id: check-toml
repo: https://github.com/pre-commit/pre-commit-hooks
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c
- repo: https://github.com/bwhmather/ssort
rev: 202524364c6ba81752b4fa9c77f16c9ccd5a5e28 # frozen: 0.13.0
hooks:
- id: ssort
- hooks:
- id: black
repo: https://github.com/psf/black
rev: 3702ba224ecffbcec30af640c149f231d90aebdb # frozen: 24.4.2
- hooks:
- id: isort
repo: https://github.com/pycqa/isort
rev: c235f5e450b4b84e58d114ed4c589cbf454175a3
- hooks:
- id: python-no-eval
- id: python-no-log-warn
repo: https://github.com/pre-commit/pygrep-hooks
rev: 3a6eb0fadf60b3cccfd80bad9dbb6fae7e47b316
- hooks:
- id: flynt
repo: https://github.com/ikamensh/flynt
rev: 651c822fdcf45fffcf9743dc755085f32acb65e3
- hooks:
- args:
- --py38-plus
id: pyupgrade
repo: https://github.com/asottile/pyupgrade
rev: 12af25eb252deaaecb6b259df40d01f42e716dc3
- hooks:
- additional_dependencies:
- tomli ; python_version < '3.11'
id: auto-walrus
repo: https://github.com/MarcoGorelli/auto-walrus
rev: ba0661836089a532a710f68713a3e3e53f7f0113 # frozen: 0.3.4
- hooks:
- additional_dependencies:
- tomli ; python_version < '3.11'
id: codespell
repo: https://github.com/codespell-project/codespell
rev: 6e41aba91fb32e9feb741a6258eefeb9c6e4a482
- hooks:
- id: commitizen
repo: https://github.com/commitizen-tools/commitizen
rev: 9d17f393228f6c60793b4929d910e3b1f0fcb1ad # frozen: v3.25.1
- hooks:
- entry: hatch run python3 -m mypy
exclude: tests/.*
id: mypy
language: system
name: mypy
types:
- python
repo: local
- repo: https://github.com/andreoliwa/nitpick
rev: '36d4912df1f0bd2ed8cc535b57c5ba3b09ce3d46' # frozen: v0.35.0
hooks:
- id: nitpick
minimum_pre_commit_version: 2.18.0
default_install_hook_types:
- pre-commit
- pre-push
- commit-msg
13 changes: 2 additions & 11 deletions polymatch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,10 @@ def to_string(self) -> AnyStr:
The pattern string text
"""
if isinstance(self.pattern, str):
return "{}{}:{}:{}".format(
"~" if self.inverted else "",
self.get_type(),
self.case_action.value[1],
self.pattern,
)
return f"{'~' if self.inverted else ''}{self.get_type()}:{self.case_action.value[1]}:{self.pattern}"

return (
"{}{}:{}:".format(
"~" if self.inverted else "",
self.get_type(),
self.case_action.value[1],
)
f"{'~' if self.inverted else ''}{self.get_type()}:{self.case_action.value[1]}:"
).encode() + self.pattern

def __eq__(self, other: object) -> bool:
Expand Down
4 changes: 1 addition & 3 deletions polymatch/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def __init__(
text_type: Input text type
"""
super().__init__(
"Pattern of type {!r} can not match text of type {!r}".format(
pattern_type.__name__, text_type.__name__
)
f"Pattern of type {pattern_type.__name__!r} can not match text of type {text_type.__name__!r}"
)


Expand Down
4 changes: 1 addition & 3 deletions polymatch/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def register(self, cls: Type[Any]) -> None:
DuplicateMatcherRegistrationError: If a matching pattern is already registered
"""
if not issubclass(cls, PolymorphicMatcher):
msg = "Pattern matcher must be of type {!r} not {!r}".format(
PolymorphicMatcher.__name__, cls.__name__
)
msg = f"Pattern matcher must be of type {PolymorphicMatcher.__name__!r} not {cls.__name__!r}"
raise TypeError(msg)

name = cls.get_type()
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ convention = "google"
aggressive = true
transform-joins = true
transform-concats = true
line-length = 120

[tool.mypy]
namespace_packages = true
Expand Down Expand Up @@ -176,6 +177,7 @@ enable_error_code = [
"truthy-iterable",
"ignore-without-code",
]
ignore_missing_imports = true

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down Expand Up @@ -203,3 +205,6 @@ version_scheme = "semver"
version_provider = "scm"
update_changelog_on_bump = true
major_version_zero = true

[tool.nitpick]
style = ["gh://TotallyNotRobots/nitpick/lib-style.toml"]

0 comments on commit 520fa2d

Please sign in to comment.