code-prune 2.0.0__tar.gz → 2.1.0__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.
Files changed (23) hide show
  1. {code_prune-2.0.0 → code_prune-2.1.0}/CHANGELOG.md +9 -0
  2. {code_prune-2.0.0 → code_prune-2.1.0}/PKG-INFO +4 -4
  3. {code_prune-2.0.0 → code_prune-2.1.0}/README.md +3 -3
  4. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/__init__.py +1 -1
  5. code_prune-2.1.0/code_prune/interpolation.py +80 -0
  6. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/language_tables.py +6 -0
  7. {code_prune-2.0.0 → code_prune-2.1.0}/pyproject.toml +1 -1
  8. code_prune-2.0.0/code_prune/interpolation.py +0 -45
  9. {code_prune-2.0.0 → code_prune-2.1.0}/LICENSE +0 -0
  10. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/.codepruneignore +0 -0
  11. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/annotation_config.py +0 -0
  12. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/cli.py +0 -0
  13. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/config.ini +0 -0
  14. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/config.py +0 -0
  15. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/logging.ini +0 -0
  16. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/parser.py +0 -0
  17. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/reporter.py +0 -0
  18. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/scanner.py +0 -0
  19. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/searcher.py +0 -0
  20. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/store.py +0 -0
  21. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/suppression.py +0 -0
  22. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/suppression_annotations.json +0 -0
  23. {code_prune-2.0.0 → code_prune-2.1.0}/code_prune/symbol_ignore +0 -0
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.0 - 2026-12-05
4
+
5
+ ### Added
6
+
7
+ - Gosu string interpolation in single-quoted strings now counts as a usage:
8
+ both `'$name'` and `'${expr}'` (every identifier inside the expression), so
9
+ symbols referenced only that way are no longer reported as unused. Escaped
10
+ `\$` is ignored in both quote styles.
11
+
3
12
  ## 2.0.0 - 2026-12-04
4
13
 
5
14
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code-prune
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Find unreachable, unused, and obsolete code before it becomes technical debt.
5
5
  License: MIT License
6
6
 
@@ -56,7 +56,7 @@ Description-Content-Type: text/markdown
56
56
 
57
57
  # code-prune
58
58
 
59
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/rcw3bb/code-prune/blob/main/LICENSE) [![Version](https://img.shields.io/badge/Version-2.0.0-green.svg)](https://github.com/rcw3bb/code-prune/blob/main/CHANGELOG.md) [![Python](https://img.shields.io/badge/Python-3.14%2B-blue)](https://www.python.org/) [![PyPI](https://img.shields.io/badge/PyPI-code--prune-orange)](https://pypi.org/project/code-prune/)
59
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/rcw3bb/code-prune/blob/main/LICENSE) [![Version](https://img.shields.io/badge/Version-2.1.0-green.svg)](https://github.com/rcw3bb/code-prune/blob/main/CHANGELOG.md) [![Python](https://img.shields.io/badge/Python-3.14%2B-blue)](https://www.python.org/) [![PyPI](https://img.shields.io/badge/PyPI-code--prune-orange)](https://pypi.org/project/code-prune/)
60
60
 
61
61
 
62
62
  A CLI tool that scans a codebase for unreachable, unused, and obsolete code,
@@ -174,8 +174,8 @@ Overriding members are also never reported as unused symbols: Java `@Override`,
174
174
  Gosu `override` / `@Override`, TypeScript `override`, and Python `@override` /
175
175
  `@typing.override`.
176
176
 
177
- Gosu `$name` and `${expr}` string interpolation in double-quoted strings counts
178
- as a usage of `name` (single-quoted Gosu strings are not interpolated).
177
+ Gosu `$name` and `${expr}` string interpolation counts as a usage of `name` in
178
+ both double- and single-quoted strings.
179
179
 
180
180
  ### Suppression annotations
181
181
 
@@ -1,6 +1,6 @@
1
1
  # code-prune
2
2
 
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/rcw3bb/code-prune/blob/main/LICENSE) [![Version](https://img.shields.io/badge/Version-2.0.0-green.svg)](https://github.com/rcw3bb/code-prune/blob/main/CHANGELOG.md) [![Python](https://img.shields.io/badge/Python-3.14%2B-blue)](https://www.python.org/) [![PyPI](https://img.shields.io/badge/PyPI-code--prune-orange)](https://pypi.org/project/code-prune/)
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/rcw3bb/code-prune/blob/main/LICENSE) [![Version](https://img.shields.io/badge/Version-2.1.0-green.svg)](https://github.com/rcw3bb/code-prune/blob/main/CHANGELOG.md) [![Python](https://img.shields.io/badge/Python-3.14%2B-blue)](https://www.python.org/) [![PyPI](https://img.shields.io/badge/PyPI-code--prune-orange)](https://pypi.org/project/code-prune/)
4
4
 
5
5
 
6
6
  A CLI tool that scans a codebase for unreachable, unused, and obsolete code,
@@ -118,8 +118,8 @@ Overriding members are also never reported as unused symbols: Java `@Override`,
118
118
  Gosu `override` / `@Override`, TypeScript `override`, and Python `@override` /
119
119
  `@typing.override`.
120
120
 
121
- Gosu `$name` and `${expr}` string interpolation in double-quoted strings counts
122
- as a usage of `name` (single-quoted Gosu strings are not interpolated).
121
+ Gosu `$name` and `${expr}` string interpolation counts as a usage of `name` in
122
+ both double- and single-quoted strings.
123
123
 
124
124
  ### Suppression annotations
125
125
 
@@ -10,7 +10,7 @@ Since: 1.0.0
10
10
  from env_dir_bootstrap import EnvDirBootstrap
11
11
 
12
12
  __app_name__ = "code-prune"
13
- __version__ = "2.0.0"
13
+ __version__ = "2.1.0"
14
14
 
15
15
  _bootstrapper = EnvDirBootstrap(
16
16
  env_var="CODE_PRUNE_CONFIG_DIR",
@@ -0,0 +1,80 @@
1
+ """Usages hidden inside Gosu string interpolation.
2
+
3
+ Gosu parses ``"${expr}"`` into real identifier nodes, but a simple ``"$name"``
4
+ stays plain string text, and a single-quoted string is one opaque literal
5
+ (``'${expr}'`` is not parsed at all). Those names are real usages, so they are
6
+ extracted here and counted when deciding whether a symbol is unused.
7
+
8
+ Author: Ron Webb
9
+ Since: 2.0.0
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import re
15
+ from collections.abc import Iterable
16
+
17
+ from tree_sitter import Node # type: ignore[import-untyped]
18
+
19
+ from .language_tables import (
20
+ INTERPOLATED_LITERAL_NODE_TYPES,
21
+ INTERPOLATED_TEXT_NODE_TYPES,
22
+ )
23
+
24
+ _SIMPLE_INTERPOLATION = re.compile(r"\$([A-Za-z_][A-Za-z0-9_]*)")
25
+ _EXPRESSION_INTERPOLATION = re.compile(r"\$\{([^}]*)\}")
26
+ _IDENTIFIER = re.compile(r"[A-Za-z_][A-Za-z0-9_]*")
27
+ _ESCAPED_DOLLAR = re.compile(r"\\\$")
28
+
29
+
30
+ def _text_names(text: str) -> list[str]:
31
+ """Return the names referenced by ``$name`` / ``${expr}`` in *text*.
32
+
33
+ Author: Ron Webb
34
+ Since: 2.1.0
35
+ """
36
+ text = _ESCAPED_DOLLAR.sub("", text)
37
+ names = _SIMPLE_INTERPOLATION.findall(text)
38
+ for expression in _EXPRESSION_INTERPOLATION.findall(text):
39
+ names.extend(_IDENTIFIER.findall(expression))
40
+ return names
41
+
42
+
43
+ def interpolated_names(
44
+ nodes: Iterable[Node], source_bytes: bytes, language: str
45
+ ) -> list[str]:
46
+ """Return the names referenced through interpolation within *nodes*.
47
+
48
+ Two shapes are inspected: ``string_content`` text of a double-quoted string
49
+ (only ``$name`` there, as ``${expr}`` is already parsed into identifier
50
+ nodes and ``\\$`` is a separate escape-sequence node) and childless
51
+ single-quoted string literals, whose ``$name`` and ``${expr}`` are both raw
52
+ text.
53
+
54
+ Author: Ron Webb
55
+ Since: 2.0.0
56
+ """
57
+ text_types = INTERPOLATED_TEXT_NODE_TYPES.get(language, frozenset())
58
+ literal_types = INTERPOLATED_LITERAL_NODE_TYPES.get(language, frozenset())
59
+ names: list[str] = []
60
+ for node in nodes:
61
+ if node.type in text_types:
62
+ names.extend(
63
+ _SIMPLE_INTERPOLATION.findall(_decode_node(node, source_bytes))
64
+ )
65
+ elif node.type in literal_types and node.child_count == 0:
66
+ text = _decode_node(node, source_bytes)
67
+ if text.startswith("'"):
68
+ names.extend(_text_names(text))
69
+ return names
70
+
71
+
72
+ def _decode_node(node: Node, source_bytes: bytes) -> str:
73
+ """Return the source text covered by *node*.
74
+
75
+ Author: Ron Webb
76
+ Since: 2.1.0
77
+ """
78
+ return source_bytes[node.start_byte : node.end_byte].decode(
79
+ "utf-8", errors="replace"
80
+ )
@@ -186,6 +186,12 @@ INTERPOLATED_TEXT_NODE_TYPES: dict[str, frozenset[str]] = {
186
186
  "Gosu": frozenset({"string_content"}),
187
187
  }
188
188
 
189
+ #: Childless literal node types whose raw text may contain interpolation
190
+ #: (Gosu single-quoted strings), per language.
191
+ INTERPOLATED_LITERAL_NODE_TYPES: dict[str, frozenset[str]] = {
192
+ "Gosu": frozenset({"string_literal"}),
193
+ }
194
+
189
195
  #: Identifier-like node types counted as a "usage" of a name.
190
196
  USAGE_NODE_TYPES: dict[str, frozenset[str]] = {
191
197
  "Python": frozenset({"identifier"}),
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "code-prune"
3
- version = "2.0.0"
3
+ version = "2.1.0"
4
4
  description = "Find unreachable, unused, and obsolete code before it becomes technical debt."
5
5
  authors = [
6
6
  {name = "Ron Webb"}
@@ -1,45 +0,0 @@
1
- """Usages hidden inside Gosu string interpolation.
2
-
3
- Gosu parses ``"${expr}"`` into real identifier nodes, but a simple ``"$name"``
4
- stays plain string text. Those names are real usages, so they are extracted here
5
- and counted when deciding whether a symbol is unused. Single-quoted Gosu strings
6
- are not interpolated and are therefore ignored.
7
-
8
- Author: Ron Webb
9
- Since: 2.0.0
10
- """
11
-
12
- from __future__ import annotations
13
-
14
- import re
15
- from collections.abc import Iterable
16
-
17
- from tree_sitter import Node # type: ignore[import-untyped]
18
-
19
- from .language_tables import INTERPOLATED_TEXT_NODE_TYPES
20
-
21
- _SIMPLE_INTERPOLATION = re.compile(r"\$([A-Za-z_][A-Za-z0-9_]*)")
22
-
23
-
24
- def interpolated_names(
25
- nodes: Iterable[Node], source_bytes: bytes, language: str
26
- ) -> list[str]:
27
- """Return the names referenced as ``$name`` within string text of *nodes*.
28
-
29
- Escaped dollars (``\\$name``) are separate escape-sequence nodes in the
30
- grammar, so they never reach the text checked here.
31
-
32
- Author: Ron Webb
33
- Since: 2.0.0
34
- """
35
- text_types = INTERPOLATED_TEXT_NODE_TYPES.get(language)
36
- if not text_types:
37
- return []
38
- names: list[str] = []
39
- for node in nodes:
40
- if node.type in text_types:
41
- text = source_bytes[node.start_byte : node.end_byte].decode(
42
- "utf-8", errors="replace"
43
- )
44
- names.extend(_SIMPLE_INTERPOLATION.findall(text))
45
- return names
File without changes
File without changes