graphlint 0.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.
- graphlint-0.1.0/CHANGELOG.md +22 -0
- graphlint-0.1.0/CONTRIBUTING.md +58 -0
- graphlint-0.1.0/LICENSE +21 -0
- graphlint-0.1.0/MANIFEST.in +14 -0
- graphlint-0.1.0/PKG-INFO +181 -0
- graphlint-0.1.0/README.md +152 -0
- graphlint-0.1.0/README_PYPI.md +152 -0
- graphlint-0.1.0/docs/en/api/build.md +94 -0
- graphlint-0.1.0/docs/en/api/configure.md +168 -0
- graphlint-0.1.0/docs/en/api/exceptions.md +101 -0
- graphlint-0.1.0/docs/en/api/query.md +157 -0
- graphlint-0.1.0/docs/en/architecture/overview.md +194 -0
- graphlint-0.1.0/docs/en/cli/usage.md +157 -0
- graphlint-0.1.0/docs/en/guide/agent-integration.md +62 -0
- graphlint-0.1.0/docs/en/guide/configuration.md +150 -0
- graphlint-0.1.0/docs/en/guide/entry-detection.md +213 -0
- graphlint-0.1.0/docs/en/guide/getting-started.md +207 -0
- graphlint-0.1.0/docs/en/guide/warnings.md +119 -0
- graphlint-0.1.0/docs/en/index.md +64 -0
- graphlint-0.1.0/docs/zh/README.md +152 -0
- graphlint-0.1.0/docs/zh/api/build.md +94 -0
- graphlint-0.1.0/docs/zh/api/configure.md +168 -0
- graphlint-0.1.0/docs/zh/api/exceptions.md +101 -0
- graphlint-0.1.0/docs/zh/api/query.md +157 -0
- graphlint-0.1.0/docs/zh/architecture/overview.md +194 -0
- graphlint-0.1.0/docs/zh/cli/usage.md +157 -0
- graphlint-0.1.0/docs/zh/guide/agent-integration.md +62 -0
- graphlint-0.1.0/docs/zh/guide/configuration.md +150 -0
- graphlint-0.1.0/docs/zh/guide/entry-detection.md +213 -0
- graphlint-0.1.0/docs/zh/guide/getting-started.md +207 -0
- graphlint-0.1.0/docs/zh/guide/warnings.md +119 -0
- graphlint-0.1.0/docs/zh/index.md +64 -0
- graphlint-0.1.0/graphlint/__init__.py +25 -0
- graphlint-0.1.0/graphlint/agent_tools.py +263 -0
- graphlint-0.1.0/graphlint/analyzer/__init__.py +1 -0
- graphlint-0.1.0/graphlint/analyzer/_ast_visitor.py +361 -0
- graphlint-0.1.0/graphlint/analyzer/_graph_algo.py +437 -0
- graphlint-0.1.0/graphlint/analyzer/_types.py +65 -0
- graphlint-0.1.0/graphlint/analyzer/decorators.py +169 -0
- graphlint-0.1.0/graphlint/analyzer/entry_detect.py +509 -0
- graphlint-0.1.0/graphlint/analyzer/graph.py +766 -0
- graphlint-0.1.0/graphlint/analyzer/imports.py +120 -0
- graphlint-0.1.0/graphlint/analyzer/parser.py +133 -0
- graphlint-0.1.0/graphlint/analyzer/warnings.py +361 -0
- graphlint-0.1.0/graphlint/api.py +419 -0
- graphlint-0.1.0/graphlint/cli.py +247 -0
- graphlint-0.1.0/graphlint/config/__init__.py +1 -0
- graphlint-0.1.0/graphlint/config/defaults.py +129 -0
- graphlint-0.1.0/graphlint/config/manager.py +222 -0
- graphlint-0.1.0/graphlint/exceptions.py +43 -0
- graphlint-0.1.0/graphlint/i18n/__init__.py +125 -0
- graphlint-0.1.0/graphlint/i18n/en.py +75 -0
- graphlint-0.1.0/graphlint/i18n/zh_CN.py +75 -0
- graphlint-0.1.0/graphlint/incremental/__init__.py +1 -0
- graphlint-0.1.0/graphlint/incremental/_db_ops.py +438 -0
- graphlint-0.1.0/graphlint/incremental/indexer.py +343 -0
- graphlint-0.1.0/graphlint/params.py +313 -0
- graphlint-0.1.0/graphlint/query/__init__.py +1 -0
- graphlint-0.1.0/graphlint/query/engine.py +436 -0
- graphlint-0.1.0/graphlint/query/formatter.py +332 -0
- graphlint-0.1.0/graphlint/query/volume.py +92 -0
- graphlint-0.1.0/graphlint/storage/__init__.py +1 -0
- graphlint-0.1.0/graphlint/storage/db.py +165 -0
- graphlint-0.1.0/graphlint/storage/hashing.py +54 -0
- graphlint-0.1.0/graphlint/storage/schema.py +140 -0
- graphlint-0.1.0/graphlint.egg-info/PKG-INFO +181 -0
- graphlint-0.1.0/graphlint.egg-info/SOURCES.txt +100 -0
- graphlint-0.1.0/graphlint.egg-info/dependency_links.txt +1 -0
- graphlint-0.1.0/graphlint.egg-info/entry_points.txt +2 -0
- graphlint-0.1.0/graphlint.egg-info/requires.txt +4 -0
- graphlint-0.1.0/graphlint.egg-info/top_level.txt +1 -0
- graphlint-0.1.0/pyproject.toml +65 -0
- graphlint-0.1.0/setup.cfg +4 -0
- graphlint-0.1.0/tests/__init__.py +1 -0
- graphlint-0.1.0/tests/integration/__init__.py +0 -0
- graphlint-0.1.0/tests/integration/test_api.py +105 -0
- graphlint-0.1.0/tests/integration/test_cli.py +107 -0
- graphlint-0.1.0/tests/integration/test_data_transfer.py +148 -0
- graphlint-0.1.0/tests/integration/test_dead_code_query.py +75 -0
- graphlint-0.1.0/tests/integration/test_full_pipeline.py +102 -0
- graphlint-0.1.0/tests/integration/test_incremental.py +86 -0
- graphlint-0.1.0/tests/integration/test_json_output.py +80 -0
- graphlint-0.1.0/tests/performance/__init__.py +0 -0
- graphlint-0.1.0/tests/performance/test_large_codebase.py +82 -0
- graphlint-0.1.0/tests/unit/__init__.py +0 -0
- graphlint-0.1.0/tests/unit/test_config.py +178 -0
- graphlint-0.1.0/tests/unit/test_db.py +165 -0
- graphlint-0.1.0/tests/unit/test_decorators.py +110 -0
- graphlint-0.1.0/tests/unit/test_engine.py +135 -0
- graphlint-0.1.0/tests/unit/test_entry_detect.py +200 -0
- graphlint-0.1.0/tests/unit/test_exceptions.py +54 -0
- graphlint-0.1.0/tests/unit/test_formatter.py +239 -0
- graphlint-0.1.0/tests/unit/test_graph.py +170 -0
- graphlint-0.1.0/tests/unit/test_hashing.py +135 -0
- graphlint-0.1.0/tests/unit/test_i18n.py +100 -0
- graphlint-0.1.0/tests/unit/test_imports.py +93 -0
- graphlint-0.1.0/tests/unit/test_mock_boundary.py +159 -0
- graphlint-0.1.0/tests/unit/test_params.py +88 -0
- graphlint-0.1.0/tests/unit/test_parser.py +158 -0
- graphlint-0.1.0/tests/unit/test_schema.py +151 -0
- graphlint-0.1.0/tests/unit/test_volume.py +105 -0
- graphlint-0.1.0/tests/unit/test_warnings.py +166 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-07-01
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Initial release
|
|
9
|
+
- AST-based Python source code parsing (classes, functions, methods, variables, fields)
|
|
10
|
+
- Dependency graph construction with 5 edge types (read, write, call, inherit, decorate)
|
|
11
|
+
- 8 built-in entry point detection rules (main, FastAPI, Flask, Django, Click, Typer, Celery, pytest)
|
|
12
|
+
- Custom entry point rules via AST pattern matching
|
|
13
|
+
- 11 warning types (unused_import, dynamic_import, circular_ref, syntax_error, write_only, deprecated_usage, dead_code, type_mismatch, unresolved_ref, unused_variable, file_too_large)
|
|
14
|
+
- Incremental indexing with SHA256-based change detection
|
|
15
|
+
- Adaptive output volume strategy (full, index, truncated)
|
|
16
|
+
- Internationalization (English and Simplified Chinese)
|
|
17
|
+
- CLI interface (`graphlint query`, `graphlint build`, `graphlint config`)
|
|
18
|
+
- Python API (`query()`, `build()`, `configure()`)
|
|
19
|
+
- SQLite persistence with cross-platform file locking
|
|
20
|
+
- Parallel file parsing via ProcessPoolExecutor
|
|
21
|
+
- Configuration management with dot-notation key access
|
|
22
|
+
- Comprehensive test suite (unit, integration, performance)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Contributing to graphlint
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing! This document outlines the process for contributing to graphlint.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
1. Fork the repository on GitHub
|
|
8
|
+
2. Clone your fork locally
|
|
9
|
+
3. Create a virtual environment and install dev dependencies:
|
|
10
|
+
```bash
|
|
11
|
+
python -m venv env
|
|
12
|
+
source env/bin/activate # or env/Scripts/activate on Windows
|
|
13
|
+
pip install -e ".[dev]"
|
|
14
|
+
```
|
|
15
|
+
4. Create a branch for your changes
|
|
16
|
+
|
|
17
|
+
## Development Workflow
|
|
18
|
+
|
|
19
|
+
- Write code that follows [PEP 8](https://peps.python.org/pep-0008/) style
|
|
20
|
+
- Add type annotations for all public functions and methods
|
|
21
|
+
- Write tests for new functionality
|
|
22
|
+
- Ensure all existing tests pass before submitting a PR
|
|
23
|
+
|
|
24
|
+
## Running Checks
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Run tests
|
|
28
|
+
pytest
|
|
29
|
+
|
|
30
|
+
# Run with coverage
|
|
31
|
+
pytest --cov=graphlint
|
|
32
|
+
|
|
33
|
+
# Type checking
|
|
34
|
+
mypy graphlint/
|
|
35
|
+
|
|
36
|
+
# Lint
|
|
37
|
+
ruff check graphlint/ tests/
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Pull Request Process
|
|
41
|
+
|
|
42
|
+
1. Update the README or documentation if your change affects the public API
|
|
43
|
+
2. Add an entry to CHANGELOG.md under the "Unreleased" section
|
|
44
|
+
3. Ensure all checks pass (tests, mypy, ruff)
|
|
45
|
+
4. Submit your pull request with a clear description of the changes
|
|
46
|
+
|
|
47
|
+
## Code Style
|
|
48
|
+
|
|
49
|
+
- Use 4 spaces for indentation (no tabs)
|
|
50
|
+
- Maximum line length: 120 characters
|
|
51
|
+
- Use `from __future__ import annotations` for modern type hints
|
|
52
|
+
- Prefer `Optional[X]` over `X | None` for Python 3.9 compatibility
|
|
53
|
+
- Module-level docstrings should briefly describe the module's purpose
|
|
54
|
+
- Public functions and classes should have docstrings
|
|
55
|
+
|
|
56
|
+
## Questions?
|
|
57
|
+
|
|
58
|
+
Open an issue on [GitHub](https://github.com/AngelosZou/graphlint/issues) if you have questions or need clarification.
|
graphlint-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yutong Zou
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
include pyproject.toml
|
|
2
|
+
include README.md
|
|
3
|
+
include docs/zh/README.md
|
|
4
|
+
include LICENSE
|
|
5
|
+
include CHANGELOG.md
|
|
6
|
+
include CONTRIBUTING.md
|
|
7
|
+
|
|
8
|
+
recursive-include graphlint *.py
|
|
9
|
+
recursive-include docs *.md
|
|
10
|
+
recursive-include tests *.py
|
|
11
|
+
|
|
12
|
+
prune tests/__pycache__
|
|
13
|
+
prune .graphlint
|
|
14
|
+
prune .pytest_cache
|
graphlint-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: graphlint
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A static analysis tool for identifying dead code in a codebase. It provides Python API and CLI for use by agents.
|
|
5
|
+
Author-email: Yutong Zou <yutong.zou.24@alumni.ucl.ac.uk>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/AngelosZou/graphlint
|
|
8
|
+
Project-URL: Repository, https://github.com/AngelosZou/graphlint
|
|
9
|
+
Project-URL: Issues, https://github.com/AngelosZou/graphlint/issues
|
|
10
|
+
Keywords: graph,dependency-graph,code-analysis,dead-code,circular-dependency,import-checker,static-analysis,lint
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
21
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov>=4; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# graphlint
|
|
31
|
+
|
|
32
|
+
[](https://pypi.org/project/graphlint/)
|
|
33
|
+
[](https://pypi.org/project/graphlint/)
|
|
34
|
+
[](https://github.com/AngelosZou/graphlint/blob/main/LICENSE)
|
|
35
|
+
|
|
36
|
+
[](https://github.com/AngelosZou/graphlint/blob/main/README.md)
|
|
37
|
+
[](https://github.com/AngelosZou/graphlint/blob/main/docs/zh/README.md)
|
|
38
|
+
|
|
39
|
+
**Dead code detection for AI-generated Python codebases.**
|
|
40
|
+
|
|
41
|
+
AI agents generate code rapidly, leaving behind dead and redundant code that pollutes the LLM's context window and dilutes attention. Graphlint analyzes your Python codebase's dependency graph to identify entry points and **detect dead code** — components unreachable from any entry point — so agents can self-clean and keep the codebase lean.
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
- **Dead code detection** — finds components unreachable from any entry point via graph traversal
|
|
46
|
+
- **AST parsing** — extracts classes, functions, methods, variables, and fields
|
|
47
|
+
- **Dependency graph** — builds directed edges: `read`, `write`, `call`, `inherit`, `decorate`
|
|
48
|
+
- **Entry point detection** — 10 built-in rules (main, FastAPI, Flask, Django, Click, Typer, Celery, pytest, plus package and test entries) and custom rules
|
|
49
|
+
- **Warning detection** — 11 warning types including circular references, unused imports, write-only variables, and more
|
|
50
|
+
- **Incremental indexing** — SHA256-based change detection parses only modified files
|
|
51
|
+
- **Python API + CLI** — integrate into any Tool, CI pipeline, or let agents self-analyze and self-clean
|
|
52
|
+
- **Zero runtime dependencies** — only requires the Python standard library
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install graphlint
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Requirements:** Python >= 3.9
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
### Agent Integration
|
|
65
|
+
|
|
66
|
+
Graphlint provides a command to inject its usage prompt into your AI coding tools at the **global level**, so every project automatically has graphlint's guidance:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Install graphlint prompt into agent tools (opencode, cursor, codex, cc)
|
|
70
|
+
graphlint install
|
|
71
|
+
|
|
72
|
+
# Remove graphlint prompt from agent tools
|
|
73
|
+
graphlint uninstall
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Run `graphlint install` and select the tools you use — the prompt (usage scenarios, essential commands, and parameters) will be added to their global configuration. For details, see [Agent Integration](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/agent-integration.md).
|
|
77
|
+
|
|
78
|
+
### CLI
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Find dead code in current directory
|
|
82
|
+
graphlint query --warn-types "dead_code"
|
|
83
|
+
|
|
84
|
+
# Full analysis with JSON output
|
|
85
|
+
graphlint query --json
|
|
86
|
+
|
|
87
|
+
# View a specific graph detail
|
|
88
|
+
graphlint query -g 1 --detail full
|
|
89
|
+
|
|
90
|
+
# Rebuild index
|
|
91
|
+
graphlint build --force
|
|
92
|
+
|
|
93
|
+
# Configure
|
|
94
|
+
graphlint config show
|
|
95
|
+
graphlint config set --key lang --value en
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Python API
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from graphlint.api import query
|
|
102
|
+
|
|
103
|
+
# Find dead code components
|
|
104
|
+
result = query(warn_types="dead_code", json_output=True)
|
|
105
|
+
|
|
106
|
+
# Full dependency graph analysis
|
|
107
|
+
result = query(include_tests=True, json_output=True)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Warning Types
|
|
111
|
+
|
|
112
|
+
| Warning | Description |
|
|
113
|
+
|---------|-------------|
|
|
114
|
+
| `unused_import` | Imported module or name is never used |
|
|
115
|
+
| `dynamic_import` | Dynamic import via `importlib` or `__import__` |
|
|
116
|
+
| `circular_ref` | Circular dependency between functions/classes |
|
|
117
|
+
| `syntax_error` | File contains a syntax error |
|
|
118
|
+
| `write_only` | Variable is written but never read |
|
|
119
|
+
| `deprecated_usage` | Usage of a deprecated function/class |
|
|
120
|
+
| `dead_code` | Component unreachable from any entry point |
|
|
121
|
+
| `type_mismatch` | Suspicious type annotations |
|
|
122
|
+
| `unresolved_ref` | Reference to an undefined name |
|
|
123
|
+
| `unused_variable` | Variable is defined but never used |
|
|
124
|
+
| `file_too_large` | File exceeds the configured size limit |
|
|
125
|
+
|
|
126
|
+
## Development
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Clone the repository
|
|
130
|
+
git clone https://github.com/AngelosZou/graphlint.git
|
|
131
|
+
cd graphlint
|
|
132
|
+
|
|
133
|
+
# Create a virtual environment
|
|
134
|
+
python -m venv env
|
|
135
|
+
env/Scripts/activate # Windows
|
|
136
|
+
source env/bin/activate # Unix
|
|
137
|
+
|
|
138
|
+
# Install dev dependencies
|
|
139
|
+
pip install -e ".[dev]"
|
|
140
|
+
|
|
141
|
+
# Run tests
|
|
142
|
+
pytest
|
|
143
|
+
|
|
144
|
+
# Run with coverage
|
|
145
|
+
pytest --cov=graphlint
|
|
146
|
+
|
|
147
|
+
# Run type checking
|
|
148
|
+
mypy graphlint/
|
|
149
|
+
|
|
150
|
+
# Run linting
|
|
151
|
+
ruff check graphlint/ tests/
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Configuration
|
|
155
|
+
|
|
156
|
+
Graphlint stores its configuration in `.graphlint/config.json` within the analyzed directory. Use `graphlint config` commands to manage settings, or edit the file directly.
|
|
157
|
+
|
|
158
|
+
See `graphlint config show` for the full default configuration.
|
|
159
|
+
|
|
160
|
+
## Documentation
|
|
161
|
+
|
|
162
|
+
Full documentation is available in the [docs/](https://github.com/AngelosZou/graphlint/tree/main/docs/) directory:
|
|
163
|
+
|
|
164
|
+
- [Getting Started](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/getting-started.md)
|
|
165
|
+
- [Agent Integration](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/agent-integration.md)
|
|
166
|
+
- [Configuration Guide](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/configuration.md)
|
|
167
|
+
- [Entry Point Detection](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/entry-detection.md)
|
|
168
|
+
- [Warning Reference](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/warnings.md)
|
|
169
|
+
- [CLI Usage](https://github.com/AngelosZou/graphlint/blob/main/docs/en/cli/usage.md)
|
|
170
|
+
- [Architecture Overview](https://github.com/AngelosZou/graphlint/blob/main/docs/en/architecture/overview.md)
|
|
171
|
+
- [Python API](https://github.com/AngelosZou/graphlint/tree/main/docs/en/api/)
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT — see [LICENSE](https://github.com/AngelosZou/graphlint/blob/main/LICENSE) for details.
|
|
176
|
+
|
|
177
|
+
## Links
|
|
178
|
+
|
|
179
|
+
- [GitHub Repository](https://github.com/AngelosZou/graphlint)
|
|
180
|
+
- [Issue Tracker](https://github.com/AngelosZou/graphlint/issues)
|
|
181
|
+
- [PyPI Package](https://pypi.org/project/graphlint/)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# graphlint
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/graphlint/)
|
|
4
|
+
[](https://pypi.org/project/graphlint/)
|
|
5
|
+
[](https://github.com/AngelosZou/graphlint/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
[](README.md)
|
|
8
|
+
[](docs/zh/README.md)
|
|
9
|
+
|
|
10
|
+
**Dead code detection for AI-generated Python codebases.**
|
|
11
|
+
|
|
12
|
+
AI agents generate code rapidly, leaving behind dead and redundant code that pollutes the LLM's context window and dilutes attention. Graphlint analyzes your Python codebase's dependency graph to identify entry points and **detect dead code** — components unreachable from any entry point — so agents can self-clean and keep the codebase lean.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Dead code detection** — finds components unreachable from any entry point via graph traversal
|
|
17
|
+
- **AST parsing** — extracts classes, functions, methods, variables, and fields
|
|
18
|
+
- **Dependency graph** — builds directed edges: `read`, `write`, `call`, `inherit`, `decorate`
|
|
19
|
+
- **Entry point detection** — 10 built-in rules (main, FastAPI, Flask, Django, Click, Typer, Celery, pytest, plus package and test entries) and custom rules
|
|
20
|
+
- **Warning detection** — 11 warning types including circular references, unused imports, write-only variables, and more
|
|
21
|
+
- **Incremental indexing** — SHA256-based change detection parses only modified files
|
|
22
|
+
- **Python API + CLI** — integrate into any Tool, CI pipeline, or let agents self-analyze and self-clean
|
|
23
|
+
- **Zero runtime dependencies** — only requires the Python standard library
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install graphlint
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Requirements:** Python >= 3.9
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
### Agent Integration
|
|
36
|
+
|
|
37
|
+
Graphlint provides a command to inject its usage prompt into your AI coding tools at the **global level**, so every project automatically has graphlint's guidance:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Install graphlint prompt into agent tools (opencode, cursor, codex, cc)
|
|
41
|
+
graphlint install
|
|
42
|
+
|
|
43
|
+
# Remove graphlint prompt from agent tools
|
|
44
|
+
graphlint uninstall
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Run `graphlint install` and select the tools you use — the prompt (usage scenarios, essential commands, and parameters) will be added to their global configuration. For details, see [Agent Integration](docs/en/guide/agent-integration.md).
|
|
48
|
+
|
|
49
|
+
### CLI
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Find dead code in current directory
|
|
53
|
+
graphlint query --warn-types "dead_code"
|
|
54
|
+
|
|
55
|
+
# Full analysis with JSON output
|
|
56
|
+
graphlint query --json
|
|
57
|
+
|
|
58
|
+
# View a specific graph detail
|
|
59
|
+
graphlint query -g 1 --detail full
|
|
60
|
+
|
|
61
|
+
# Rebuild index
|
|
62
|
+
graphlint build --force
|
|
63
|
+
|
|
64
|
+
# Configure
|
|
65
|
+
graphlint config show
|
|
66
|
+
graphlint config set --key lang --value en
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Python API
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from graphlint.api import query
|
|
73
|
+
|
|
74
|
+
# Find dead code components
|
|
75
|
+
result = query(warn_types="dead_code", json_output=True)
|
|
76
|
+
|
|
77
|
+
# Full dependency graph analysis
|
|
78
|
+
result = query(include_tests=True, json_output=True)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Warning Types
|
|
82
|
+
|
|
83
|
+
| Warning | Description |
|
|
84
|
+
|---------|-------------|
|
|
85
|
+
| `unused_import` | Imported module or name is never used |
|
|
86
|
+
| `dynamic_import` | Dynamic import via `importlib` or `__import__` |
|
|
87
|
+
| `circular_ref` | Circular dependency between functions/classes |
|
|
88
|
+
| `syntax_error` | File contains a syntax error |
|
|
89
|
+
| `write_only` | Variable is written but never read |
|
|
90
|
+
| `deprecated_usage` | Usage of a deprecated function/class |
|
|
91
|
+
| `dead_code` | Component unreachable from any entry point |
|
|
92
|
+
| `type_mismatch` | Suspicious type annotations |
|
|
93
|
+
| `unresolved_ref` | Reference to an undefined name |
|
|
94
|
+
| `unused_variable` | Variable is defined but never used |
|
|
95
|
+
| `file_too_large` | File exceeds the configured size limit |
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Clone the repository
|
|
101
|
+
git clone https://github.com/AngelosZou/graphlint.git
|
|
102
|
+
cd graphlint
|
|
103
|
+
|
|
104
|
+
# Create a virtual environment
|
|
105
|
+
python -m venv env
|
|
106
|
+
env/Scripts/activate # Windows
|
|
107
|
+
source env/bin/activate # Unix
|
|
108
|
+
|
|
109
|
+
# Install dev dependencies
|
|
110
|
+
pip install -e ".[dev]"
|
|
111
|
+
|
|
112
|
+
# Run tests
|
|
113
|
+
pytest
|
|
114
|
+
|
|
115
|
+
# Run with coverage
|
|
116
|
+
pytest --cov=graphlint
|
|
117
|
+
|
|
118
|
+
# Run type checking
|
|
119
|
+
mypy graphlint/
|
|
120
|
+
|
|
121
|
+
# Run linting
|
|
122
|
+
ruff check graphlint/ tests/
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Configuration
|
|
126
|
+
|
|
127
|
+
Graphlint stores its configuration in `.graphlint/config.json` within the analyzed directory. Use `graphlint config` commands to manage settings, or edit the file directly.
|
|
128
|
+
|
|
129
|
+
See `graphlint config show` for the full default configuration.
|
|
130
|
+
|
|
131
|
+
## Documentation
|
|
132
|
+
|
|
133
|
+
Full documentation is available in the [docs/](docs/) directory:
|
|
134
|
+
|
|
135
|
+
- [Getting Started](docs/en/guide/getting-started.md)
|
|
136
|
+
- [Agent Integration](docs/en/guide/agent-integration.md)
|
|
137
|
+
- [Configuration Guide](docs/en/guide/configuration.md)
|
|
138
|
+
- [Entry Point Detection](docs/en/guide/entry-detection.md)
|
|
139
|
+
- [Warning Reference](docs/en/guide/warnings.md)
|
|
140
|
+
- [CLI Usage](docs/en/cli/usage.md)
|
|
141
|
+
- [Architecture Overview](docs/en/architecture/overview.md)
|
|
142
|
+
- [Python API](docs/en/api/)
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT — see [LICENSE](LICENSE) for details.
|
|
147
|
+
|
|
148
|
+
## Links
|
|
149
|
+
|
|
150
|
+
- [GitHub Repository](https://github.com/AngelosZou/graphlint)
|
|
151
|
+
- [Issue Tracker](https://github.com/AngelosZou/graphlint/issues)
|
|
152
|
+
- [PyPI Package](https://pypi.org/project/graphlint/)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# graphlint
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/graphlint/)
|
|
4
|
+
[](https://pypi.org/project/graphlint/)
|
|
5
|
+
[](https://github.com/AngelosZou/graphlint/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
[](https://github.com/AngelosZou/graphlint/blob/main/README.md)
|
|
8
|
+
[](https://github.com/AngelosZou/graphlint/blob/main/docs/zh/README.md)
|
|
9
|
+
|
|
10
|
+
**Dead code detection for AI-generated Python codebases.**
|
|
11
|
+
|
|
12
|
+
AI agents generate code rapidly, leaving behind dead and redundant code that pollutes the LLM's context window and dilutes attention. Graphlint analyzes your Python codebase's dependency graph to identify entry points and **detect dead code** — components unreachable from any entry point — so agents can self-clean and keep the codebase lean.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Dead code detection** — finds components unreachable from any entry point via graph traversal
|
|
17
|
+
- **AST parsing** — extracts classes, functions, methods, variables, and fields
|
|
18
|
+
- **Dependency graph** — builds directed edges: `read`, `write`, `call`, `inherit`, `decorate`
|
|
19
|
+
- **Entry point detection** — 10 built-in rules (main, FastAPI, Flask, Django, Click, Typer, Celery, pytest, plus package and test entries) and custom rules
|
|
20
|
+
- **Warning detection** — 11 warning types including circular references, unused imports, write-only variables, and more
|
|
21
|
+
- **Incremental indexing** — SHA256-based change detection parses only modified files
|
|
22
|
+
- **Python API + CLI** — integrate into any Tool, CI pipeline, or let agents self-analyze and self-clean
|
|
23
|
+
- **Zero runtime dependencies** — only requires the Python standard library
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install graphlint
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Requirements:** Python >= 3.9
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
### Agent Integration
|
|
36
|
+
|
|
37
|
+
Graphlint provides a command to inject its usage prompt into your AI coding tools at the **global level**, so every project automatically has graphlint's guidance:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Install graphlint prompt into agent tools (opencode, cursor, codex, cc)
|
|
41
|
+
graphlint install
|
|
42
|
+
|
|
43
|
+
# Remove graphlint prompt from agent tools
|
|
44
|
+
graphlint uninstall
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Run `graphlint install` and select the tools you use — the prompt (usage scenarios, essential commands, and parameters) will be added to their global configuration. For details, see [Agent Integration](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/agent-integration.md).
|
|
48
|
+
|
|
49
|
+
### CLI
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Find dead code in current directory
|
|
53
|
+
graphlint query --warn-types "dead_code"
|
|
54
|
+
|
|
55
|
+
# Full analysis with JSON output
|
|
56
|
+
graphlint query --json
|
|
57
|
+
|
|
58
|
+
# View a specific graph detail
|
|
59
|
+
graphlint query -g 1 --detail full
|
|
60
|
+
|
|
61
|
+
# Rebuild index
|
|
62
|
+
graphlint build --force
|
|
63
|
+
|
|
64
|
+
# Configure
|
|
65
|
+
graphlint config show
|
|
66
|
+
graphlint config set --key lang --value en
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Python API
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from graphlint.api import query
|
|
73
|
+
|
|
74
|
+
# Find dead code components
|
|
75
|
+
result = query(warn_types="dead_code", json_output=True)
|
|
76
|
+
|
|
77
|
+
# Full dependency graph analysis
|
|
78
|
+
result = query(include_tests=True, json_output=True)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Warning Types
|
|
82
|
+
|
|
83
|
+
| Warning | Description |
|
|
84
|
+
|---------|-------------|
|
|
85
|
+
| `unused_import` | Imported module or name is never used |
|
|
86
|
+
| `dynamic_import` | Dynamic import via `importlib` or `__import__` |
|
|
87
|
+
| `circular_ref` | Circular dependency between functions/classes |
|
|
88
|
+
| `syntax_error` | File contains a syntax error |
|
|
89
|
+
| `write_only` | Variable is written but never read |
|
|
90
|
+
| `deprecated_usage` | Usage of a deprecated function/class |
|
|
91
|
+
| `dead_code` | Component unreachable from any entry point |
|
|
92
|
+
| `type_mismatch` | Suspicious type annotations |
|
|
93
|
+
| `unresolved_ref` | Reference to an undefined name |
|
|
94
|
+
| `unused_variable` | Variable is defined but never used |
|
|
95
|
+
| `file_too_large` | File exceeds the configured size limit |
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Clone the repository
|
|
101
|
+
git clone https://github.com/AngelosZou/graphlint.git
|
|
102
|
+
cd graphlint
|
|
103
|
+
|
|
104
|
+
# Create a virtual environment
|
|
105
|
+
python -m venv env
|
|
106
|
+
env/Scripts/activate # Windows
|
|
107
|
+
source env/bin/activate # Unix
|
|
108
|
+
|
|
109
|
+
# Install dev dependencies
|
|
110
|
+
pip install -e ".[dev]"
|
|
111
|
+
|
|
112
|
+
# Run tests
|
|
113
|
+
pytest
|
|
114
|
+
|
|
115
|
+
# Run with coverage
|
|
116
|
+
pytest --cov=graphlint
|
|
117
|
+
|
|
118
|
+
# Run type checking
|
|
119
|
+
mypy graphlint/
|
|
120
|
+
|
|
121
|
+
# Run linting
|
|
122
|
+
ruff check graphlint/ tests/
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Configuration
|
|
126
|
+
|
|
127
|
+
Graphlint stores its configuration in `.graphlint/config.json` within the analyzed directory. Use `graphlint config` commands to manage settings, or edit the file directly.
|
|
128
|
+
|
|
129
|
+
See `graphlint config show` for the full default configuration.
|
|
130
|
+
|
|
131
|
+
## Documentation
|
|
132
|
+
|
|
133
|
+
Full documentation is available in the [docs/](https://github.com/AngelosZou/graphlint/tree/main/docs/) directory:
|
|
134
|
+
|
|
135
|
+
- [Getting Started](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/getting-started.md)
|
|
136
|
+
- [Agent Integration](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/agent-integration.md)
|
|
137
|
+
- [Configuration Guide](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/configuration.md)
|
|
138
|
+
- [Entry Point Detection](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/entry-detection.md)
|
|
139
|
+
- [Warning Reference](https://github.com/AngelosZou/graphlint/blob/main/docs/en/guide/warnings.md)
|
|
140
|
+
- [CLI Usage](https://github.com/AngelosZou/graphlint/blob/main/docs/en/cli/usage.md)
|
|
141
|
+
- [Architecture Overview](https://github.com/AngelosZou/graphlint/blob/main/docs/en/architecture/overview.md)
|
|
142
|
+
- [Python API](https://github.com/AngelosZou/graphlint/tree/main/docs/en/api/)
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT — see [LICENSE](https://github.com/AngelosZou/graphlint/blob/main/LICENSE) for details.
|
|
147
|
+
|
|
148
|
+
## Links
|
|
149
|
+
|
|
150
|
+
- [GitHub Repository](https://github.com/AngelosZou/graphlint)
|
|
151
|
+
- [Issue Tracker](https://github.com/AngelosZou/graphlint/issues)
|
|
152
|
+
- [PyPI Package](https://pypi.org/project/graphlint/)
|