code-prune 1.6.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.6.0 → code_prune-1.7.0}/CHANGELOG.md +10 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/PKG-INFO +5 -4
- {code_prune-1.6.0 → code_prune-1.7.0}/README.md +4 -3
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/__init__.py +1 -1
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/store.py +30 -3
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/suppression.py +20 -3
- {code_prune-1.6.0 → code_prune-1.7.0}/pyproject.toml +1 -1
- {code_prune-1.6.0 → code_prune-1.7.0}/LICENSE +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/.codepruneignore +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/cli.py +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/config.ini +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/config.py +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/language_tables.py +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/logging.ini +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/parser.py +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/reporter.py +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/scanner.py +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/searcher.py +0 -0
- {code_prune-1.6.0 → code_prune-1.7.0}/code_prune/symbol_ignore +0 -0
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
|
|
3
13
|
## 1.6.0 - 2026-11-29
|
|
4
14
|
|
|
5
15
|
### 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
|
|
@@ -173,7 +174,7 @@ 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
176
|
annotated that way, which covers all of its members) are skipped as well, as are
|
|
176
|
-
Gosu declarations annotated with `@Export
|
|
177
|
+
Gosu declarations annotated with `@Export` (on a class, this covers its members).
|
|
177
178
|
|
|
178
179
|
## Development
|
|
179
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
|
|
@@ -117,7 +118,7 @@ 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
120
|
annotated that way, which covers all of its members) are skipped as well, as are
|
|
120
|
-
Gosu declarations annotated with `@Export
|
|
121
|
+
Gosu declarations annotated with `@Export` (on a class, this covers its members).
|
|
121
122
|
|
|
122
123
|
## Development
|
|
123
124
|
|
|
@@ -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"``, or when a Gosu declaration is annotated ``@Export``.
|
|
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
|
|
@@ -182,8 +183,8 @@ def _is_override(node: Node, source_bytes: bytes, language: str) -> bool:
|
|
|
182
183
|
)
|
|
183
184
|
|
|
184
185
|
|
|
185
|
-
def
|
|
186
|
-
"""Return whether *node* carries an ``@Export``-style annotation.
|
|
186
|
+
def _is_exported_here(node: Node, source_bytes: bytes, language: str) -> bool:
|
|
187
|
+
"""Return whether *node* itself carries an ``@Export``-style annotation.
|
|
187
188
|
|
|
188
189
|
Author: Ron Webb
|
|
189
190
|
Since: 1.6.0
|
|
@@ -195,6 +196,22 @@ def _is_exported(node: Node, source_bytes: bytes, language: str) -> bool:
|
|
|
195
196
|
)
|
|
196
197
|
|
|
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
|
+
|
|
198
215
|
def is_exempt_symbol(node: Node, source_bytes: bytes, language: str) -> bool:
|
|
199
216
|
"""Return whether the declaration *node* must not be an unused-symbol finding.
|
|
200
217
|
|
|
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
|
|
File without changes
|