Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#585)
Browse files Browse the repository at this point in the history
updates:
- [github.com/charliermarsh/ruff-pre-commit: v0.0.263 → v0.0.269](astral-sh/ruff-pre-commit@v0.0.263...v0.0.269)
- [github.com/pre-commit/mirrors-mypy: v1.2.0 → v1.3.0](pre-commit/mirrors-mypy@v1.2.0...v1.3.0)
- [github.com/commitizen-tools/commitizen: 3.2.0 → 3.2.2](commitizen-tools/commitizen@3.2.0...3.2.2)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore: fix ruff warnings

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: W. Augusto Andreoli <1258218+andreoliwa@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] and andreoliwa committed May 25, 2023
1 parent 5f12e41 commit d7ebedd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.263
rev: v0.0.269
hooks:
- id: ruff
args: [--fix]
Expand Down Expand Up @@ -70,7 +70,7 @@ repos:
- id: prettier
stages: [commit]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.2.0
rev: v1.3.0
hooks:
- id: mypy
# https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-show-error-codes
Expand Down Expand Up @@ -109,7 +109,7 @@ repos:
# https://docs.openstack.org/bashate/latest/man/bashate.html#options
args: [-i, E006]
- repo: https://github.com/commitizen-tools/commitizen
rev: 3.2.0
rev: 3.2.2
hooks:
- id: commitizen
stages: [commit-msg]
27 changes: 14 additions & 13 deletions docs/autofix_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
It doesn't recognise the "styles" dir anywhere (on the root, under "docs", under "_static"...).
Not even changing ``html_static_path`` on ``conf.py`` worked.
"""
from __future__ import annotations

import sys
from collections import defaultdict
from importlib import import_module
from pathlib import Path
from subprocess import check_output # nosec
from textwrap import dedent, indent
from typing import Dict, List, Optional, Set, Tuple, Union

import attr
import click
Expand Down Expand Up @@ -55,16 +56,16 @@ class FileType:

text: str
url: str
check: Union[bool, int]
autofix: Union[bool, int]
check: bool | int
autofix: bool | int

def __post_init__(self):
"""Warn about text that might render incorrectly."""
if "`" in self.text:
msg = f"Remove all backticks from the text: {self.text}"
raise RuntimeError(msg)

def __lt__(self, other: "FileType") -> bool:
def __lt__(self, other: FileType) -> bool:
"""Sort instances.
From the `docs <https://docs.python.org/3/howto/sorting.html#odd-and-ends>`_:
Expand Down Expand Up @@ -104,12 +105,12 @@ def autofix_str(self) -> str:
return self._pretty("autofix")

@property
def row(self) -> Tuple[str, str, str]:
def row(self) -> tuple[str, str, str]:
"""Tuple for a table row."""
return self.text_with_url, self.check_str, self.autofix_str


IMPLEMENTED_FILE_TYPES: Set[FileType] = {
IMPLEMENTED_FILE_TYPES: set[FileType] = {
FileType("Any INI file", f"{READ_THE_DOCS_URL}plugins.html#ini-files", True, True),
FileType("Any JSON file", f"{READ_THE_DOCS_URL}plugins.html#json-files", True, True),
FileType("Any plain text file", f"{READ_THE_DOCS_URL}plugins.html#text-files", True, False),
Expand All @@ -119,7 +120,7 @@ def row(self) -> Tuple[str, str, str]:
FileType(PYLINTRC, f"{READ_THE_DOCS_URL}plugins.html#ini-files", True, True),
FileType(SETUP_CFG, f"{READ_THE_DOCS_URL}plugins.html#ini-files", True, True),
}
PLANNED_FILE_TYPES: Set[FileType] = {
PLANNED_FILE_TYPES: set[FileType] = {
FileType("Any Markdown file", "", 280, 0),
FileType("Any Terraform file", "", 318, 0),
FileType(".dockerignore", "", 8, 8),
Expand All @@ -146,7 +147,7 @@ def __init__(self, filename: str) -> None:
self.divider_end = RST_DIVIDER_END
self.divider_from_here = RST_DIVIDER_FROM_HERE

def write(self, lines: List[str], divider: Optional[str] = None) -> int:
def write(self, lines: list[str], divider: str | None = None) -> int:
"""Write content to the file."""
old_content = self.file.read_text()
if divider:
Expand Down Expand Up @@ -252,7 +253,7 @@ def write_config() -> int:
return DocFile("configuration.rst").write(blocks, divider="config-file")


def rst_table(header: Tuple[str, ...], rows: List[Tuple[str, ...]]) -> List[str]:
def rst_table(header: tuple[str, ...], rows: list[tuple[str, ...]]) -> list[str]:
"""Create a ReST table from header and rows."""
blocks = [".. list-table::\n :header-rows: 1\n"]
num_columns = len(header)
Expand All @@ -262,10 +263,10 @@ def rst_table(header: Tuple[str, ...], rows: List[Tuple[str, ...]]) -> List[str]
return blocks


def write_readme(file_types: Set[FileType], divider: str) -> int:
def write_readme(file_types: set[FileType], divider: str) -> int:
"""Write the README."""
# TODO: chore: quickstart.rst has some parts of README.rst as a copy/paste/change
rows: List[Tuple[str, ...]] = []
rows: list[tuple[str, ...]] = []
for file_type in sorted(file_types):
rows.append(file_type.row)

Expand All @@ -281,9 +282,9 @@ class StyleLibraryRow: # pylint: disable=too-few-public-methods
name: str


def _build_library(gitref: bool = True) -> List[str]:
def _build_library(gitref: bool = True) -> list[str]:
# pylint: disable=no-member
library: Dict[str, List[Tuple]] = defaultdict(list)
library: dict[str, list[tuple]] = defaultdict(list)
pre, post = (":gitref:", "") if gitref else ("", "_")
for path in sorted(builtin_styles()): # type: Path
style = BuiltinStyle.from_path(path)
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ select = ["ALL"]

# https://beta.ruff.rs/docs/settings/#ignore
ignore = [
"ANN", # https://beta.ruff.rs/docs/rules/#flake8-annotations-ann # TODO: fix: add typing annotations (fix 249 errors and remove this ignore)
"COM", # https://beta.ruff.rs/docs/rules/#flake8-commas-com
"D107", # Missing docstring in `__init__`
"D202", # No blank lines allowed after function docstring
Expand All @@ -138,9 +139,8 @@ ignore = [
"E402", # Module level import not at top of file
"E501", # Line too long
"FBT", # https://beta.ruff.rs/docs/rules/#flake8-boolean-trap-fbt

# TODO: fix: add typing annotations (fix 249 errors and remove this ignore)
"ANN", # https://beta.ruff.rs/docs/rules/#flake8-annotations-ann
"TD002", # Missing author in TO DO
"TD003", # Missing issue link on the line following this TO DO
]

# https://beta.ruff.rs/docs/settings/#line-length
Expand Down
2 changes: 1 addition & 1 deletion src/nitpick/blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def quoted_split(string_: str, separator=SEPARATOR_DOT) -> list[str]:
)

def remove_quotes(match):
return match.group(0).strip("".join([SINGLE_QUOTE, DOUBLE_QUOTE])).replace(separator, SEPARATOR_QUOTED_SPLIT)
return match.group(0).strip(f"{SINGLE_QUOTE}{DOUBLE_QUOTE}").replace(separator, SEPARATOR_QUOTED_SPLIT)

return [
part.replace(SEPARATOR_QUOTED_SPLIT, separator)
Expand Down
16 changes: 10 additions & 6 deletions src/nitpick/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
"""Nitpick exceptions."""
from __future__ import annotations

import warnings
from typing import Any, Dict, List, Union
from typing import TYPE_CHECKING, Any

from more_itertools import always_iterable

from nitpick.constants import PRE_COMMIT_CONFIG_YAML, PROJECT_NAME
from nitpick.violations import Fuss

if TYPE_CHECKING:
from nitpick.violations import Fuss


class QuitComplainingError(Exception):
"""Quit complaining and exit the application."""

def __init__(self, violations: Union[Fuss, List[Fuss]]) -> None:
def __init__(self, violations: Fuss | list[Fuss]) -> None:
super().__init__()
self.violations: List[Fuss] = list(always_iterable(violations))
self.violations: list[Fuss] = list(always_iterable(violations))


class Deprecation:
Expand All @@ -37,7 +41,7 @@ def pre_commit_without_dash(path_from_root: str) -> bool:
return False

@staticmethod
def jsonfile_section(style_errors: Dict[str, Any]) -> bool:
def jsonfile_section(style_errors: dict[str, Any]) -> bool:
"""The [nitpick.JSONFile] is not needed anymore; JSON files are now detected by the extension."""
has_nitpick_jsonfile_section = style_errors.get(PROJECT_NAME, {}).pop("JSONFile", None)
if has_nitpick_jsonfile_section:
Expand Down Expand Up @@ -69,4 +73,4 @@ def pre_commit_repos_with_yaml_key() -> bool:

def pretty_exception(err: Exception, message: str = ""):
"""Return a pretty error message with the full path of the Exception."""
return f"{message} ({err.__module__}.{err.__class__.__name__}: {str(err)})"
return f"{message} ({err.__module__}.{err.__class__.__name__}: {err!s})"
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_simple_error(tmp_path):

project.cli_run(
f"""
{str(project.root_dir / "pyproject.toml")}:1: NIP318 has missing values:
{project.root_dir / "pyproject.toml"!s}:1: NIP318 has missing values:
[tool.black]
line-length = 100
"""
Expand Down

0 comments on commit d7ebedd

Please sign in to comment.