code-prune 1.5.0__tar.gz → 1.7.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.
- {code_prune-1.5.0 → code_prune-1.7.0}/CHANGELOG.md +17 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/PKG-INFO +6 -4
- {code_prune-1.5.0 → code_prune-1.7.0}/README.md +5 -3
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/__init__.py +1 -1
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/language_tables.py +3 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/store.py +30 -3
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/suppression.py +36 -3
- {code_prune-1.5.0 → code_prune-1.7.0}/pyproject.toml +1 -1
- {code_prune-1.5.0 → code_prune-1.7.0}/LICENSE +0 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/.codepruneignore +0 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/cli.py +0 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/config.ini +0 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/config.py +0 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/logging.ini +0 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/parser.py +0 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/reporter.py +0 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/scanner.py +0 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/searcher.py +0 -0
- {code_prune-1.5.0 → code_prune-1.7.0}/code_prune/symbol_ignore +0 -0
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.7.0 - 2026-11-29
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- `unused-symbol` no longer reports the methods and fields of a class that is
|
|
8
|
+
itself reported as unused (in the same file); only the class is reported,
|
|
9
|
+
since removing it removes its members. A class that is exempt (Gosu `@Export`,
|
|
10
|
+
or `@SuppressWarnings("unused"|"all")` in Java/Gosu) likewise exempts all of
|
|
11
|
+
its members.
|
|
12
|
+
|
|
13
|
+
## 1.6.0 - 2026-11-29
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- `unused-symbol` no longer reports Gosu declarations (classes, functions,
|
|
18
|
+
fields) annotated with `@Export`.
|
|
19
|
+
|
|
3
20
|
## 1.5.0 - 2026-11-29
|
|
4
21
|
|
|
5
22
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: code-prune
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.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
|
-
[](https://github.com/rcw3bb/code-prune/blob/main/LICENSE) [](https://github.com/rcw3bb/code-prune/blob/main/LICENSE) [](https://github.com/rcw3bb/code-prune/blob/main/CHANGELOG.md) [](https://www.python.org/) [](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,
|
|
@@ -77,7 +77,8 @@ TypeScript, Java, and Gosu**:
|
|
|
77
77
|
definitions that are never referenced anywhere in the scanned project. Fields
|
|
78
78
|
cover class-level fields in every language, Python `self.x` attributes,
|
|
79
79
|
JavaScript `#private` fields, TypeScript interface properties and constructor
|
|
80
|
-
parameter properties, and Java enum constants.
|
|
80
|
+
parameter properties, and Java enum constants. When a class is itself unused
|
|
81
|
+
only the class is reported, not its methods and fields.
|
|
81
82
|
- **Obsolete markers** — `@deprecated`/`@Deprecated`-style decorators and
|
|
82
83
|
annotations, plus comments mentioning `deprecated`.
|
|
83
84
|
- **TODO markers** — `TODO`/`FIXME`/`XXX` comment tags (not necessarily
|
|
@@ -172,7 +173,8 @@ Overriding members are also never reported as unused symbols: Java `@Override`,
|
|
|
172
173
|
Gosu `override` / `@Override`, TypeScript `override`, and Python `@override` /
|
|
173
174
|
`@typing.override`. In Java and Gosu, declarations annotated with
|
|
174
175
|
`@SuppressWarnings("unused")` or `@SuppressWarnings("all")` (including a class
|
|
175
|
-
annotated that way, which covers all of its members) are skipped as well
|
|
176
|
+
annotated that way, which covers all of its members) are skipped as well, as are
|
|
177
|
+
Gosu declarations annotated with `@Export` (on a class, this covers its members).
|
|
176
178
|
|
|
177
179
|
## Development
|
|
178
180
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# code-prune
|
|
2
2
|
|
|
3
|
-
[](https://github.com/rcw3bb/code-prune/blob/main/LICENSE) [](https://github.com/rcw3bb/code-prune/blob/main/LICENSE) [](https://github.com/rcw3bb/code-prune/blob/main/CHANGELOG.md) [](https://www.python.org/) [](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,
|
|
@@ -21,7 +21,8 @@ TypeScript, Java, and Gosu**:
|
|
|
21
21
|
definitions that are never referenced anywhere in the scanned project. Fields
|
|
22
22
|
cover class-level fields in every language, Python `self.x` attributes,
|
|
23
23
|
JavaScript `#private` fields, TypeScript interface properties and constructor
|
|
24
|
-
parameter properties, and Java enum constants.
|
|
24
|
+
parameter properties, and Java enum constants. When a class is itself unused
|
|
25
|
+
only the class is reported, not its methods and fields.
|
|
25
26
|
- **Obsolete markers** — `@deprecated`/`@Deprecated`-style decorators and
|
|
26
27
|
annotations, plus comments mentioning `deprecated`.
|
|
27
28
|
- **TODO markers** — `TODO`/`FIXME`/`XXX` comment tags (not necessarily
|
|
@@ -116,7 +117,8 @@ Overriding members are also never reported as unused symbols: Java `@Override`,
|
|
|
116
117
|
Gosu `override` / `@Override`, TypeScript `override`, and Python `@override` /
|
|
117
118
|
`@typing.override`. In Java and Gosu, declarations annotated with
|
|
118
119
|
`@SuppressWarnings("unused")` or `@SuppressWarnings("all")` (including a class
|
|
119
|
-
annotated that way, which covers all of its members) are skipped as well
|
|
120
|
+
annotated that way, which covers all of its members) are skipped as well, as are
|
|
121
|
+
Gosu declarations annotated with `@Export` (on a class, this covers its members).
|
|
120
122
|
|
|
121
123
|
## Development
|
|
122
124
|
|
|
@@ -163,6 +163,9 @@ SUPPRESS_WARNINGS_VALUES = frozenset({"unused", "all"})
|
|
|
163
163
|
#: Annotation names marking a method as an override.
|
|
164
164
|
OVERRIDE_ANNOTATION_NAMES = frozenset({"Override"})
|
|
165
165
|
|
|
166
|
+
#: Annotation names marking a declaration as exported (used externally), per language.
|
|
167
|
+
EXPORT_ANNOTATION_NAMES: dict[str, frozenset[str]] = {"Gosu": frozenset({"Export"})}
|
|
168
|
+
|
|
166
169
|
#: Modifier node types marking a declaration as an override, per language.
|
|
167
170
|
OVERRIDE_MODIFIER_TYPES: dict[str, frozenset[str]] = {
|
|
168
171
|
"TypeScript": frozenset({"override_modifier"}),
|
|
@@ -94,6 +94,28 @@ _DELETE_FINDINGS = "DELETE FROM findings WHERE session_id = ?"
|
|
|
94
94
|
_DELETE_DEFINITIONS = "DELETE FROM definitions WHERE session_id = ?"
|
|
95
95
|
_DELETE_IDENTIFIERS = "DELETE FROM identifiers WHERE session_id = ?"
|
|
96
96
|
|
|
97
|
+
#: ``(file_path, line, col, name, kind, enclosing_class)`` row of ``definitions``.
|
|
98
|
+
_DefinitionRow = tuple[str, int, int, str, str, str | None]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _without_unused_class_members(
|
|
102
|
+
rows: list[_DefinitionRow],
|
|
103
|
+
) -> list[_DefinitionRow]:
|
|
104
|
+
"""Drop methods/fields whose enclosing class (in the same file) is in *rows*.
|
|
105
|
+
|
|
106
|
+
*rows* holds only unused definitions, so a class present there is unused and
|
|
107
|
+
its members need no separate report.
|
|
108
|
+
|
|
109
|
+
Author: Ron Webb
|
|
110
|
+
Since: 1.7.0
|
|
111
|
+
"""
|
|
112
|
+
unused_classes = {
|
|
113
|
+
(file_path, name) for file_path, _, _, name, kind, _ in rows if kind == "class"
|
|
114
|
+
}
|
|
115
|
+
return [
|
|
116
|
+
row for row in rows if row[5] is None or (row[0], row[5]) not in unused_classes
|
|
117
|
+
]
|
|
118
|
+
|
|
97
119
|
|
|
98
120
|
class SessionStore:
|
|
99
121
|
"""SQLite-backed session store for dead-code scan results.
|
|
@@ -241,6 +263,8 @@ class SessionStore:
|
|
|
241
263
|
it finds textually referenced in the search paths are suppressed too;
|
|
242
264
|
*on_progress* (forwarded to the searcher) lets a caller drive a
|
|
243
265
|
progress indicator over that, potentially long-running, search.
|
|
266
|
+
Methods and fields of a class that is itself reported unused are
|
|
267
|
+
dropped, since removing the class removes them.
|
|
244
268
|
|
|
245
269
|
Author: Ron Webb
|
|
246
270
|
Since: 1.0.0
|
|
@@ -260,9 +284,12 @@ class SessionStore:
|
|
|
260
284
|
]
|
|
261
285
|
referenced = searcher.find_referenced(candidates, on_progress)
|
|
262
286
|
results: list[dict[str, object]] = []
|
|
263
|
-
|
|
264
|
-
if (
|
|
265
|
-
|
|
287
|
+
unreferenced = [
|
|
288
|
+
row for row in rows if (row[3], row[4], row[0], row[5]) not in referenced
|
|
289
|
+
]
|
|
290
|
+
for file_path, line, col, name, kind, _ in _without_unused_class_members(
|
|
291
|
+
unreferenced
|
|
292
|
+
):
|
|
266
293
|
results.append(
|
|
267
294
|
{
|
|
268
295
|
"category": CATEGORY_UNUSED_SYMBOL,
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
A declaration is exempt when it overrides an inherited member (it is invoked
|
|
4
4
|
through its base type, so it never has a textual usage) or, for Java and Gosu,
|
|
5
5
|
when it (or an enclosing class) carries ``@SuppressWarnings`` with ``"unused"``
|
|
6
|
-
or ``"all"``.
|
|
6
|
+
or ``"all"``, or when a Gosu declaration is annotated ``@Export``. Both
|
|
7
|
+
annotations on a class also exempt every member of that class.
|
|
7
8
|
|
|
8
9
|
Author: Ron Webb
|
|
9
10
|
Since: 1.5.0
|
|
@@ -15,6 +16,7 @@ from tree_sitter import Node # type: ignore[import-untyped]
|
|
|
15
16
|
|
|
16
17
|
from .language_tables import (
|
|
17
18
|
ANNOTATION_NODE_TYPES,
|
|
19
|
+
EXPORT_ANNOTATION_NAMES,
|
|
18
20
|
OVERRIDE_ANNOTATION_NAMES,
|
|
19
21
|
OVERRIDE_MODIFIER_TYPES,
|
|
20
22
|
SUPPRESS_WARNINGS_NAME,
|
|
@@ -181,12 +183,43 @@ def _is_override(node: Node, source_bytes: bytes, language: str) -> bool:
|
|
|
181
183
|
)
|
|
182
184
|
|
|
183
185
|
|
|
186
|
+
def _is_exported_here(node: Node, source_bytes: bytes, language: str) -> bool:
|
|
187
|
+
"""Return whether *node* itself carries an ``@Export``-style annotation.
|
|
188
|
+
|
|
189
|
+
Author: Ron Webb
|
|
190
|
+
Since: 1.6.0
|
|
191
|
+
"""
|
|
192
|
+
export_names = EXPORT_ANNOTATION_NAMES.get(language, frozenset())
|
|
193
|
+
return any(
|
|
194
|
+
_annotation_name(annotation, source_bytes) in export_names
|
|
195
|
+
for annotation in _annotations(node, language)
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _is_exported(node: Node, source_bytes: bytes, language: str) -> bool:
|
|
200
|
+
"""Return whether *node* or any enclosing declaration is ``@Export``-ed.
|
|
201
|
+
|
|
202
|
+
Author: Ron Webb
|
|
203
|
+
Since: 1.7.0
|
|
204
|
+
"""
|
|
205
|
+
if language not in EXPORT_ANNOTATION_NAMES:
|
|
206
|
+
return False
|
|
207
|
+
current: Node | None = node
|
|
208
|
+
while current is not None:
|
|
209
|
+
if _is_exported_here(current, source_bytes, language):
|
|
210
|
+
return True
|
|
211
|
+
current = current.parent
|
|
212
|
+
return False
|
|
213
|
+
|
|
214
|
+
|
|
184
215
|
def is_exempt_symbol(node: Node, source_bytes: bytes, language: str) -> bool:
|
|
185
216
|
"""Return whether the declaration *node* must not be an unused-symbol finding.
|
|
186
217
|
|
|
187
218
|
Author: Ron Webb
|
|
188
219
|
Since: 1.5.0
|
|
189
220
|
"""
|
|
190
|
-
return
|
|
191
|
-
node, source_bytes, language
|
|
221
|
+
return (
|
|
222
|
+
_is_override(node, source_bytes, language)
|
|
223
|
+
or _is_exported(node, source_bytes, language)
|
|
224
|
+
or _is_suppressed(node, source_bytes, language)
|
|
192
225
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|