Skip to content

Commit f13a494

Browse files
committed
chore: configure linting for the project
1 parent 5a2f2ec commit f13a494

6 files changed

Lines changed: 136 additions & 8 deletions

File tree

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# https://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
end_of_line = lf
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
applyTo: "**/*.py"
3+
description: "ALWAYS read these when reading or modifying Python files. Covers ruff lint/format and pyright type-checking expectations, scope, and the pre-commit workflow."
4+
---
5+
6+
# Python Files
7+
8+
This repo uses [`ruff`](https://docs.astral.sh/ruff/) for linting/formatting and [`pyright`](https://microsoft.github.io/pyright/) for type checking. Config: [`ruff.toml`](../../ruff.toml), [`pyrightconfig.json`](../../pyrightconfig.json).
9+
10+
## Before committing
11+
12+
After editing any `.py` file, run both checks on the files you touched:
13+
14+
```bash
15+
ruff check <file> # add --fix to auto-apply safe fixes
16+
ruff format <file> # formatting
17+
pyright <file> # type checking
18+
```
19+
20+
Or check everything at once:
21+
22+
```bash
23+
ruff check
24+
pyright
25+
```
26+
27+
## Expectations
28+
29+
- **Don't introduce new violations.** If `ruff check` or `pyright` reports new errors against files you modified, fix them before committing.
30+
- **Pre-existing violations** in files you didn't touch are out of scope — leave them for whoever next edits that file.
31+
- **Auto-fixes** (`ruff check --fix`) are safe to apply on files you're already editing. Review the diff before committing.
32+
- **`# noqa` and `# type: ignore` comments** require a justification comment on the same line (e.g. `# noqa: F401 — re-exported`) and should be used extremely sparingly.
33+
34+
## Scope
35+
36+
Both tools currently scan: `.github/`, `base/`, `scripts/`. Generated/vendored paths (`base/build`, `base/out`, `specs`, `**/__pycache__`, `**/.venv`, `**/venv`, `**/node_modules`) are excluded.

.vscode/extensions.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"recommendations": [
3+
"charliermarsh.ruff",
4+
"editorconfig.editorconfig",
5+
"DavidAnson.vscode-markdownlint",
6+
"timonwong.shellcheck",
7+
"ms-python.vscode-pylance"
8+
]
9+
}

.vscode/settings.json

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// These files should not be manually edited — modify the TOML sources instead.
44
// Prevent accidental edits to rendered specs.
55
"files.readonlyInclude": {
6-
"specs/**": true
6+
"specs/**": true,
7+
"locks/**": true
78
},
89
// Suppress diagnostics from rendered specs — they are not source files.
910
// Unfortunately, vscode does not provide a way to exclude all problem
@@ -13,16 +14,45 @@
1314
"shellcheck.ignorePatterns": {
1415
"specs/**": true
1516
},
16-
"python.analysis.exclude": [
17-
"specs",
18-
"**/node_modules",
19-
"**/__pycache__",
20-
"**/.*"
21-
],
2217
// Using Azure Pipelines schema for validation of ADO YAMLs.
2318
"azure-pipelines.1ESPipelineTemplatesSchemaFile": true,
2419
// Associate ADO pipelines with the "azure-pipelines" type instead of GitHub Actions.
2520
"files.associations": {
2621
"**/.github/workflows/ado/**/*.yml": "azure-pipelines"
27-
}
22+
},
23+
// General lint rules
24+
"editor.formatOnSave": true,
25+
"editor.codeActionsOnSave": {
26+
"source.fixAll.markdownlint": "explicit",
27+
"source.fixAll.shellcheck": "explicit"
28+
},
29+
"shellcheck.enable": true,
30+
"shellcheck.enableQuickFix": true,
31+
// Lint rules for python
32+
"[python]": {
33+
"editor.defaultFormatter": "charliermarsh.ruff",
34+
"editor.formatOnSave": true,
35+
"editor.codeActionsOnSave": {
36+
"source.fixAll.ruff": "explicit",
37+
"source.organizeImports.ruff": "explicit",
38+
"source.fixAll": "explicit",
39+
"source.fixAll.pylance": "explicit"
40+
}
41+
},
42+
"python.analysis.diagnosticsSource": "Pylance",
43+
"python.missingPackage.severity": "Error",
44+
"python.testing.unittestEnabled": false,
45+
"python.testing.pytestEnabled": true,
46+
"python.analysis.exclude": [
47+
"**/node_modules",
48+
"**/__pycache__",
49+
"**/.*",
50+
"specs",
51+
"base/build"
52+
],
53+
"python.analysis.include": [
54+
".github"
55+
],
56+
"ruff.configuration": "${workspaceFolder}/ruff.toml",
57+
"ruff.lint.enable": true
2858
}

pyrightconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"exclude": [
3+
"**/node_modules",
4+
"**/__pycache__",
5+
"**/.venv",
6+
"**/venv",
7+
"base/build",
8+
"base/out",
9+
"specs"
10+
],
11+
"typeCheckingMode": "standard",
12+
"pythonVersion": "3.12",
13+
"pythonPlatform": "Linux",
14+
"reportUntypedFunctionDecorator": "error",
15+
"reportMissingTypeStubs": "warning",
16+
"reportMissingParameterType": "error",
17+
"reportMissingTypeArgument": "error",
18+
"reportUnknownParameterType": "error"
19+
}

ruff.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
extend-exclude = ["base/build", "base/out", "specs"]
2+
3+
line-length = 120
4+
5+
target-version = "py312"
6+
7+
[lint]
8+
select = ["ALL"] # Everything
9+
ignore = [
10+
"COM812", # Conflicts with formatter.
11+
"S603", # Check for validation of input to subprocess calls, almost always a false positive
12+
"S607", # Requiring abspath for all binaries used is very restrictive
13+
"T201", # These scripts are fine to use `print` for output
14+
]
15+
16+
# We want D401 still, even though google style omits it.
17+
extend-select = ["D401"]
18+
19+
fixable = ["ALL"]
20+
21+
[lint.isort]
22+
# Just force this, its better than dealing with a mishmash of modules that have annotations and those that don't
23+
required-imports = ["from __future__ import annotations"]
24+
25+
[lint.pydocstyle]
26+
convention = "google"

0 commit comments

Comments
 (0)