sarj-python-lint 0.80.14__tar.gz → 0.80.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/PKG-INFO +2 -1
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/pyproject.toml +2 -2
- sarj_python_lint-0.80.17/src/sarj_python_lint/__init__.py +2 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/__main__.py +78 -71
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/_ratchet_cli.py +70 -55
- sarj_python_lint-0.80.17/src/sarj_python_lint/rules/__init__.py +3 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_registry.py +4 -2
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_comment_cruft.py +24 -0
- sarj_python_lint-0.80.17/src/sarj_python_lint/rules/no_dunder_all.py +364 -0
- sarj_python_lint-0.80.17/src/sarj_python_lint/rules/prefer_match_value_dispatch.py +230 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_str_enum.py +7 -6
- sarj_python_lint-0.80.14/src/sarj_python_lint/__init__.py +0 -5
- sarj_python_lint-0.80.14/src/sarj_python_lint/rules/__init__.py +0 -6
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/.gitignore +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/LICENSE +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/README.md +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/_analysis_session.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/_filesystem.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/_secret_names.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/_version.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/py.typed +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/ratchet.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rule_base.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_ast_index.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_comments.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_docstrings.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_fastapi.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_first_party.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_fixed_record.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_imports.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_logging.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_paths.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_project_index.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_prose_budget.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_pytest.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_sql.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_suppression_comments.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_test_assertions.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/complex_postgres_query_requires_architecture_review.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/defect_xfail_requires_explicit_strict.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/docstring_args_restate_signature.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/docstring_returns_restate_signature.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/excessive_commentary.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/fakes_in_shared_location.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/fastapi_explicit_openapi_contract.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/iac_source_coupled_test.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/invalid_pydantic_field_default.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/mock_without_spec.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/negative_only_http_status_assertion.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_analytical_aggregation_in_postgres_store.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_conftest_test_module_import.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_copied_inherited_docstring.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_cors_wildcard_with_credentials.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_duplicate_dunder_all_entry.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_fastapi_on_event.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_file_level_escape_hatch_suppression.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_first_party_private_import.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_frozen_after_validator_field_write.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_generic_single_export_module.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_hidden_constructor_fallback.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_nested_pydantic_field_validator.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_offset_pagination.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_positional_psycopg_row_escape.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_psycopg_execution_outside_injected_owner.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_random_uuid_in_sql.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_raw_connection_in_tests.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_raw_source_text_test_oracle.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_redundant_literal_description.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_repeated_string_literal.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_repeated_test_body.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_restated_comment.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_secret_in_log.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_select_star.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_string_concat_in_loop.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_tautological_expect.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_typed_doc_sections.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_unique_violation_message_match.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_unnecessary_docstring.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_vague_suppression_description.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_whole_request_response_payload_in_log.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/opaque_parametrize_case_needs_id.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/over_mocked_test.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/phase_label_comment.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_class_row.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_collection_comprehension.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_constant_time_secret_compare.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_fstring_over_concat.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_immutable_module_constant.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_library_fake.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_match_assert_never.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_match_type_dispatch.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_module_level_constant.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_namedtuple_over_tuple_return.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_nominal_id_types.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_non_nullable_collection.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_or_pattern.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_self_documenting_constant.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_self_type_annotation.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_set_isdisjoint.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_struct_over_namedtuple.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_walrus_awaited_none_guard.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_walrus_comprehension_filter.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_walrus_regex_match.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/prefer_walrus_stream_loop.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/production_derived_test_cases.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/pydantic_at_boundaries.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/pytest_fixture_returns_bare_tuple.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/redundant_class_docstring.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/redundant_docstring.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/redundant_module_docstring.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/repeated_kwarg_heavy_call_in_test.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/repeated_static_call_cases.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/require_keyword_only_swap_prone_params.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/require_nodecode_for_splitting_settings_field.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/require_port_for_service.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/require_pydantic_for_external_json.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/require_pydantic_ordinal_lower_bound.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/restated_test_docstring.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/stepdown.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/store_get_delegates_to_bulk_read.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/store_insert_requires_on_conflict.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/timestamp_order_requires_tiebreaker.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/trailing_value_narration.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/typed_error_reasons.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/uncontrolled_randomness_in_test.py +0 -0
- {sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/unused_mock_setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sarj-python-lint
|
|
3
|
-
Version: 0.80.
|
|
3
|
+
Version: 0.80.17
|
|
4
4
|
Summary: Custom Python lint rules — AST-based, pre-commit-friendly, hypermodern defaults
|
|
5
5
|
Project-URL: Homepage, https://code-standards.sarj.ai/rules/python/
|
|
6
6
|
Project-URL: Documentation, https://code-standards.sarj.ai/rules/python/
|
|
@@ -19,6 +19,7 @@ Classifier: Topic :: Software Development :: Quality Assurance
|
|
|
19
19
|
Requires-Python: >=3.14
|
|
20
20
|
Requires-Dist: ruff>=0.16.5
|
|
21
21
|
Requires-Dist: sqlglot==30.18.0
|
|
22
|
+
Requires-Dist: typer==0.27.2
|
|
22
23
|
Description-Content-Type: text/markdown
|
|
23
24
|
|
|
24
25
|
<!-- Generated by `code-standards maintain docs sync`; do not edit. -->
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sarj-python-lint"
|
|
3
|
-
version = "0.80.
|
|
3
|
+
version = "0.80.17"
|
|
4
4
|
description = "Custom Python lint rules — AST-based, pre-commit-friendly, hypermodern defaults"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "sarj-ai" }]
|
|
@@ -15,7 +15,7 @@ classifiers = [
|
|
|
15
15
|
"Programming Language :: Python :: 3.14",
|
|
16
16
|
"Topic :: Software Development :: Quality Assurance",
|
|
17
17
|
]
|
|
18
|
-
dependencies = ["ruff>=0.16.5", "sqlglot==30.18.0"]
|
|
18
|
+
dependencies = ["ruff>=0.16.5", "sqlglot==30.18.0", "typer==0.27.2"]
|
|
19
19
|
|
|
20
20
|
[project.scripts]
|
|
21
21
|
sarj-python-lint = "sarj_python_lint.__main__:main"
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import argparse
|
|
4
3
|
import ast
|
|
5
4
|
from collections import Counter
|
|
5
|
+
from dataclasses import dataclass
|
|
6
6
|
import json
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
import sys
|
|
9
9
|
from types import MappingProxyType
|
|
10
|
-
from typing import NamedTuple
|
|
10
|
+
from typing import Annotated, NamedTuple
|
|
11
|
+
|
|
12
|
+
import typer
|
|
11
13
|
|
|
12
14
|
from sarj_python_lint import __version__
|
|
13
15
|
from sarj_python_lint._analysis_session import AnalysisSession
|
|
@@ -236,24 +238,9 @@ def _docstring_owner_locations(source: str) -> dict[int, _OwnerLocation]:
|
|
|
236
238
|
return owners
|
|
237
239
|
|
|
238
240
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
# `explain` takes exactly one rule, so it cannot share `--rule`'s list slot
|
|
243
|
-
# without widening the type and losing the check on every `check` call site.
|
|
244
|
-
which: str
|
|
245
|
-
files: list[Path]
|
|
246
|
-
baseline: Path | None
|
|
247
|
-
update_baseline: Path | None
|
|
248
|
-
|
|
249
|
-
def __init__(self) -> None:
|
|
250
|
-
super().__init__()
|
|
251
|
-
self.cmd = None
|
|
252
|
-
self.rule = []
|
|
253
|
-
self.which = ""
|
|
254
|
-
self.files = []
|
|
255
|
-
self.baseline = None
|
|
256
|
-
self.update_baseline = None
|
|
241
|
+
@dataclass
|
|
242
|
+
class _Result:
|
|
243
|
+
code: int = 0
|
|
257
244
|
|
|
258
245
|
|
|
259
246
|
def _explain(wanted: str) -> int:
|
|
@@ -328,78 +315,98 @@ def _apply_baseline(
|
|
|
328
315
|
return out
|
|
329
316
|
|
|
330
317
|
|
|
331
|
-
def
|
|
332
|
-
parser = argparse.ArgumentParser(
|
|
333
|
-
prog="sarj-python-lint",
|
|
334
|
-
description="Custom Python lint rules.",
|
|
335
|
-
)
|
|
336
|
-
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
337
|
-
sub = parser.add_subparsers(dest="cmd", required=True)
|
|
338
|
-
|
|
339
|
-
check_p = sub.add_parser("check", help="Run rules over files.")
|
|
340
|
-
check_p.add_argument(
|
|
341
|
-
"--rule",
|
|
342
|
-
action="append",
|
|
343
|
-
required=True,
|
|
344
|
-
help="Rule ID (repeat for multiple).",
|
|
345
|
-
)
|
|
346
|
-
check_p.add_argument(
|
|
347
|
-
"--baseline",
|
|
348
|
-
type=Path,
|
|
349
|
-
help="Per-file shrink-only baseline JSON: {path: {CODE: count}}. Diags up to the baselined count are suppressed.",
|
|
350
|
-
)
|
|
351
|
-
check_p.add_argument(
|
|
352
|
-
"--update-baseline",
|
|
353
|
-
type=Path,
|
|
354
|
-
help="Write the current per-file diagnostic counts to this JSON and exit 0.",
|
|
355
|
-
)
|
|
356
|
-
check_p.add_argument("files", nargs="+", type=Path)
|
|
357
|
-
|
|
358
|
-
sub.add_parser("list-rules", help="List available rule IDs.")
|
|
359
|
-
|
|
360
|
-
explain_p = sub.add_parser("explain", help="Print one rule's summary and the links to its examples and evidence.")
|
|
361
|
-
explain_p.add_argument("which", metavar="rule", help="Rule ID or SARJ code.")
|
|
362
|
-
|
|
363
|
-
args = parser.parse_args(argv, namespace=_Args())
|
|
364
|
-
|
|
365
|
-
if args.cmd == "list-rules":
|
|
366
|
-
for rid, cls in sorted(REGISTRY.items()):
|
|
367
|
-
inst = cls()
|
|
368
|
-
sys.stdout.write(f"{inst.code:8} {rid:40} {inst.description}\n")
|
|
369
|
-
return 0
|
|
370
|
-
|
|
371
|
-
if args.cmd == "explain":
|
|
372
|
-
return _explain(args.which)
|
|
373
|
-
|
|
318
|
+
def _run_check(rule: list[str], files: list[Path], baseline: Path | None, update_baseline: Path | None) -> int:
|
|
374
319
|
try:
|
|
375
|
-
diags = analyze(
|
|
320
|
+
diags = analyze(rule, files)
|
|
376
321
|
except (OSError, ValueError) as exc:
|
|
377
322
|
sys.stderr.write(f"error: {exc}\n")
|
|
378
323
|
return 2
|
|
379
|
-
if
|
|
324
|
+
if update_baseline is not None:
|
|
380
325
|
counts = _baseline_counts(diags)
|
|
381
326
|
blocking = sum(d.severity is Severity.ERROR for d in diags)
|
|
382
327
|
warnings = len(diags) - blocking
|
|
383
328
|
try:
|
|
384
|
-
atomic_write_text(
|
|
329
|
+
atomic_write_text(update_baseline, json.dumps(counts, indent=2, sort_keys=True) + "\n")
|
|
385
330
|
except OSError as exc:
|
|
386
|
-
sys.stderr.write(f"error: cannot write baseline {
|
|
331
|
+
sys.stderr.write(f"error: cannot write baseline {update_baseline}: {exc}\n")
|
|
387
332
|
return 2
|
|
388
333
|
sys.stdout.write(
|
|
389
|
-
f"baseline written: {
|
|
334
|
+
f"baseline written: {update_baseline} "
|
|
390
335
|
f"({blocking} blocking diagnostics over {len(counts)} files; {warnings} warnings excluded)\n"
|
|
391
336
|
)
|
|
392
337
|
return 0
|
|
393
|
-
if
|
|
338
|
+
if baseline is not None:
|
|
394
339
|
try:
|
|
395
|
-
diags = _apply_baseline(diags, _read_baseline(
|
|
340
|
+
diags = _apply_baseline(diags, _read_baseline(baseline))
|
|
396
341
|
except (OSError, ValueError) as exc:
|
|
397
|
-
sys.stderr.write(f"error: invalid baseline {
|
|
342
|
+
sys.stderr.write(f"error: invalid baseline {baseline}: {exc}\n")
|
|
398
343
|
return 2
|
|
399
344
|
for d in diags:
|
|
400
345
|
sys.stdout.write(d.format() + "\n")
|
|
401
346
|
return 1 if any(d.severity is Severity.ERROR for d in diags) else 0
|
|
402
347
|
|
|
403
348
|
|
|
349
|
+
app = typer.Typer(
|
|
350
|
+
help="Custom Python lint rules.",
|
|
351
|
+
add_completion=False,
|
|
352
|
+
no_args_is_help=False,
|
|
353
|
+
pretty_exceptions_enable=False,
|
|
354
|
+
context_settings={"help_option_names": ["-h", "--help"]},
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _show_version(*, value: bool) -> None:
|
|
359
|
+
if value:
|
|
360
|
+
sys.stdout.write(f"sarj-python-lint {__version__}\n")
|
|
361
|
+
raise typer.Exit
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
@app.callback()
|
|
365
|
+
def _root(
|
|
366
|
+
*,
|
|
367
|
+
_version: Annotated[bool, typer.Option("--version", callback=_show_version, is_eager=True)] = False,
|
|
368
|
+
) -> None:
|
|
369
|
+
pass
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
@app.command("list-rules", help="List available rule IDs.")
|
|
373
|
+
def _list_rules() -> None:
|
|
374
|
+
for rid, cls in sorted(REGISTRY.items()):
|
|
375
|
+
inst = cls()
|
|
376
|
+
sys.stdout.write(f"{inst.code:8} {rid:40} {inst.description}\n")
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
@app.command("explain", help="Print one rule's summary and the links to its examples and evidence.")
|
|
380
|
+
def _explain_command(
|
|
381
|
+
context: typer.Context, which: Annotated[str, typer.Argument(metavar="rule", help="Rule ID or SARJ code.")]
|
|
382
|
+
) -> None:
|
|
383
|
+
context.ensure_object(_Result).code = _explain(which)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
@app.command("check", help="Run rules over files.")
|
|
387
|
+
def _check_command(
|
|
388
|
+
context: typer.Context,
|
|
389
|
+
files: Annotated[list[Path], typer.Argument()],
|
|
390
|
+
rule: Annotated[list[str], typer.Option("--rule", help="Rule ID (repeat for multiple).")],
|
|
391
|
+
baseline: Annotated[
|
|
392
|
+
Path | None, typer.Option(help="Per-file shrink-only baseline JSON: {path: {CODE: count}}.")
|
|
393
|
+
] = None,
|
|
394
|
+
update_baseline: Annotated[
|
|
395
|
+
Path | None, typer.Option(help="Write current per-file diagnostic counts to JSON and exit 0.")
|
|
396
|
+
] = None,
|
|
397
|
+
) -> None:
|
|
398
|
+
context.ensure_object(_Result).code = _run_check(rule, files, baseline, update_baseline)
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def main(argv: list[str] | None = None) -> int:
|
|
402
|
+
result = _Result()
|
|
403
|
+
try:
|
|
404
|
+
app(args=argv, prog_name="sarj-python-lint", obj=result)
|
|
405
|
+
except SystemExit as exc:
|
|
406
|
+
if exc.code != 0:
|
|
407
|
+
raise
|
|
408
|
+
return result.code
|
|
409
|
+
|
|
410
|
+
|
|
404
411
|
if __name__ == "__main__":
|
|
405
412
|
sys.exit(main())
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
from dataclasses import dataclass
|
|
4
4
|
import json
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
import subprocess # ruff: ignore[suspicious-subprocess-import] -- fixed local Ruff introspection only
|
|
7
7
|
import sys
|
|
8
|
-
from typing import TYPE_CHECKING, TypeGuard
|
|
8
|
+
from typing import TYPE_CHECKING, Annotated, TypeGuard
|
|
9
|
+
|
|
10
|
+
import typer
|
|
9
11
|
|
|
10
12
|
from sarj_python_lint._filesystem import atomic_write_text
|
|
11
13
|
from sarj_python_lint._version import __version__
|
|
@@ -29,7 +31,8 @@ if TYPE_CHECKING:
|
|
|
29
31
|
_DEFAULT_BASELINE_NAME = "suppression-baseline.json"
|
|
30
32
|
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
@dataclass(frozen=True)
|
|
35
|
+
class _Options:
|
|
33
36
|
root: Path
|
|
34
37
|
baseline: Path | None
|
|
35
38
|
package: list[str]
|
|
@@ -38,19 +41,8 @@ class _Args(argparse.Namespace):
|
|
|
38
41
|
update: bool
|
|
39
42
|
allow_increase: bool
|
|
40
43
|
|
|
41
|
-
def __init__(self) -> None:
|
|
42
|
-
super().__init__()
|
|
43
|
-
self.root = Path()
|
|
44
|
-
self.baseline = None
|
|
45
|
-
self.package = []
|
|
46
|
-
self.exclude_subtree = []
|
|
47
|
-
self.per_file_ceiling = None
|
|
48
|
-
self.update = False
|
|
49
|
-
self.allow_increase = False
|
|
50
|
-
|
|
51
44
|
|
|
52
|
-
def
|
|
53
|
-
args = _build_parser().parse_args(argv, namespace=_Args())
|
|
45
|
+
def _run(args: _Options) -> int:
|
|
54
46
|
root = args.root.resolve()
|
|
55
47
|
baseline_path = args.baseline if args.baseline is not None else root / _DEFAULT_BASELINE_NAME
|
|
56
48
|
|
|
@@ -180,48 +172,68 @@ def _is_string_object_mapping(value: object) -> TypeGuard[dict[str, object]]:
|
|
|
180
172
|
return isinstance(value, dict)
|
|
181
173
|
|
|
182
174
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
175
|
+
@dataclass
|
|
176
|
+
class _Result:
|
|
177
|
+
code: int = 0
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
app = typer.Typer(
|
|
181
|
+
help="Ratchet on lint/type suppressions: per-code, per-package and per-file ceilings that may only shrink.",
|
|
182
|
+
add_completion=False,
|
|
183
|
+
no_args_is_help=False,
|
|
184
|
+
pretty_exceptions_enable=False,
|
|
185
|
+
context_settings={"help_option_names": ["-h", "--help"]},
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _show_version(*, value: bool) -> None:
|
|
190
|
+
if value:
|
|
191
|
+
sys.stdout.write(f"sarj-ratchet {__version__}\n")
|
|
192
|
+
raise typer.Exit
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
@app.command()
|
|
196
|
+
def _command(
|
|
197
|
+
context: typer.Context,
|
|
198
|
+
*,
|
|
199
|
+
root: Annotated[Path, typer.Argument(help="tree to scan (default: cwd)")] = Path(),
|
|
200
|
+
baseline: Annotated[
|
|
201
|
+
Path | None, typer.Option(help=f"baseline JSON (default: <root>/{_DEFAULT_BASELINE_NAME})")
|
|
202
|
+
] = None,
|
|
203
|
+
package: Annotated[
|
|
204
|
+
list[str] | None,
|
|
205
|
+
typer.Option(
|
|
206
|
+
"--package", help="package directory relative to root (repeatable; default: baseline or auto-discovered)"
|
|
188
207
|
),
|
|
208
|
+
] = None,
|
|
209
|
+
exclude_subtree: Annotated[
|
|
210
|
+
list[str] | None, typer.Option("--exclude-subtree", help="root-relative path prefix to skip (repeatable)")
|
|
211
|
+
] = None,
|
|
212
|
+
per_file_ceiling: Annotated[
|
|
213
|
+
int | None,
|
|
214
|
+
typer.Option(help=f"max suppressions in any one file (default: baseline or {DEFAULT_PER_FILE_CEILING})"),
|
|
215
|
+
] = None,
|
|
216
|
+
update: Annotated[
|
|
217
|
+
bool, typer.Option("--update", help="rewrite baseline from current counts (refuses to raise a ceiling)")
|
|
218
|
+
] = False,
|
|
219
|
+
allow_increase: Annotated[
|
|
220
|
+
bool, typer.Option("--allow-increase", help="with --update: permit ceilings to rise (requires explicit review)")
|
|
221
|
+
] = False,
|
|
222
|
+
_version: Annotated[bool, typer.Option("--version", callback=_show_version, is_eager=True)] = False,
|
|
223
|
+
) -> None:
|
|
224
|
+
context.ensure_object(_Result).code = _run(
|
|
225
|
+
_Options(root, baseline, package or [], exclude_subtree or [], per_file_ceiling, update, allow_increase)
|
|
189
226
|
)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
default=[],
|
|
201
|
-
help="package directory relative to root (repeatable; default: the baseline's, else auto-discovered)",
|
|
202
|
-
)
|
|
203
|
-
parser.add_argument(
|
|
204
|
-
"--exclude-subtree",
|
|
205
|
-
action="append",
|
|
206
|
-
default=[],
|
|
207
|
-
help="root-relative path prefix to skip, e.g. generated client output (repeatable)",
|
|
208
|
-
)
|
|
209
|
-
parser.add_argument(
|
|
210
|
-
"--per-file-ceiling",
|
|
211
|
-
type=int,
|
|
212
|
-
help=f"max suppressions in any one file (default: the baseline's, else {DEFAULT_PER_FILE_CEILING})",
|
|
213
|
-
)
|
|
214
|
-
parser.add_argument(
|
|
215
|
-
"--update",
|
|
216
|
-
action="store_true",
|
|
217
|
-
help="rewrite the baseline from current counts (refuses to raise a ceiling)",
|
|
218
|
-
)
|
|
219
|
-
parser.add_argument(
|
|
220
|
-
"--allow-increase",
|
|
221
|
-
action="store_true",
|
|
222
|
-
help="with --update: permit ceilings to rise (requires explicit review)",
|
|
223
|
-
)
|
|
224
|
-
return parser
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def main(argv: list[str] | None = None) -> int:
|
|
230
|
+
result = _Result()
|
|
231
|
+
try:
|
|
232
|
+
app(args=argv, prog_name="sarj-ratchet", obj=result)
|
|
233
|
+
except SystemExit as exc:
|
|
234
|
+
if exc.code != 0:
|
|
235
|
+
raise
|
|
236
|
+
return result.code
|
|
225
237
|
|
|
226
238
|
|
|
227
239
|
def _update(
|
|
@@ -249,5 +261,8 @@ def _update(
|
|
|
249
261
|
return 0
|
|
250
262
|
|
|
251
263
|
|
|
264
|
+
run_ratchet = main
|
|
265
|
+
|
|
266
|
+
|
|
252
267
|
if __name__ == "__main__":
|
|
253
268
|
sys.exit(main())
|
{sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/_registry.py
RENAMED
|
@@ -33,6 +33,7 @@ from sarj_python_lint.rules.no_copied_inherited_docstring import NoCopiedInherit
|
|
|
33
33
|
from sarj_python_lint.rules.no_cors_wildcard_with_credentials import (
|
|
34
34
|
NoCorsWildcardWithCredentials,
|
|
35
35
|
)
|
|
36
|
+
from sarj_python_lint.rules.no_dunder_all import NoDunderAll
|
|
36
37
|
from sarj_python_lint.rules.no_duplicate_dunder_all_entry import NoDuplicateDunderAllEntry
|
|
37
38
|
from sarj_python_lint.rules.no_fastapi_on_event import NoFastapiOnEvent
|
|
38
39
|
from sarj_python_lint.rules.no_file_level_escape_hatch_suppression import (
|
|
@@ -91,6 +92,7 @@ from sarj_python_lint.rules.prefer_immutable_module_constant import (
|
|
|
91
92
|
from sarj_python_lint.rules.prefer_library_fake import PreferLibraryFake
|
|
92
93
|
from sarj_python_lint.rules.prefer_match_assert_never import PreferMatchAssertNever
|
|
93
94
|
from sarj_python_lint.rules.prefer_match_type_dispatch import PreferMatchTypeDispatch
|
|
95
|
+
from sarj_python_lint.rules.prefer_match_value_dispatch import PreferMatchValueDispatch
|
|
94
96
|
from sarj_python_lint.rules.prefer_module_level_constant import (
|
|
95
97
|
PreferModuleLevelConstant,
|
|
96
98
|
)
|
|
@@ -217,6 +219,7 @@ REGISTRY: Mapping[str, type[Rule]] = MappingProxyType(
|
|
|
217
219
|
RequirePortForService.id: RequirePortForService,
|
|
218
220
|
PreferNonNullableCollection.id: PreferNonNullableCollection,
|
|
219
221
|
PreferMatchTypeDispatch.id: PreferMatchTypeDispatch,
|
|
222
|
+
PreferMatchValueDispatch.id: PreferMatchValueDispatch,
|
|
220
223
|
PreferWalrusRegexMatch.id: PreferWalrusRegexMatch,
|
|
221
224
|
PreferWalrusComprehensionFilter.id: PreferWalrusComprehensionFilter,
|
|
222
225
|
PreferWalrusStreamLoop.id: PreferWalrusStreamLoop,
|
|
@@ -224,6 +227,7 @@ REGISTRY: Mapping[str, type[Rule]] = MappingProxyType(
|
|
|
224
227
|
PreferSetIsdisjoint.id: PreferSetIsdisjoint,
|
|
225
228
|
PreferSelfDocumentingConstant.id: PreferSelfDocumentingConstant,
|
|
226
229
|
NoDuplicateDunderAllEntry.id: NoDuplicateDunderAllEntry,
|
|
230
|
+
NoDunderAll.id: NoDunderAll,
|
|
227
231
|
NoCopiedInheritedDocstring.id: NoCopiedInheritedDocstring,
|
|
228
232
|
RedundantClassDocstring.id: RedundantClassDocstring,
|
|
229
233
|
RedundantModuleDocstring.id: RedundantModuleDocstring,
|
|
@@ -250,5 +254,3 @@ REGISTRY: Mapping[str, type[Rule]] = MappingProxyType(
|
|
|
250
254
|
TypedErrorReasons.id: TypedErrorReasons,
|
|
251
255
|
}
|
|
252
256
|
)
|
|
253
|
-
|
|
254
|
-
__all__ = ["REGISTRY"]
|
{sarj_python_lint-0.80.14 → sarj_python_lint-0.80.17}/src/sarj_python_lint/rules/no_comment_cruft.py
RENAMED
|
@@ -4,6 +4,7 @@ import ast
|
|
|
4
4
|
from pathlib import PurePosixPath
|
|
5
5
|
import re
|
|
6
6
|
import tokenize
|
|
7
|
+
import tomllib
|
|
7
8
|
from typing import TYPE_CHECKING, ClassVar, override
|
|
8
9
|
|
|
9
10
|
from sarj_python_lint.rule_base import (
|
|
@@ -227,6 +228,27 @@ _CODING_COOKIE_RE = re.compile(r"coding[:=]\s*[-_.a-zA-Z0-9]+")
|
|
|
227
228
|
# Only `>>>` arms a doctest block.
|
|
228
229
|
_DOCTEST_PROMPT = ">>>"
|
|
229
230
|
|
|
231
|
+
_SCRIPT_METADATA_RE = re.compile(r"^# /// script\n(?P<content>(?:#(?: .*)?\n)+)# ///(?=\n|$)", re.MULTILINE)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _script_metadata_lines(source: str, standalone: Sequence[PositionedComment]) -> frozenset[int]:
|
|
235
|
+
normalized = "\n".join(source.splitlines())
|
|
236
|
+
matches = list(_SCRIPT_METADATA_RE.finditer(normalized))
|
|
237
|
+
if len(matches) != 1:
|
|
238
|
+
return frozenset()
|
|
239
|
+
match = matches[0]
|
|
240
|
+
first = normalized.count("\n", 0, match.start()) + 1
|
|
241
|
+
lines = frozenset(range(first, first + match.group().count("\n") + 1))
|
|
242
|
+
top_level = {line for line, col, _ in standalone if col == 0}
|
|
243
|
+
if not lines <= top_level:
|
|
244
|
+
return frozenset()
|
|
245
|
+
content = "\n".join(line[2:] if line.startswith("# ") else "" for line in match.group("content").splitlines())
|
|
246
|
+
try:
|
|
247
|
+
tomllib.loads(content)
|
|
248
|
+
except tomllib.TOMLDecodeError:
|
|
249
|
+
return frozenset()
|
|
250
|
+
return lines
|
|
251
|
+
|
|
230
252
|
|
|
231
253
|
def _is_coding_cookie(body: str) -> bool:
|
|
232
254
|
return bool(_CODING_COOKIE_RE.search(body))
|
|
@@ -499,6 +521,8 @@ class NoCommentCruft(Rule):
|
|
|
499
521
|
standalone, first_code_line = standalone_comments(source)
|
|
500
522
|
except tokenize.TokenError, IndentationError, SyntaxError:
|
|
501
523
|
return []
|
|
524
|
+
skip = _script_metadata_lines(source, standalone)
|
|
525
|
+
standalone = [comment for comment in standalone if comment.line not in skip]
|
|
502
526
|
diags: dict[int, Diagnostic] = {}
|
|
503
527
|
by_line = {line: (col, body) for line, col, body in standalone}
|
|
504
528
|
skip = _doctest_block_lines(standalone) | _illustration_block_lines(standalone)
|