@martinffx/atelier 2.0.0 → 3.0.0
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.
- package/CHANGELOG.md +14 -0
- package/README.md +94 -253
- package/package.json +1 -1
- package/skills/{spec-orchestrator → atelier-orchestrator}/SKILL.md +3 -3
- package/skills/atelier-setup/SKILL.md +80 -0
- package/skills/code-review/references/reviewers.md +3 -3
- package/skills/code-review/references/rq.md +6 -6
- package/skills/spec-brainstorm/SKILL.md +5 -5
- package/skills/spec-implement/SKILL.md +2 -3
- package/skills/spec-plan/SKILL.md +21 -29
- package/skills/spec-plan/references/plan_template.md +77 -0
- package/skills/python-architecture/SKILL.md +0 -148
- package/skills/python-architecture/references/data-modeling.md +0 -558
- package/skills/python-architecture/references/ddd.md +0 -569
- package/skills/python-architecture/references/functional-core.md +0 -337
- package/skills/python-build-tools/SKILL.md +0 -153
- package/skills/python-build-tools/references/basedpyright.md +0 -321
- package/skills/python-build-tools/references/ruff.md +0 -225
- package/skills/python-build-tools/references/uv.md +0 -257
- package/skills/python-fastapi/SKILL.md +0 -184
- package/skills/python-fastapi/references/api-design.md +0 -563
- package/skills/python-fastapi/references/dependencies.md +0 -479
- package/skills/python-fastapi/references/middleware.md +0 -475
- package/skills/python-fastapi/references/validation.md +0 -497
- package/skills/python-modern-python/SKILL.md +0 -201
- package/skills/python-modern-python/references/async.md +0 -76
- package/skills/python-modern-python/references/pattern-matching.md +0 -89
- package/skills/python-modern-python/references/typing.md +0 -96
- package/skills/python-monorepo/SKILL.md +0 -146
- package/skills/python-monorepo/references/docker.md +0 -515
- package/skills/python-monorepo/references/namespace-packages.md +0 -426
- package/skills/python-monorepo/references/workspace-config.md +0 -341
- package/skills/python-sqlalchemy/SKILL.md +0 -119
- package/skills/python-sqlalchemy/references/async.md +0 -51
- package/skills/python-sqlalchemy/references/models.md +0 -67
- package/skills/python-sqlalchemy/references/queries.md +0 -57
- package/skills/python-temporal/SKILL.md +0 -128
- package/skills/python-temporal/references/patterns.md +0 -87
- package/skills/python-temporal/references/testing.md +0 -54
- package/skills/python-testing/SKILL.md +0 -161
- package/skills/python-testing/references/boundaries.md +0 -449
- package/skills/python-testing/references/mocking.md +0 -449
- package/skills/python-testing/references/pytest.md +0 -524
- package/skills/typescript-api-design/SKILL.md +0 -396
- package/skills/typescript-api-design/references/error-responses.md +0 -469
- package/skills/typescript-build-tools/SKILL.md +0 -447
- package/skills/typescript-build-tools/references/biome.md +0 -436
- package/skills/typescript-build-tools/references/bun.md +0 -432
- package/skills/typescript-build-tools/references/turborepo.md +0 -426
- package/skills/typescript-build-tools/references/vitest.md +0 -518
- package/skills/typescript-drizzle-orm/SKILL.md +0 -398
- package/skills/typescript-drizzle-orm/references/cloudflare.md +0 -392
- package/skills/typescript-drizzle-orm/references/entity-pattern.md +0 -412
- package/skills/typescript-drizzle-orm/references/postgresql.md +0 -191
- package/skills/typescript-drizzle-orm/references/repository-pattern.md +0 -479
- package/skills/typescript-drizzle-orm/references/sqlite.md +0 -291
- package/skills/typescript-dynamodb-toolbox/SKILL.md +0 -370
- package/skills/typescript-dynamodb-toolbox/references/entity-layer.md +0 -574
- package/skills/typescript-dynamodb-toolbox/references/error-handling.md +0 -495
- package/skills/typescript-dynamodb-toolbox/references/modeling.md +0 -332
- package/skills/typescript-dynamodb-toolbox/references/repository-layer.md +0 -631
- package/skills/typescript-dynamodb-toolbox/references/testing.md +0 -718
- package/skills/typescript-dynamodb-toolbox/references/transactions.md +0 -423
- package/skills/typescript-effect-ts/SKILL.md +0 -341
- package/skills/typescript-effect-ts/references/core.md +0 -412
- package/skills/typescript-effect-ts/references/error-handling.md +0 -468
- package/skills/typescript-effect-ts/references/resources.md +0 -476
- package/skills/typescript-effect-ts/references/schema.md +0 -536
- package/skills/typescript-effect-ts/references/services.md +0 -461
- package/skills/typescript-fastify/SKILL.md +0 -405
- package/skills/typescript-fastify/references/plugins.md +0 -329
- package/skills/typescript-fastify/references/typeid.md +0 -315
- package/skills/typescript-functional-patterns/SKILL.md +0 -402
- package/skills/typescript-functional-patterns/references/adts.md +0 -497
- package/skills/typescript-functional-patterns/references/branded-types.md +0 -542
- package/skills/typescript-functional-patterns/references/migration-guide.md +0 -695
- package/skills/typescript-functional-patterns/references/option-result.md +0 -585
- package/skills/typescript-testing/SKILL.md +0 -353
- package/skills/typescript-testing/references/mocking.md +0 -675
- package/skills/typescript-testing/references/msw.md +0 -852
- package/skills/typescript-testing/references/snapshot-testing.md +0 -774
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
# basedpyright - Strict Type Checking
|
|
2
|
-
|
|
3
|
-
Fast type checker forked from pyright with improved performance and stricter defaults. Recommended for production Python codebases.
|
|
4
|
-
|
|
5
|
-
## Configuration
|
|
6
|
-
|
|
7
|
-
Complete `[tool.basedpyright]` section in pyproject.toml:
|
|
8
|
-
|
|
9
|
-
```toml
|
|
10
|
-
[tool.basedpyright]
|
|
11
|
-
typeCheckingMode = "strict"
|
|
12
|
-
pythonVersion = "3.12"
|
|
13
|
-
pythonPlatform = "Linux"
|
|
14
|
-
|
|
15
|
-
# Paths
|
|
16
|
-
include = ["src", "tests"]
|
|
17
|
-
exclude = ["**/__pycache__", ".venv", "build", "dist"]
|
|
18
|
-
ignore = []
|
|
19
|
-
typeshedPath = ""
|
|
20
|
-
stubPath = ""
|
|
21
|
-
|
|
22
|
-
# Reporting
|
|
23
|
-
reportMissingImports = true
|
|
24
|
-
reportMissingTypeStubs = false
|
|
25
|
-
reportMissingModuleSource = true
|
|
26
|
-
reportUndefinedVariable = true
|
|
27
|
-
reportPrivateUsage = false
|
|
28
|
-
reportGeneralTypeIssues = true
|
|
29
|
-
reportOptionalMemberAccess = true
|
|
30
|
-
reportOptionalSubscript = true
|
|
31
|
-
reportOptionalCall = true
|
|
32
|
-
reportOptionalIterable = true
|
|
33
|
-
reportOptionalContextManager = true
|
|
34
|
-
reportOptionalOperand = true
|
|
35
|
-
reportOptionalTypeArg = true
|
|
36
|
-
reportUnusedImport = true
|
|
37
|
-
reportUnusedClass = true
|
|
38
|
-
reportUnusedFunction = true
|
|
39
|
-
reportUnusedVariable = true
|
|
40
|
-
reportDuplicateImport = true
|
|
41
|
-
reportIncompatibleMethodOverride = true
|
|
42
|
-
reportIncompatibleVariableOverride = true
|
|
43
|
-
reportAssignmentType = true
|
|
44
|
-
reportReturnType = true
|
|
45
|
-
|
|
46
|
-
# Lenient mode (use sparingly)
|
|
47
|
-
reportIncompatibleMethodOverride = "warning"
|
|
48
|
-
reportOptionalMemberAccess = "warning"
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Type Checking Modes
|
|
52
|
-
|
|
53
|
-
- **off**: No type checking
|
|
54
|
-
- **basic**: Basic type checking (fastest)
|
|
55
|
-
- **standard**: Standard type checking (default)
|
|
56
|
-
- **strict**: Strict type checking (recommended for production)
|
|
57
|
-
|
|
58
|
-
Recommend `strict` for new projects. For existing codebases, start with `basic` and incrementally increase.
|
|
59
|
-
|
|
60
|
-
## Common Type Patterns
|
|
61
|
-
|
|
62
|
-
### Basic Types
|
|
63
|
-
|
|
64
|
-
```python
|
|
65
|
-
from typing import Optional, Union, Any
|
|
66
|
-
from decimal import Decimal
|
|
67
|
-
|
|
68
|
-
# Basic types
|
|
69
|
-
name: str = "Alice"
|
|
70
|
-
age: int = 30
|
|
71
|
-
price: float = 19.99
|
|
72
|
-
decimal_price: Decimal = Decimal("19.99")
|
|
73
|
-
is_active: bool = True
|
|
74
|
-
|
|
75
|
-
# Collections
|
|
76
|
-
items: list[str] = ["apple", "banana"]
|
|
77
|
-
mapping: dict[str, int] = {"count": 5}
|
|
78
|
-
unique: set[str] = {"a", "b", "c"}
|
|
79
|
-
coords: tuple[int, int] = (10, 20)
|
|
80
|
-
|
|
81
|
-
# Optional (value or None)
|
|
82
|
-
nickname: Optional[str] = None
|
|
83
|
-
nickname = "Bob" # OK
|
|
84
|
-
|
|
85
|
-
# Union (multiple types)
|
|
86
|
-
value: Union[int, str] = 42
|
|
87
|
-
value = "text" # OK
|
|
88
|
-
|
|
89
|
-
# Generic unknown
|
|
90
|
-
data: Any = {"key": "value"} # Avoid when possible
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### Functions
|
|
94
|
-
|
|
95
|
-
```python
|
|
96
|
-
def calculate_discount(
|
|
97
|
-
total: Decimal,
|
|
98
|
-
rate: Optional[Decimal] = None
|
|
99
|
-
) -> Decimal:
|
|
100
|
-
"""Calculate discount amount."""
|
|
101
|
-
if rate is None:
|
|
102
|
-
rate = Decimal("0.1")
|
|
103
|
-
return total * rate
|
|
104
|
-
|
|
105
|
-
def process_items(items: list[str]) -> None:
|
|
106
|
-
"""Process items - no return value."""
|
|
107
|
-
for item in items:
|
|
108
|
-
print(item)
|
|
109
|
-
|
|
110
|
-
def get_or_default(value: Optional[str]) -> str:
|
|
111
|
-
"""Return value or default."""
|
|
112
|
-
return value or "default"
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### Classes
|
|
116
|
-
|
|
117
|
-
```python
|
|
118
|
-
from dataclasses import dataclass
|
|
119
|
-
|
|
120
|
-
@dataclass
|
|
121
|
-
class User:
|
|
122
|
-
"""User entity with type hints."""
|
|
123
|
-
id: int
|
|
124
|
-
name: str
|
|
125
|
-
email: str
|
|
126
|
-
age: Optional[int] = None
|
|
127
|
-
|
|
128
|
-
def validate(self) -> None:
|
|
129
|
-
"""Validate user data."""
|
|
130
|
-
if not self.name:
|
|
131
|
-
raise ValueError("Name required")
|
|
132
|
-
if self.age is not None and self.age < 0:
|
|
133
|
-
raise ValueError("Age must be positive")
|
|
134
|
-
|
|
135
|
-
@property
|
|
136
|
-
def is_adult(self) -> bool:
|
|
137
|
-
"""Check if adult."""
|
|
138
|
-
if self.age is None:
|
|
139
|
-
return False
|
|
140
|
-
return self.age >= 18
|
|
141
|
-
|
|
142
|
-
def __str__(self) -> str:
|
|
143
|
-
return f"{self.name} ({self.email})"
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Generics
|
|
147
|
-
|
|
148
|
-
```python
|
|
149
|
-
from typing import Generic, TypeVar
|
|
150
|
-
|
|
151
|
-
T = TypeVar("T")
|
|
152
|
-
|
|
153
|
-
class Container(Generic[T]):
|
|
154
|
-
"""Generic container."""
|
|
155
|
-
def __init__(self, item: T) -> None:
|
|
156
|
-
self.item = item
|
|
157
|
-
|
|
158
|
-
def get(self) -> T:
|
|
159
|
-
return self.item
|
|
160
|
-
|
|
161
|
-
# Usage
|
|
162
|
-
int_container: Container[int] = Container(42)
|
|
163
|
-
value: int = int_container.get()
|
|
164
|
-
|
|
165
|
-
str_container: Container[str] = Container("hello")
|
|
166
|
-
text: str = str_container.get()
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### Protocol (Structural Typing)
|
|
170
|
-
|
|
171
|
-
```python
|
|
172
|
-
from typing import Protocol
|
|
173
|
-
|
|
174
|
-
class Logger(Protocol):
|
|
175
|
-
"""Logger protocol."""
|
|
176
|
-
def log(self, message: str) -> None: ...
|
|
177
|
-
def error(self, message: str) -> None: ...
|
|
178
|
-
|
|
179
|
-
class ConsoleLogger:
|
|
180
|
-
"""Implements Logger protocol."""
|
|
181
|
-
def log(self, message: str) -> None:
|
|
182
|
-
print(f"INFO: {message}")
|
|
183
|
-
|
|
184
|
-
def error(self, message: str) -> None:
|
|
185
|
-
print(f"ERROR: {message}")
|
|
186
|
-
|
|
187
|
-
def use_logger(logger: Logger) -> None:
|
|
188
|
-
"""Use any logger that implements protocol."""
|
|
189
|
-
logger.log("Starting")
|
|
190
|
-
logger.error("Something failed")
|
|
191
|
-
|
|
192
|
-
# ConsoleLogger satisfies Logger protocol
|
|
193
|
-
use_logger(ConsoleLogger())
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
## Commands
|
|
197
|
-
|
|
198
|
-
```bash
|
|
199
|
-
# Type check entire project
|
|
200
|
-
basedpyright
|
|
201
|
-
|
|
202
|
-
# Type check specific file
|
|
203
|
-
basedpyright src/main.py
|
|
204
|
-
|
|
205
|
-
# Type check specific directory
|
|
206
|
-
basedpyright src/
|
|
207
|
-
|
|
208
|
-
# Verbose output
|
|
209
|
-
basedpyright --verbose
|
|
210
|
-
|
|
211
|
-
# Show warnings
|
|
212
|
-
basedpyright --warnings
|
|
213
|
-
|
|
214
|
-
# Output format
|
|
215
|
-
basedpyright --outputjson
|
|
216
|
-
|
|
217
|
-
# Type checking statistics
|
|
218
|
-
basedpyright --stats
|
|
219
|
-
|
|
220
|
-
# Configuration
|
|
221
|
-
basedpyright --configfile custom.toml
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
## Integration
|
|
225
|
-
|
|
226
|
-
### With VS Code
|
|
227
|
-
|
|
228
|
-
Install extension: Pylance or Basedpyright (by Bazel)
|
|
229
|
-
|
|
230
|
-
Add to `.vscode/settings.json`:
|
|
231
|
-
|
|
232
|
-
```json
|
|
233
|
-
{
|
|
234
|
-
"python.linting.enabled": true,
|
|
235
|
-
"[python]": {
|
|
236
|
-
"editor.defaultFormatter": "charliermarsh.ruff",
|
|
237
|
-
"editor.formatOnSave": true,
|
|
238
|
-
"editor.codeActionsOnSave": {
|
|
239
|
-
"source.organizeImports": "explicit"
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
"basedpyright.typeCheckingMode": "strict"
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### Pre-commit Hook
|
|
247
|
-
|
|
248
|
-
Add to `.pre-commit-config.yaml`:
|
|
249
|
-
|
|
250
|
-
```yaml
|
|
251
|
-
- repo: local
|
|
252
|
-
hooks:
|
|
253
|
-
- id: basedpyright
|
|
254
|
-
name: basedpyright
|
|
255
|
-
entry: basedpyright
|
|
256
|
-
language: system
|
|
257
|
-
types: [python]
|
|
258
|
-
require_serial: true
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
### GitHub Actions
|
|
262
|
-
|
|
263
|
-
```yaml
|
|
264
|
-
- name: Type check with basedpyright
|
|
265
|
-
run: basedpyright
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
## Common Issues
|
|
269
|
-
|
|
270
|
-
### Missing Type Stubs
|
|
271
|
-
|
|
272
|
-
Install type stubs for third-party packages:
|
|
273
|
-
|
|
274
|
-
```bash
|
|
275
|
-
uv add --dev types-requests types-pyyaml types-click
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
### Ignoring Type Errors
|
|
279
|
-
|
|
280
|
-
```python
|
|
281
|
-
# Ignore entire line
|
|
282
|
-
value: int = some_string_func() # type: ignore
|
|
283
|
-
|
|
284
|
-
# Ignore specific error
|
|
285
|
-
value: int = some_string_func() # type: ignore[assignment]
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
Use sparingly - type hints should be fixed, not ignored.
|
|
289
|
-
|
|
290
|
-
### Strict Mode Challenges
|
|
291
|
-
|
|
292
|
-
If strict mode is too strict, consider:
|
|
293
|
-
|
|
294
|
-
1. Using `type: ignore` for legacy code
|
|
295
|
-
2. Starting with `standard` mode and gradually increasing strictness
|
|
296
|
-
3. Configuring `reportPrivateUsage = false` for internal APIs
|
|
297
|
-
4. Excluding test code: `exclude = ["tests"]`
|
|
298
|
-
|
|
299
|
-
## Performance
|
|
300
|
-
|
|
301
|
-
Basedpyright is 2-5x faster than mypy on large codebases.
|
|
302
|
-
|
|
303
|
-
Typical project:
|
|
304
|
-
- mypy: 10-30 seconds
|
|
305
|
-
- basedpyright: 2-10 seconds
|
|
306
|
-
|
|
307
|
-
## Troubleshooting
|
|
308
|
-
|
|
309
|
-
```bash
|
|
310
|
-
# Clear cache
|
|
311
|
-
rm -rf .basedpyright
|
|
312
|
-
|
|
313
|
-
# Verbose error messages
|
|
314
|
-
basedpyright --verbose
|
|
315
|
-
|
|
316
|
-
# Check configuration
|
|
317
|
-
basedpyright --showconfig
|
|
318
|
-
|
|
319
|
-
# Update tool
|
|
320
|
-
uv add --upgrade basedpyright
|
|
321
|
-
```
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
# ruff - Fast Python Linter and Formatter
|
|
2
|
-
|
|
3
|
-
Rust-based linter and formatter that replaces black, isort, flake8, and pylint. 10-100x faster with auto-fix and formatting capabilities.
|
|
4
|
-
|
|
5
|
-
## Configuration
|
|
6
|
-
|
|
7
|
-
Complete `[tool.ruff]` section in pyproject.toml:
|
|
8
|
-
|
|
9
|
-
```toml
|
|
10
|
-
[tool.ruff]
|
|
11
|
-
line-length = 100
|
|
12
|
-
target-version = "py312"
|
|
13
|
-
src = ["src", "tests"]
|
|
14
|
-
extend-exclude = [".git", ".venv", "node_modules"]
|
|
15
|
-
|
|
16
|
-
[tool.ruff.lint]
|
|
17
|
-
select = [
|
|
18
|
-
"E", # pycodestyle errors
|
|
19
|
-
"F", # pyflakes
|
|
20
|
-
"W", # pycodestyle warnings
|
|
21
|
-
"I", # isort (import sorting)
|
|
22
|
-
"N", # pep8-naming
|
|
23
|
-
"UP", # pyupgrade
|
|
24
|
-
"RUF", # Ruff-specific rules
|
|
25
|
-
"B", # flake8-bugbear
|
|
26
|
-
"C4", # flake8-comprehensions
|
|
27
|
-
"SIM", # flake8-simplify
|
|
28
|
-
"PIE", # flake8-pie
|
|
29
|
-
"RET", # flake8-return
|
|
30
|
-
"Q", # flake8-quotes
|
|
31
|
-
"PT", # flake8-pytest-style
|
|
32
|
-
"LOG", # flake8-logging
|
|
33
|
-
]
|
|
34
|
-
ignore = [
|
|
35
|
-
"E501", # Line too long (handled by formatter)
|
|
36
|
-
"E203", # Whitespace before punctuation
|
|
37
|
-
"PT004", # Fixture doesn't return anything
|
|
38
|
-
]
|
|
39
|
-
extend-safe-fixes = ["PIE794", "RUF100"]
|
|
40
|
-
|
|
41
|
-
[tool.ruff.lint.per-file-ignores]
|
|
42
|
-
"__init__.py" = ["F401"] # Ignore unused imports in __init__
|
|
43
|
-
"tests/*.py" = ["B008"] # Ignore mutable defaults in tests
|
|
44
|
-
|
|
45
|
-
[tool.ruff.lint.isort]
|
|
46
|
-
known-first-party = ["my_app", "my_service"]
|
|
47
|
-
force-single-line = false
|
|
48
|
-
combine-as-imports = true
|
|
49
|
-
|
|
50
|
-
[tool.ruff.lint.flake8-quotes]
|
|
51
|
-
docstring-quotes = "double"
|
|
52
|
-
inline-quotes = "double"
|
|
53
|
-
|
|
54
|
-
[tool.ruff.lint.flake8-comprehensions]
|
|
55
|
-
allow-dict-calls-with-keyword-arguments = true
|
|
56
|
-
|
|
57
|
-
[tool.ruff.format]
|
|
58
|
-
quote-style = "double"
|
|
59
|
-
indent-style = "space"
|
|
60
|
-
skip-magic-trailing-comma = false
|
|
61
|
-
line-ending = "auto"
|
|
62
|
-
docstring-code-format = true
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Rules Reference
|
|
66
|
-
|
|
67
|
-
### Error Categories
|
|
68
|
-
|
|
69
|
-
- **E/W**: pycodestyle - Style errors and warnings
|
|
70
|
-
- **F**: pyflakes - Logic errors
|
|
71
|
-
- **I**: isort - Import sorting
|
|
72
|
-
- **N**: pep8-naming - Naming conventions
|
|
73
|
-
- **UP**: pyupgrade - Modernize code
|
|
74
|
-
- **RUF**: Ruff-specific rules
|
|
75
|
-
|
|
76
|
-
### Common Issues and Fixes
|
|
77
|
-
|
|
78
|
-
```python
|
|
79
|
-
# ✓ Correct: Double quotes
|
|
80
|
-
message = "hello"
|
|
81
|
-
|
|
82
|
-
# ✗ Error: Single quotes (unless docstring)
|
|
83
|
-
message = 'hello'
|
|
84
|
-
|
|
85
|
-
# ✓ Correct: Sorted imports
|
|
86
|
-
import asyncio
|
|
87
|
-
import os
|
|
88
|
-
from typing import Optional
|
|
89
|
-
|
|
90
|
-
from pydantic import BaseModel
|
|
91
|
-
from sqlalchemy import Column, String
|
|
92
|
-
|
|
93
|
-
# ✗ Error: Unsorted imports
|
|
94
|
-
from sqlalchemy import Column
|
|
95
|
-
import os
|
|
96
|
-
import asyncio
|
|
97
|
-
|
|
98
|
-
# ✓ Correct: List comprehension
|
|
99
|
-
squares = [x**2 for x in range(10)]
|
|
100
|
-
|
|
101
|
-
# ✗ Error: Using map instead of comprehension (C401)
|
|
102
|
-
squares = list(map(lambda x: x**2, range(10)))
|
|
103
|
-
|
|
104
|
-
# ✓ Correct: Type hints with modern syntax
|
|
105
|
-
items: list[str] = ["apple"]
|
|
106
|
-
config: dict[str, int] = {}
|
|
107
|
-
|
|
108
|
-
# ✗ Error: Old-style type hints
|
|
109
|
-
items: List[str] = ["apple"]
|
|
110
|
-
config: Dict[str, int] = {}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
## Command Line Usage
|
|
114
|
-
|
|
115
|
-
```bash
|
|
116
|
-
# Check for issues
|
|
117
|
-
ruff check .
|
|
118
|
-
|
|
119
|
-
# Auto-fix issues
|
|
120
|
-
ruff check --fix .
|
|
121
|
-
|
|
122
|
-
# Fix specific file
|
|
123
|
-
ruff check --fix src/main.py
|
|
124
|
-
|
|
125
|
-
# Format code
|
|
126
|
-
ruff format .
|
|
127
|
-
|
|
128
|
-
# Format and check combined
|
|
129
|
-
ruff check --fix . && ruff format .
|
|
130
|
-
|
|
131
|
-
# Check specific rule
|
|
132
|
-
ruff check . --select E501
|
|
133
|
-
|
|
134
|
-
# Ignore specific rule
|
|
135
|
-
ruff check . --ignore F841
|
|
136
|
-
|
|
137
|
-
# Show statistics
|
|
138
|
-
ruff check . --statistics
|
|
139
|
-
|
|
140
|
-
# Generate configuration
|
|
141
|
-
ruff config
|
|
142
|
-
|
|
143
|
-
# Check what would be fixed
|
|
144
|
-
ruff check . --diff
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
## Integration Examples
|
|
148
|
-
|
|
149
|
-
### With pytest
|
|
150
|
-
|
|
151
|
-
In `pyproject.toml`:
|
|
152
|
-
|
|
153
|
-
```toml
|
|
154
|
-
[tool.ruff.lint]
|
|
155
|
-
select = ["PT"] # Include pytest-style rules
|
|
156
|
-
|
|
157
|
-
[tool.ruff.lint.flake8-pytest-style]
|
|
158
|
-
fixture-parentheses = true
|
|
159
|
-
parametrize-names-type = "csv"
|
|
160
|
-
parametrize-values-row-type = "tuple"
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
### Pre-commit Hook
|
|
164
|
-
|
|
165
|
-
Create `.pre-commit-config.yaml`:
|
|
166
|
-
|
|
167
|
-
```yaml
|
|
168
|
-
repos:
|
|
169
|
-
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
170
|
-
rev: v0.8.0
|
|
171
|
-
hooks:
|
|
172
|
-
- id: ruff
|
|
173
|
-
args: [--fix]
|
|
174
|
-
- id: ruff-format
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### GitHub Actions
|
|
178
|
-
|
|
179
|
-
```yaml
|
|
180
|
-
- name: Lint with ruff
|
|
181
|
-
run: ruff check --fix .
|
|
182
|
-
|
|
183
|
-
- name: Format with ruff
|
|
184
|
-
run: ruff format .
|
|
185
|
-
|
|
186
|
-
- name: Check format
|
|
187
|
-
run: ruff format --check .
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
## Performance Notes
|
|
191
|
-
|
|
192
|
-
- Ruff processes entire codebase in ~200ms
|
|
193
|
-
- Parallel processing on multi-core systems
|
|
194
|
-
- Significantly faster than pycodestyle + isort + black
|
|
195
|
-
|
|
196
|
-
## Migration from Black/isort
|
|
197
|
-
|
|
198
|
-
Replace:
|
|
199
|
-
|
|
200
|
-
```bash
|
|
201
|
-
# Old
|
|
202
|
-
black src/ && isort src/
|
|
203
|
-
|
|
204
|
-
# New
|
|
205
|
-
ruff format . && ruff check --fix .
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
## Troubleshooting
|
|
209
|
-
|
|
210
|
-
```bash
|
|
211
|
-
# Show which rules are active
|
|
212
|
-
ruff rule --all
|
|
213
|
-
|
|
214
|
-
# Show rule details
|
|
215
|
-
ruff rule E501
|
|
216
|
-
|
|
217
|
-
# Check what ruff would do (dry run)
|
|
218
|
-
ruff check . --diff
|
|
219
|
-
|
|
220
|
-
# Clear cache if issues occur
|
|
221
|
-
rm -rf .ruff_cache
|
|
222
|
-
|
|
223
|
-
# Verbose output
|
|
224
|
-
ruff check . -v
|
|
225
|
-
```
|