code-prune 1.2.0__tar.gz → 1.4.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.2.0 → code_prune-1.4.0}/CHANGELOG.md +34 -0
- {code_prune-1.2.0 → code_prune-1.4.0}/PKG-INFO +11 -8
- {code_prune-1.2.0 → code_prune-1.4.0}/README.md +10 -7
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/__init__.py +1 -1
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/cli.py +72 -22
- code_prune-1.4.0/code_prune/language_tables.py +170 -0
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/logging.ini +2 -2
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/scanner.py +255 -190
- code_prune-1.4.0/code_prune/searcher.py +273 -0
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/store.py +12 -8
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/symbol_ignore +1 -0
- {code_prune-1.2.0 → code_prune-1.4.0}/pyproject.toml +1 -1
- code_prune-1.2.0/code_prune/searcher.py +0 -145
- {code_prune-1.2.0 → code_prune-1.4.0}/LICENSE +0 -0
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/.codepruneignore +0 -0
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/config.ini +0 -0
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/config.py +0 -0
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/parser.py +0 -0
- {code_prune-1.2.0 → code_prune-1.4.0}/code_prune/reporter.py +0 -0
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.0 - 2026-11-22
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- The `--search-path` textual symbol search now shows a live progress bar
|
|
8
|
+
(file count and elapsed time) while it reads through the search files,
|
|
9
|
+
instead of leaving the CLI apparently idle after the "Scanning" phase
|
|
10
|
+
finishes.
|
|
11
|
+
- The `--search-path` search is much faster on large search sets: each file is
|
|
12
|
+
tokenized once and matched against all candidate names at once (instead of
|
|
13
|
+
testing every candidate against every file), and search files are read in
|
|
14
|
+
parallel using `--workers`. File discovery also uses `os.scandir`.
|
|
15
|
+
|
|
16
|
+
## 1.3.0 - 2026-11-16
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- `unused-symbol` now also reports unused fields/attributes (kind `field`):
|
|
21
|
+
class-level fields in Python, JavaScript (including `#private`), TypeScript
|
|
22
|
+
(including interface properties and constructor parameter properties), Java
|
|
23
|
+
(including enum constants) and Gosu (`var` fields without an `as` alias), plus
|
|
24
|
+
Python `self.x = ...` attributes assigned in methods.
|
|
25
|
+
- `--search-path` applies to fields with the same rule as methods: the field
|
|
26
|
+
name and its enclosing class's name must both be found in the same file.
|
|
27
|
+
- `serialVersionUID` is ignored by the default `symbol_ignore`.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- Private JavaScript/TypeScript property usages (`this.#x`) are now counted as
|
|
32
|
+
identifier usages.
|
|
33
|
+
- `code_prune.log` now uses a `RotatingFileHandler` (10 MB per file, 10 backups)
|
|
34
|
+
with UTF-8 encoding, instead of an unbounded, platform-default-encoded
|
|
35
|
+
`FileHandler`.
|
|
36
|
+
|
|
3
37
|
## 1.2.0 - 2026-11-15
|
|
4
38
|
|
|
5
39
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: code-prune
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.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,
|
|
@@ -73,8 +73,11 @@ TypeScript, Java, and Gosu**:
|
|
|
73
73
|
(`False`/`false`/`0`). Comments are never reported as unreachable.
|
|
74
74
|
- **Unused imports & local variables** — per-file, syntactic detection of
|
|
75
75
|
bindings that are never referenced again in the same file.
|
|
76
|
-
- **Unused functions/classes/methods** — cross-file detection of
|
|
77
|
-
that are never referenced anywhere in the scanned project.
|
|
76
|
+
- **Unused functions/classes/methods/fields** — cross-file detection of
|
|
77
|
+
definitions that are never referenced anywhere in the scanned project. Fields
|
|
78
|
+
cover class-level fields in every language, Python `self.x` attributes,
|
|
79
|
+
JavaScript `#private` fields, TypeScript interface properties and constructor
|
|
80
|
+
parameter properties, and Java enum constants.
|
|
78
81
|
- **Obsolete markers** — `@deprecated`/`@Deprecated`-style decorators and
|
|
79
82
|
annotations, plus comments mentioning `deprecated`.
|
|
80
83
|
- **TODO markers** — `TODO`/`FIXME`/`XXX` comment tags (not necessarily
|
|
@@ -117,10 +120,10 @@ Common options:
|
|
|
117
120
|
| `--format` | Output format: `json`, `html`, or `all` (default: `json`). |
|
|
118
121
|
| `--output` | Base output filename without extension (default: `code-prune-output`). |
|
|
119
122
|
| `--output-dir` | Directory for the report file(s) (default: `reports`). |
|
|
120
|
-
| `--workers` | Number of parallel worker threads used to scan files.
|
|
123
|
+
| `--workers` | Number of parallel worker threads used to scan files and to read `--search-path` files. |
|
|
121
124
|
| `--db` | Path to the SQLite scratch database used during a scan run. |
|
|
122
125
|
| `--target-list` | Treat `path` as a file listing target paths, one per line. |
|
|
123
|
-
| `--search-path` | Files and/or directories (separated by `;`) searched textually for each `unused-symbol` candidate; a symbol found there is not reported. Classes
|
|
126
|
+
| `--search-path` | Files and/or directories (separated by `;`) searched textually for each `unused-symbol` candidate; a symbol found there is not reported. Classes, functions/methods and fields are all matched by a whole-word regex; a method or field additionally requires its enclosing class's name to appear in the same file. The symbol's own file is skipped and `.codepruneignore` rules apply. |
|
|
124
127
|
| `--search-ext` | Comma-separated extensions of the files searched in `--search-path` (e.g. `xml,json`). Omit to search every text file. Requires `--search-path`. |
|
|
125
128
|
|
|
126
129
|
Example:
|
|
@@ -161,8 +164,8 @@ It always uses that fixed name and is not affected by `config.ini`.
|
|
|
161
164
|
### Ignoring symbol names
|
|
162
165
|
|
|
163
166
|
`symbol_ignore` holds one regex pattern per line, matched against symbol
|
|
164
|
-
names to suppress from "unused function/class/method" findings — useful for
|
|
165
|
-
dunder methods, `main`, test hooks (`test_*`, `setUp`), and similar
|
|
167
|
+
names to suppress from "unused function/class/method/field" findings — useful for
|
|
168
|
+
dunder methods, `main`, test hooks (`test_*`, `setUp`), `serialVersionUID`, and similar
|
|
166
169
|
intentionally-unreferenced symbols.
|
|
167
170
|
|
|
168
171
|
## Development
|
|
@@ -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,
|
|
@@ -17,8 +17,11 @@ TypeScript, Java, and Gosu**:
|
|
|
17
17
|
(`False`/`false`/`0`). Comments are never reported as unreachable.
|
|
18
18
|
- **Unused imports & local variables** — per-file, syntactic detection of
|
|
19
19
|
bindings that are never referenced again in the same file.
|
|
20
|
-
- **Unused functions/classes/methods** — cross-file detection of
|
|
21
|
-
that are never referenced anywhere in the scanned project.
|
|
20
|
+
- **Unused functions/classes/methods/fields** — cross-file detection of
|
|
21
|
+
definitions that are never referenced anywhere in the scanned project. Fields
|
|
22
|
+
cover class-level fields in every language, Python `self.x` attributes,
|
|
23
|
+
JavaScript `#private` fields, TypeScript interface properties and constructor
|
|
24
|
+
parameter properties, and Java enum constants.
|
|
22
25
|
- **Obsolete markers** — `@deprecated`/`@Deprecated`-style decorators and
|
|
23
26
|
annotations, plus comments mentioning `deprecated`.
|
|
24
27
|
- **TODO markers** — `TODO`/`FIXME`/`XXX` comment tags (not necessarily
|
|
@@ -61,10 +64,10 @@ Common options:
|
|
|
61
64
|
| `--format` | Output format: `json`, `html`, or `all` (default: `json`). |
|
|
62
65
|
| `--output` | Base output filename without extension (default: `code-prune-output`). |
|
|
63
66
|
| `--output-dir` | Directory for the report file(s) (default: `reports`). |
|
|
64
|
-
| `--workers` | Number of parallel worker threads used to scan files.
|
|
67
|
+
| `--workers` | Number of parallel worker threads used to scan files and to read `--search-path` files. |
|
|
65
68
|
| `--db` | Path to the SQLite scratch database used during a scan run. |
|
|
66
69
|
| `--target-list` | Treat `path` as a file listing target paths, one per line. |
|
|
67
|
-
| `--search-path` | Files and/or directories (separated by `;`) searched textually for each `unused-symbol` candidate; a symbol found there is not reported. Classes
|
|
70
|
+
| `--search-path` | Files and/or directories (separated by `;`) searched textually for each `unused-symbol` candidate; a symbol found there is not reported. Classes, functions/methods and fields are all matched by a whole-word regex; a method or field additionally requires its enclosing class's name to appear in the same file. The symbol's own file is skipped and `.codepruneignore` rules apply. |
|
|
68
71
|
| `--search-ext` | Comma-separated extensions of the files searched in `--search-path` (e.g. `xml,json`). Omit to search every text file. Requires `--search-path`. |
|
|
69
72
|
|
|
70
73
|
Example:
|
|
@@ -105,8 +108,8 @@ It always uses that fixed name and is not affected by `config.ini`.
|
|
|
105
108
|
### Ignoring symbol names
|
|
106
109
|
|
|
107
110
|
`symbol_ignore` holds one regex pattern per line, matched against symbol
|
|
108
|
-
names to suppress from "unused function/class/method" findings — useful for
|
|
109
|
-
dunder methods, `main`, test hooks (`test_*`, `setUp`), and similar
|
|
111
|
+
names to suppress from "unused function/class/method/field" findings — useful for
|
|
112
|
+
dunder methods, `main`, test hooks (`test_*`, `setUp`), `serialVersionUID`, and similar
|
|
110
113
|
intentionally-unreferenced symbols.
|
|
111
114
|
|
|
112
115
|
## Development
|
|
@@ -8,6 +8,7 @@ from __future__ import annotations
|
|
|
8
8
|
|
|
9
9
|
import concurrent.futures
|
|
10
10
|
import os
|
|
11
|
+
import re
|
|
11
12
|
import sys
|
|
12
13
|
import tempfile
|
|
13
14
|
import uuid
|
|
@@ -34,12 +35,12 @@ from . import CONF_DIR
|
|
|
34
35
|
from . import PATH_IGNORE_PATH
|
|
35
36
|
from . import SYMBOL_IGNORE_PATH
|
|
36
37
|
from .config import Config
|
|
38
|
+
from .language_tables import SUPPORTED_EXTENSIONS
|
|
37
39
|
from .reporter import write_outputs
|
|
38
40
|
from .scanner import (
|
|
39
41
|
CATEGORY_UNUSED_ALIAS,
|
|
40
42
|
CATEGORY_UNUSED_SYMBOL,
|
|
41
43
|
CLI_CATEGORIES,
|
|
42
|
-
SUPPORTED_EXTENSIONS,
|
|
43
44
|
UNUSED_CATEGORIES,
|
|
44
45
|
load_name_ignore_patterns,
|
|
45
46
|
scan_file,
|
|
@@ -276,13 +277,15 @@ def _walk_unignored(
|
|
|
276
277
|
Author: Ron Webb
|
|
277
278
|
Since: 1.0.0
|
|
278
279
|
"""
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
280
|
+
with os.scandir(root) as entries:
|
|
281
|
+
for entry in entries:
|
|
282
|
+
path = Path(entry.path)
|
|
283
|
+
if ignore is not None and ignore.is_ignored(path):
|
|
284
|
+
continue
|
|
285
|
+
if entry.is_dir():
|
|
286
|
+
yield from _walk_unignored(path, ignore)
|
|
287
|
+
elif entry.is_file():
|
|
288
|
+
yield path
|
|
286
289
|
|
|
287
290
|
|
|
288
291
|
def discover_files(
|
|
@@ -324,6 +327,26 @@ def discover_files(
|
|
|
324
327
|
return [f for f in candidates if f.suffix.lower() in allowed]
|
|
325
328
|
|
|
326
329
|
|
|
330
|
+
def _build_progress() -> Progress:
|
|
331
|
+
"""Return a :class:`~rich.progress.Progress` with the CLI's standard columns.
|
|
332
|
+
|
|
333
|
+
Shared by every long-running phase (file scanning, symbol search) so they
|
|
334
|
+
all render a spinner, bar, completed-count and elapsed time consistently.
|
|
335
|
+
|
|
336
|
+
Author: Ron Webb
|
|
337
|
+
Since: 1.4.0
|
|
338
|
+
"""
|
|
339
|
+
return Progress(
|
|
340
|
+
SpinnerColumn(),
|
|
341
|
+
TextColumn("[progress.description]{task.description}"),
|
|
342
|
+
BarColumn(),
|
|
343
|
+
MofNCompleteColumn(),
|
|
344
|
+
TimeElapsedColumn(),
|
|
345
|
+
console=_console,
|
|
346
|
+
transient=True,
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
|
|
327
350
|
def _run_concurrent_scan(
|
|
328
351
|
files: list[Path],
|
|
329
352
|
store: SessionStore,
|
|
@@ -338,15 +361,7 @@ def _run_concurrent_scan(
|
|
|
338
361
|
Author: Ron Webb
|
|
339
362
|
Since: 1.0.0
|
|
340
363
|
"""
|
|
341
|
-
with
|
|
342
|
-
SpinnerColumn(),
|
|
343
|
-
TextColumn("[progress.description]{task.description}"),
|
|
344
|
-
BarColumn(),
|
|
345
|
-
MofNCompleteColumn(),
|
|
346
|
-
TimeElapsedColumn(),
|
|
347
|
-
console=_console,
|
|
348
|
-
transient=True,
|
|
349
|
-
) as progress:
|
|
364
|
+
with _build_progress() as progress:
|
|
350
365
|
task = progress.add_task("[cyan]Scanning\u2026", total=len(files))
|
|
351
366
|
with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as executor:
|
|
352
367
|
futures = {
|
|
@@ -405,7 +420,8 @@ def _run_concurrent_scan(
|
|
|
405
420
|
type=int,
|
|
406
421
|
default=min(32, (os.cpu_count() or 1) + 4),
|
|
407
422
|
help=(
|
|
408
|
-
"Number of parallel worker threads used to scan files "
|
|
423
|
+
"Number of parallel worker threads used to scan files and to read "
|
|
424
|
+
"--search-path files "
|
|
409
425
|
"(default: min(32, cpu_count + 4))."
|
|
410
426
|
),
|
|
411
427
|
)
|
|
@@ -508,7 +524,7 @@ def main( # pylint: disable=too-many-arguments,too-many-positional-arguments,to
|
|
|
508
524
|
|
|
509
525
|
_console.print(f"[bold]Scanning[/bold] {len(files)} file(s)\u2026")
|
|
510
526
|
|
|
511
|
-
searcher = _build_searcher(search_paths, search_extensions)
|
|
527
|
+
searcher = _build_searcher(search_paths, search_extensions, workers)
|
|
512
528
|
findings, interrupted = _scan_project(
|
|
513
529
|
files, db_path, workers, selected_categories, searcher
|
|
514
530
|
)
|
|
@@ -558,10 +574,12 @@ def _discover_all_files(
|
|
|
558
574
|
|
|
559
575
|
|
|
560
576
|
def _build_searcher(
|
|
561
|
-
search_paths: list[Path], search_extensions: list[str]
|
|
577
|
+
search_paths: list[Path], search_extensions: list[str], workers: int = 1
|
|
562
578
|
) -> SymbolSearcher | None:
|
|
563
579
|
"""Build a :class:`SymbolSearcher` over *search_paths*, or ``None`` when unset.
|
|
564
580
|
|
|
581
|
+
*workers* is the number of threads used to read the search files.
|
|
582
|
+
|
|
565
583
|
Author: Ron Webb
|
|
566
584
|
Since: 1.2.0
|
|
567
585
|
"""
|
|
@@ -569,7 +587,37 @@ def _build_searcher(
|
|
|
569
587
|
return None
|
|
570
588
|
search_files = _discover_all_files(search_paths, search_extensions, False)
|
|
571
589
|
_logger.info("Searching %s file(s) for unused-symbol references", len(search_files))
|
|
572
|
-
return SymbolSearcher(search_files)
|
|
590
|
+
return SymbolSearcher(search_files, workers)
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
def _compute_unused_symbols(
|
|
594
|
+
store: SessionStore,
|
|
595
|
+
session_id: str,
|
|
596
|
+
name_ignore_patterns: list[re.Pattern[str]],
|
|
597
|
+
searcher: SymbolSearcher | None,
|
|
598
|
+
) -> list[dict[str, object]]:
|
|
599
|
+
"""Resolve ``unused-symbol`` findings, reporting progress when *searcher* is set.
|
|
600
|
+
|
|
601
|
+
Without a search path this is instant (a single SQL anti-join), so no
|
|
602
|
+
progress bar is shown. With one, every search file has to be read
|
|
603
|
+
textually, which can take a while and would otherwise leave the CLI
|
|
604
|
+
looking unresponsive; a live progress bar is shown in that case.
|
|
605
|
+
|
|
606
|
+
Author: Ron Webb
|
|
607
|
+
Since: 1.4.0
|
|
608
|
+
"""
|
|
609
|
+
if searcher is None:
|
|
610
|
+
return store.compute_unused_symbols(session_id, name_ignore_patterns)
|
|
611
|
+
with _build_progress() as progress:
|
|
612
|
+
task = progress.add_task(
|
|
613
|
+
"[cyan]Searching for symbol references\u2026", total=searcher.file_count
|
|
614
|
+
)
|
|
615
|
+
return store.compute_unused_symbols(
|
|
616
|
+
session_id,
|
|
617
|
+
name_ignore_patterns,
|
|
618
|
+
searcher,
|
|
619
|
+
on_progress=lambda: progress.advance(task),
|
|
620
|
+
)
|
|
573
621
|
|
|
574
622
|
|
|
575
623
|
def _scan_project(
|
|
@@ -594,7 +642,9 @@ def _scan_project(
|
|
|
594
642
|
if CATEGORY_UNUSED_SYMBOL in categories:
|
|
595
643
|
name_ignore_patterns = load_name_ignore_patterns(Path(SYMBOL_IGNORE_PATH))
|
|
596
644
|
findings.extend(
|
|
597
|
-
|
|
645
|
+
_compute_unused_symbols(
|
|
646
|
+
store, session_id, name_ignore_patterns, searcher
|
|
647
|
+
)
|
|
598
648
|
)
|
|
599
649
|
except KeyboardInterrupt:
|
|
600
650
|
interrupted = True
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""Per-language tree-sitter node-type tables used by the scanner.
|
|
2
|
+
|
|
3
|
+
The node types were verified empirically against each tree-sitter grammar
|
|
4
|
+
before being hard-coded here.
|
|
5
|
+
|
|
6
|
+
Author: Ron Webb
|
|
7
|
+
Since: 1.3.0
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
EXTENSION_TO_LANGUAGE: dict[str, str] = {
|
|
13
|
+
".py": "Python",
|
|
14
|
+
".pyi": "Python",
|
|
15
|
+
".js": "JavaScript",
|
|
16
|
+
".mjs": "JavaScript",
|
|
17
|
+
".cjs": "JavaScript",
|
|
18
|
+
".ts": "TypeScript",
|
|
19
|
+
".tsx": "TypeScript",
|
|
20
|
+
".java": "Java",
|
|
21
|
+
".gs": "Gosu",
|
|
22
|
+
".gsx": "Gosu",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#: File extensions the scanner can parse.
|
|
26
|
+
SUPPORTED_EXTENSIONS = frozenset(EXTENSION_TO_LANGUAGE)
|
|
27
|
+
|
|
28
|
+
#: Function/method definition node types, per language.
|
|
29
|
+
FUNCTION_NODE_TYPES: dict[str, frozenset[str]] = {
|
|
30
|
+
"Python": frozenset({"function_definition"}),
|
|
31
|
+
"JavaScript": frozenset(
|
|
32
|
+
{
|
|
33
|
+
"function_declaration",
|
|
34
|
+
"function_expression",
|
|
35
|
+
"arrow_function",
|
|
36
|
+
"method_definition",
|
|
37
|
+
}
|
|
38
|
+
),
|
|
39
|
+
"TypeScript": frozenset(
|
|
40
|
+
{
|
|
41
|
+
"function_declaration",
|
|
42
|
+
"function_expression",
|
|
43
|
+
"arrow_function",
|
|
44
|
+
"method_definition",
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
"Java": frozenset({"method_declaration", "constructor_declaration"}),
|
|
48
|
+
"Gosu": frozenset({"function_declaration", "constructor_declaration"}),
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#: Class/interface definition node types, per language.
|
|
52
|
+
CLASS_NODE_TYPES: dict[str, frozenset[str]] = {
|
|
53
|
+
"Python": frozenset({"class_definition"}),
|
|
54
|
+
"JavaScript": frozenset({"class_declaration"}),
|
|
55
|
+
"TypeScript": frozenset({"class_declaration", "interface_declaration"}),
|
|
56
|
+
"Java": frozenset(
|
|
57
|
+
{"class_declaration", "interface_declaration", "enum_declaration"}
|
|
58
|
+
),
|
|
59
|
+
"Gosu": frozenset({"class_declaration"}),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#: Field/attribute declaration node types, per language. Python class-level
|
|
63
|
+
#: fields are plain ``assignment`` nodes; ``self.x = ...`` attributes are found
|
|
64
|
+
#: separately inside methods.
|
|
65
|
+
FIELD_NODE_TYPES: dict[str, frozenset[str]] = {
|
|
66
|
+
"Python": frozenset({"assignment"}),
|
|
67
|
+
"JavaScript": frozenset({"field_definition"}),
|
|
68
|
+
"TypeScript": frozenset({"public_field_definition", "property_signature"}),
|
|
69
|
+
"Java": frozenset({"field_declaration", "enum_constant"}),
|
|
70
|
+
"Gosu": frozenset({"field_declaration"}),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#: Grammar field holding the declared name of a field node (default ``name``).
|
|
74
|
+
FIELD_NAME_FIELD: dict[str, str] = {"Python": "left", "JavaScript": "property"}
|
|
75
|
+
|
|
76
|
+
#: Node types a field name may have.
|
|
77
|
+
FIELD_NAME_NODE_TYPES = frozenset(
|
|
78
|
+
{"identifier", "property_identifier", "private_property_identifier"}
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
#: Modifiers that turn a TypeScript constructor parameter into a field.
|
|
82
|
+
PARAMETER_PROPERTY_MODIFIERS = frozenset({"accessibility_modifier", "readonly"})
|
|
83
|
+
|
|
84
|
+
#: Import/uses-clause node types, per language.
|
|
85
|
+
IMPORT_NODE_TYPES: dict[str, frozenset[str]] = {
|
|
86
|
+
"Python": frozenset({"import_statement", "import_from_statement"}),
|
|
87
|
+
"JavaScript": frozenset({"import_statement"}),
|
|
88
|
+
"TypeScript": frozenset({"import_statement"}),
|
|
89
|
+
"Java": frozenset({"import_declaration"}),
|
|
90
|
+
"Gosu": frozenset({"uses_declaration"}),
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#: Local-variable declaration/assignment node types, per language.
|
|
94
|
+
LOCAL_DECL_NODE_TYPES: dict[str, frozenset[str]] = {
|
|
95
|
+
"Python": frozenset({"assignment"}),
|
|
96
|
+
"JavaScript": frozenset({"variable_declarator"}),
|
|
97
|
+
"TypeScript": frozenset({"variable_declarator"}),
|
|
98
|
+
"Java": frozenset({"variable_declarator"}),
|
|
99
|
+
"Gosu": frozenset({"local_variable_declaration"}),
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#: Statements that terminate control flow within a block, per language.
|
|
103
|
+
TERMINATING_STATEMENT_TYPES: dict[str, frozenset[str]] = {
|
|
104
|
+
"Python": frozenset(
|
|
105
|
+
{"return_statement", "raise_statement", "break_statement", "continue_statement"}
|
|
106
|
+
),
|
|
107
|
+
"JavaScript": frozenset(
|
|
108
|
+
{"return_statement", "throw_statement", "break_statement", "continue_statement"}
|
|
109
|
+
),
|
|
110
|
+
"TypeScript": frozenset(
|
|
111
|
+
{"return_statement", "throw_statement", "break_statement", "continue_statement"}
|
|
112
|
+
),
|
|
113
|
+
"Java": frozenset(
|
|
114
|
+
{"return_statement", "throw_statement", "break_statement", "continue_statement"}
|
|
115
|
+
),
|
|
116
|
+
"Gosu": frozenset(
|
|
117
|
+
{"return_statement", "throw_statement", "break_statement", "continue_statement"}
|
|
118
|
+
),
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#: Node types whose direct named children form a sequential statement list.
|
|
122
|
+
BLOCK_NODE_TYPES: dict[str, frozenset[str]] = {
|
|
123
|
+
"Python": frozenset({"block"}),
|
|
124
|
+
"JavaScript": frozenset({"statement_block"}),
|
|
125
|
+
"TypeScript": frozenset({"statement_block"}),
|
|
126
|
+
"Java": frozenset({"block"}),
|
|
127
|
+
"Gosu": frozenset({"statement_block"}),
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
#: Comment node types, per language.
|
|
131
|
+
COMMENT_NODE_TYPES: dict[str, frozenset[str]] = {
|
|
132
|
+
"Python": frozenset({"comment"}),
|
|
133
|
+
"JavaScript": frozenset({"comment"}),
|
|
134
|
+
"TypeScript": frozenset({"comment"}),
|
|
135
|
+
"Java": frozenset({"line_comment", "block_comment"}),
|
|
136
|
+
"Gosu": frozenset({"line_comment", "block_comment"}),
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#: Decorator/annotation node types consulted for deprecation markers.
|
|
140
|
+
DECORATOR_NODE_TYPES: dict[str, frozenset[str]] = {
|
|
141
|
+
"Python": frozenset({"decorator"}),
|
|
142
|
+
"JavaScript": frozenset(),
|
|
143
|
+
"TypeScript": frozenset({"decorator"}),
|
|
144
|
+
"Java": frozenset({"marker_annotation", "annotation"}),
|
|
145
|
+
"Gosu": frozenset({"annotation"}),
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#: Identifier-like node types counted as a "usage" of a name.
|
|
149
|
+
USAGE_NODE_TYPES: dict[str, frozenset[str]] = {
|
|
150
|
+
"Python": frozenset({"identifier"}),
|
|
151
|
+
"JavaScript": frozenset(
|
|
152
|
+
{
|
|
153
|
+
"identifier",
|
|
154
|
+
"property_identifier",
|
|
155
|
+
"private_property_identifier",
|
|
156
|
+
"shorthand_property_identifier",
|
|
157
|
+
}
|
|
158
|
+
),
|
|
159
|
+
"TypeScript": frozenset(
|
|
160
|
+
{
|
|
161
|
+
"identifier",
|
|
162
|
+
"property_identifier",
|
|
163
|
+
"private_property_identifier",
|
|
164
|
+
"shorthand_property_identifier",
|
|
165
|
+
"type_identifier",
|
|
166
|
+
}
|
|
167
|
+
),
|
|
168
|
+
"Java": frozenset({"identifier", "type_identifier"}),
|
|
169
|
+
"Gosu": frozenset({"identifier"}),
|
|
170
|
+
}
|
|
@@ -17,9 +17,9 @@ formatter=consoleFormatter
|
|
|
17
17
|
args=(sys.stderr,)
|
|
18
18
|
|
|
19
19
|
[handler_fileHandler]
|
|
20
|
-
class=
|
|
20
|
+
class=handlers.RotatingFileHandler
|
|
21
21
|
formatter=logFormatter
|
|
22
|
-
args=('code_prune.log', 'a')
|
|
22
|
+
args=('code_prune.log', 'a', 10485760, 10, 'utf-8')
|
|
23
23
|
|
|
24
24
|
[formatter_logFormatter]
|
|
25
25
|
format=%(asctime)s [%(levelname)s] %(name)s - %(message)s
|