yaddd-linter 0.3.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.
- yaddd_linter-0.3.0/.gitignore +169 -0
- yaddd_linter-0.3.0/PKG-INFO +165 -0
- yaddd_linter-0.3.0/README.md +149 -0
- yaddd_linter-0.3.0/pyproject.toml +39 -0
- yaddd_linter-0.3.0/src/yaddd_linter/__init__.py +5 -0
- yaddd_linter-0.3.0/src/yaddd_linter/aggregate.py +34 -0
- yaddd_linter-0.3.0/src/yaddd_linter/checker.py +723 -0
- yaddd_linter-0.3.0/src/yaddd_linter/cli.py +233 -0
- yaddd_linter-0.3.0/src/yaddd_linter/config.py +155 -0
- yaddd_linter-0.3.0/src/yaddd_linter/layers.py +128 -0
- yaddd_linter-0.3.0/src/yaddd_linter/lsp.py +127 -0
- yaddd_linter-0.3.0/src/yaddd_linter/py.typed +0 -0
- yaddd_linter-0.3.0/src/yaddd_linter/rules.py +44 -0
- yaddd_linter-0.3.0/tests/test_checker.py +909 -0
- yaddd_linter-0.3.0/tests/test_cli.py +168 -0
- yaddd_linter-0.3.0/tests/test_config.py +107 -0
- yaddd_linter-0.3.0/tests/test_lsp.py +91 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
110
|
+
.pdm.toml
|
|
111
|
+
.pdm-python
|
|
112
|
+
.pdm-build/
|
|
113
|
+
|
|
114
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
115
|
+
__pypackages__/
|
|
116
|
+
|
|
117
|
+
# Celery stuff
|
|
118
|
+
celerybeat-schedule
|
|
119
|
+
celerybeat.pid
|
|
120
|
+
|
|
121
|
+
# SageMath parsed files
|
|
122
|
+
*.sage.py
|
|
123
|
+
|
|
124
|
+
# Environments
|
|
125
|
+
.env
|
|
126
|
+
.venv
|
|
127
|
+
env/
|
|
128
|
+
venv/
|
|
129
|
+
ENV/
|
|
130
|
+
env.bak/
|
|
131
|
+
venv.bak/
|
|
132
|
+
|
|
133
|
+
# Spyder project settings
|
|
134
|
+
.spyderproject
|
|
135
|
+
.spyproject
|
|
136
|
+
|
|
137
|
+
# Rope project settings
|
|
138
|
+
.ropeproject
|
|
139
|
+
|
|
140
|
+
# mkdocs documentation
|
|
141
|
+
/site
|
|
142
|
+
|
|
143
|
+
# ruff
|
|
144
|
+
.ruff_cache/
|
|
145
|
+
|
|
146
|
+
# mypy
|
|
147
|
+
.mypy_cache/
|
|
148
|
+
|
|
149
|
+
# ty
|
|
150
|
+
.ty/
|
|
151
|
+
|
|
152
|
+
# Pyre type checker
|
|
153
|
+
.pyre/
|
|
154
|
+
|
|
155
|
+
# pytype static type analyzer
|
|
156
|
+
.pytype/
|
|
157
|
+
|
|
158
|
+
# Cython debug symbols
|
|
159
|
+
cython_debug/
|
|
160
|
+
|
|
161
|
+
# IDE
|
|
162
|
+
.idea
|
|
163
|
+
.vscode/!launch.json
|
|
164
|
+
.vscode/!tasks.json
|
|
165
|
+
|
|
166
|
+
# OS
|
|
167
|
+
.DS_Store
|
|
168
|
+
|
|
169
|
+
*_old/
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: yaddd-linter
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: DDD-aware linter for yaddd projects.
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: ddd,linter,yaddd
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
13
|
+
Requires-Python: >=3.12
|
|
14
|
+
Requires-Dist: pygls<2,>=1.3
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# yaddd-linter
|
|
18
|
+
|
|
19
|
+
DDD-aware static analysis for [yaddd](https://github.com/netstuff/yaddd) projects.
|
|
20
|
+
|
|
21
|
+
## Rules
|
|
22
|
+
|
|
23
|
+
- **YDDD001** — Direct mutation of an aggregate/entity field outside aggregate methods.
|
|
24
|
+
- **YDDD002** — Mutating call on an aggregate attribute outside aggregate methods.
|
|
25
|
+
- **YDDD003** — Layer isolation violation between core layers (e.g. domain imports application).
|
|
26
|
+
- **YDDD004** — Domain layer imports a third-party module (domain must depend only on
|
|
27
|
+
stdlib, `yaddd` itself, and the pydantic serialization stack behind `PydanticVO`,
|
|
28
|
+
which is documented as a domain base class).
|
|
29
|
+
- **YDDD005** — A yaddd plugin imports another yaddd plugin (e.g. `yaddd_sqlalchemy` imports `yaddd_pydantic`).
|
|
30
|
+
- **YDDD006** — A class in `domain/<slice>/aggregates/` does not inherit from `AggregateRoot`/`Entity`
|
|
31
|
+
(a bare dataclass skips invariant checks, identity equality and the event stream).
|
|
32
|
+
- **YDDD007** — A data class in `application/**/commands.py` or `application/**/dto.py` does not
|
|
33
|
+
inherit from `yaddd.Command`/`Query`/`DTO` (a bare dataclass or pydantic model bypasses the
|
|
34
|
+
application contract). Constant holders without annotated fields are ignored.
|
|
35
|
+
- **YDDD008** — An aggregate module breaks the "one aggregate — one file" rule: more than one
|
|
36
|
+
class, module-level functions or constants, or a module name that does not match the aggregate
|
|
37
|
+
name in snake_case. Entities, value objects, constants and helpers are imported, never declared
|
|
38
|
+
inside an aggregate module.
|
|
39
|
+
- **YDDD009** — A presentation schema breaks the layer-linking contract: a `*Request` class in
|
|
40
|
+
`presentation/**/schemas.py` (or a `presentation/**/schemas/` package) does not define
|
|
41
|
+
`to_message()`, or a class inheriting `ApplicationResponse`/`PydanticApplicationResponse` does
|
|
42
|
+
not define a `from_dto()` factory. Purely presentational responses without the application link
|
|
43
|
+
are free of requirements.
|
|
44
|
+
- **YDDD010** — Module decomposition limits: a grab-bag module name (`utils.py`, `helpers.py`,
|
|
45
|
+
`common.py`, `misc.py`), more than 300 lines, or more than 10 public top-level names.
|
|
46
|
+
`__init__.py` and test modules are exempt from the size limits. Thresholds are configurable via
|
|
47
|
+
`max_module_lines` and `max_module_public_names` in `[tool.yaddd-linter]`.
|
|
48
|
+
- **YDDD011** — Transport rendering in the application layer: a method named `to_payload`,
|
|
49
|
+
`to_json` or `to_jsonable` on an application-layer class. The application layer exposes data;
|
|
50
|
+
rendering into wire formats lives in presentation/infrastructure adapters.
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
yaddd-linter packages/yaddd/src
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The default output format is compatible with ruff:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
packages/yaddd/src/yaddd/application/service.py:42:5: YDDD001 Direct mutation of aggregate field 'status' of variable 'order' outside aggregate methods
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## CLI options
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
yaddd-linter [OPTIONS] PATHS...
|
|
68
|
+
|
|
69
|
+
Options:
|
|
70
|
+
--format {text,json} Output format (default: text).
|
|
71
|
+
--stdin-filename PATH Filename to use when reading from stdin.
|
|
72
|
+
--select CODES Comma-separated rule codes to enable.
|
|
73
|
+
--ignore CODES Comma-separated rule codes to disable.
|
|
74
|
+
--config PATH Path to pyproject.toml with [tool.yaddd-linter].
|
|
75
|
+
--layers-config PATH Path to .yaddd/layers.json with per-layer import policies.
|
|
76
|
+
--version Show version and exit.
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Configuration
|
|
80
|
+
|
|
81
|
+
`yaddd-linter` reads configuration from the nearest `pyproject.toml`:
|
|
82
|
+
|
|
83
|
+
```toml
|
|
84
|
+
[tool.yaddd-linter]
|
|
85
|
+
select = ["YDDD001", "YDDD003"]
|
|
86
|
+
ignore = ["YDDD004"]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
CLI flags `--select` and `--ignore` override the configuration file.
|
|
90
|
+
|
|
91
|
+
Layer policy is read from `.yaddd/layers.json` next to `pyproject.toml`, or from
|
|
92
|
+
`--layers-config`:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"schema": 1,
|
|
97
|
+
"layers": {
|
|
98
|
+
"domain": {
|
|
99
|
+
"imports": ["domain"],
|
|
100
|
+
"third_party": ["pydantic", "yaddd_pydantic"]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Without that file the linter uses the built-in layer rules. The file is
|
|
107
|
+
generated by `yaddd-agents`.
|
|
108
|
+
|
|
109
|
+
## Exit codes
|
|
110
|
+
|
|
111
|
+
- `0` — no violations found.
|
|
112
|
+
- `1` — one or more violations found.
|
|
113
|
+
- `2` — CLI or configuration error.
|
|
114
|
+
|
|
115
|
+
## JSON output
|
|
116
|
+
|
|
117
|
+
Use `--format json` to emit a machine-readable array:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
echo "from yaddd.application.commands import CreateOrder" \
|
|
121
|
+
| yaddd-linter --stdin-filename app/domain/order.py --format json -
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
[
|
|
126
|
+
{
|
|
127
|
+
"path": "app/domain/order.py",
|
|
128
|
+
"line": 1,
|
|
129
|
+
"col": 0,
|
|
130
|
+
"code": "YDDD003",
|
|
131
|
+
"message": "domain layer imports from application layer: 'yaddd.application.commands'"
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## LSP server
|
|
137
|
+
|
|
138
|
+
`yaddd-linter` includes a Language Server Protocol server for live diagnostics
|
|
139
|
+
in editors.
|
|
140
|
+
|
|
141
|
+
Start it manually:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
yaddd-linter-lsp
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The server communicates over stdio and updates diagnostics on:
|
|
148
|
+
|
|
149
|
+
- `textDocument/didOpen`
|
|
150
|
+
- `textDocument/didChange`
|
|
151
|
+
- `textDocument/didSave`
|
|
152
|
+
|
|
153
|
+
Diagnostics are cleared on `textDocument/didClose`.
|
|
154
|
+
|
|
155
|
+
### Editor setup
|
|
156
|
+
|
|
157
|
+
- **VSCode**: create an extension that launches `yaddd-linter-lsp` and connects
|
|
158
|
+
via `vscode-languageclient`.
|
|
159
|
+
- **Zed**: register `yaddd-linter-lsp` as a language server for Python in
|
|
160
|
+
`settings.json`.
|
|
161
|
+
- **JetBrains**: use LSP4IJ or a small plugin that starts `yaddd-linter-lsp`.
|
|
162
|
+
- **Neovim / Emacs**: configure the server with your LSP client.
|
|
163
|
+
|
|
164
|
+
The LSP server reads the same `[tool.yaddd-linter]` configuration from the
|
|
165
|
+
nearest `pyproject.toml`.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# yaddd-linter
|
|
2
|
+
|
|
3
|
+
DDD-aware static analysis for [yaddd](https://github.com/netstuff/yaddd) projects.
|
|
4
|
+
|
|
5
|
+
## Rules
|
|
6
|
+
|
|
7
|
+
- **YDDD001** — Direct mutation of an aggregate/entity field outside aggregate methods.
|
|
8
|
+
- **YDDD002** — Mutating call on an aggregate attribute outside aggregate methods.
|
|
9
|
+
- **YDDD003** — Layer isolation violation between core layers (e.g. domain imports application).
|
|
10
|
+
- **YDDD004** — Domain layer imports a third-party module (domain must depend only on
|
|
11
|
+
stdlib, `yaddd` itself, and the pydantic serialization stack behind `PydanticVO`,
|
|
12
|
+
which is documented as a domain base class).
|
|
13
|
+
- **YDDD005** — A yaddd plugin imports another yaddd plugin (e.g. `yaddd_sqlalchemy` imports `yaddd_pydantic`).
|
|
14
|
+
- **YDDD006** — A class in `domain/<slice>/aggregates/` does not inherit from `AggregateRoot`/`Entity`
|
|
15
|
+
(a bare dataclass skips invariant checks, identity equality and the event stream).
|
|
16
|
+
- **YDDD007** — A data class in `application/**/commands.py` or `application/**/dto.py` does not
|
|
17
|
+
inherit from `yaddd.Command`/`Query`/`DTO` (a bare dataclass or pydantic model bypasses the
|
|
18
|
+
application contract). Constant holders without annotated fields are ignored.
|
|
19
|
+
- **YDDD008** — An aggregate module breaks the "one aggregate — one file" rule: more than one
|
|
20
|
+
class, module-level functions or constants, or a module name that does not match the aggregate
|
|
21
|
+
name in snake_case. Entities, value objects, constants and helpers are imported, never declared
|
|
22
|
+
inside an aggregate module.
|
|
23
|
+
- **YDDD009** — A presentation schema breaks the layer-linking contract: a `*Request` class in
|
|
24
|
+
`presentation/**/schemas.py` (or a `presentation/**/schemas/` package) does not define
|
|
25
|
+
`to_message()`, or a class inheriting `ApplicationResponse`/`PydanticApplicationResponse` does
|
|
26
|
+
not define a `from_dto()` factory. Purely presentational responses without the application link
|
|
27
|
+
are free of requirements.
|
|
28
|
+
- **YDDD010** — Module decomposition limits: a grab-bag module name (`utils.py`, `helpers.py`,
|
|
29
|
+
`common.py`, `misc.py`), more than 300 lines, or more than 10 public top-level names.
|
|
30
|
+
`__init__.py` and test modules are exempt from the size limits. Thresholds are configurable via
|
|
31
|
+
`max_module_lines` and `max_module_public_names` in `[tool.yaddd-linter]`.
|
|
32
|
+
- **YDDD011** — Transport rendering in the application layer: a method named `to_payload`,
|
|
33
|
+
`to_json` or `to_jsonable` on an application-layer class. The application layer exposes data;
|
|
34
|
+
rendering into wire formats lives in presentation/infrastructure adapters.
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
yaddd-linter packages/yaddd/src
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The default output format is compatible with ruff:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
packages/yaddd/src/yaddd/application/service.py:42:5: YDDD001 Direct mutation of aggregate field 'status' of variable 'order' outside aggregate methods
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## CLI options
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
yaddd-linter [OPTIONS] PATHS...
|
|
52
|
+
|
|
53
|
+
Options:
|
|
54
|
+
--format {text,json} Output format (default: text).
|
|
55
|
+
--stdin-filename PATH Filename to use when reading from stdin.
|
|
56
|
+
--select CODES Comma-separated rule codes to enable.
|
|
57
|
+
--ignore CODES Comma-separated rule codes to disable.
|
|
58
|
+
--config PATH Path to pyproject.toml with [tool.yaddd-linter].
|
|
59
|
+
--layers-config PATH Path to .yaddd/layers.json with per-layer import policies.
|
|
60
|
+
--version Show version and exit.
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Configuration
|
|
64
|
+
|
|
65
|
+
`yaddd-linter` reads configuration from the nearest `pyproject.toml`:
|
|
66
|
+
|
|
67
|
+
```toml
|
|
68
|
+
[tool.yaddd-linter]
|
|
69
|
+
select = ["YDDD001", "YDDD003"]
|
|
70
|
+
ignore = ["YDDD004"]
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
CLI flags `--select` and `--ignore` override the configuration file.
|
|
74
|
+
|
|
75
|
+
Layer policy is read from `.yaddd/layers.json` next to `pyproject.toml`, or from
|
|
76
|
+
`--layers-config`:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"schema": 1,
|
|
81
|
+
"layers": {
|
|
82
|
+
"domain": {
|
|
83
|
+
"imports": ["domain"],
|
|
84
|
+
"third_party": ["pydantic", "yaddd_pydantic"]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Without that file the linter uses the built-in layer rules. The file is
|
|
91
|
+
generated by `yaddd-agents`.
|
|
92
|
+
|
|
93
|
+
## Exit codes
|
|
94
|
+
|
|
95
|
+
- `0` — no violations found.
|
|
96
|
+
- `1` — one or more violations found.
|
|
97
|
+
- `2` — CLI or configuration error.
|
|
98
|
+
|
|
99
|
+
## JSON output
|
|
100
|
+
|
|
101
|
+
Use `--format json` to emit a machine-readable array:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
echo "from yaddd.application.commands import CreateOrder" \
|
|
105
|
+
| yaddd-linter --stdin-filename app/domain/order.py --format json -
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
[
|
|
110
|
+
{
|
|
111
|
+
"path": "app/domain/order.py",
|
|
112
|
+
"line": 1,
|
|
113
|
+
"col": 0,
|
|
114
|
+
"code": "YDDD003",
|
|
115
|
+
"message": "domain layer imports from application layer: 'yaddd.application.commands'"
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## LSP server
|
|
121
|
+
|
|
122
|
+
`yaddd-linter` includes a Language Server Protocol server for live diagnostics
|
|
123
|
+
in editors.
|
|
124
|
+
|
|
125
|
+
Start it manually:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
yaddd-linter-lsp
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The server communicates over stdio and updates diagnostics on:
|
|
132
|
+
|
|
133
|
+
- `textDocument/didOpen`
|
|
134
|
+
- `textDocument/didChange`
|
|
135
|
+
- `textDocument/didSave`
|
|
136
|
+
|
|
137
|
+
Diagnostics are cleared on `textDocument/didClose`.
|
|
138
|
+
|
|
139
|
+
### Editor setup
|
|
140
|
+
|
|
141
|
+
- **VSCode**: create an extension that launches `yaddd-linter-lsp` and connects
|
|
142
|
+
via `vscode-languageclient`.
|
|
143
|
+
- **Zed**: register `yaddd-linter-lsp` as a language server for Python in
|
|
144
|
+
`settings.json`.
|
|
145
|
+
- **JetBrains**: use LSP4IJ or a small plugin that starts `yaddd-linter-lsp`.
|
|
146
|
+
- **Neovim / Emacs**: configure the server with your LSP client.
|
|
147
|
+
|
|
148
|
+
The LSP server reads the same `[tool.yaddd-linter]` configuration from the
|
|
149
|
+
nearest `pyproject.toml`.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "yaddd-linter"
|
|
3
|
+
version = "0.3.0"
|
|
4
|
+
description = "DDD-aware linter for yaddd projects."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = { text = "MIT" }
|
|
8
|
+
keywords = ["ddd", "linter", "yaddd"]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"Programming Language :: Python :: 3",
|
|
13
|
+
"Programming Language :: Python :: 3.12",
|
|
14
|
+
"Programming Language :: Python :: 3.13",
|
|
15
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
16
|
+
]
|
|
17
|
+
dependencies = [
|
|
18
|
+
"pygls>=1.3,<2",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
yaddd-linter = "yaddd_linter.cli:main"
|
|
23
|
+
yaddd-linter-lsp = "yaddd_linter.lsp:main"
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["hatchling"]
|
|
27
|
+
build-backend = "hatchling.build"
|
|
28
|
+
|
|
29
|
+
[tool.hatch.build.targets.wheel]
|
|
30
|
+
packages = ["src/yaddd_linter"]
|
|
31
|
+
|
|
32
|
+
[tool.ruff]
|
|
33
|
+
line-length = 120
|
|
34
|
+
|
|
35
|
+
[tool.ruff.lint]
|
|
36
|
+
select = ["E", "F", "I", "B", "C4"]
|
|
37
|
+
|
|
38
|
+
[tool.ty.environment]
|
|
39
|
+
python-version = "3.12"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Aggregate and entity detection helpers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import ast
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
AGGREGATE_BASES = frozenset({"AggregateRoot", "Entity"})
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def is_aggregate_classdef(node: ast.ClassDef) -> bool:
|
|
12
|
+
"""Return True if the class definition inherits from AggregateRoot/Entity."""
|
|
13
|
+
for base in node.bases:
|
|
14
|
+
if isinstance(base, ast.Name) and base.id in AGGREGATE_BASES:
|
|
15
|
+
return True
|
|
16
|
+
# yaddd.domain.entities.AggregateRoot
|
|
17
|
+
if isinstance(base, ast.Attribute) and isinstance(base.value, ast.Name):
|
|
18
|
+
if base.attr in AGGREGATE_BASES:
|
|
19
|
+
return True
|
|
20
|
+
return False
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def find_aggregate_classes(path: Path) -> set[str]:
|
|
24
|
+
"""Return a set of aggregate/entity class names defined in the file."""
|
|
25
|
+
try:
|
|
26
|
+
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
|
|
27
|
+
except SyntaxError:
|
|
28
|
+
return set()
|
|
29
|
+
|
|
30
|
+
aggregates: set[str] = set()
|
|
31
|
+
for node in ast.walk(tree):
|
|
32
|
+
if isinstance(node, ast.ClassDef) and is_aggregate_classdef(node):
|
|
33
|
+
aggregates.add(node.name)
|
|
34
|
+
return aggregates
|