diff --git a/README.md b/README.md index 2ccfff88f..9edcc3bf4 100644 --- a/README.md +++ b/README.md @@ -48,18 +48,20 @@ The commands above run all linting checks, but for performance you may want to r if you only changed C++ files, you don't need to run the YAML linting checks) using one of the tasks in the table below. -| Task | Description | -|-------------------------|----------------------------------------------------------| -| `lint:cmake-check` | Runs the CMake linters. | -| `lint:cmake-fix` | Runs the CMake linters and fixes any violations. | -| `lint:cpp-check` | Runs the C++ linters (formatters and static analyzers). | -| `lint:cpp-fix` | Runs the C++ linters and fixes some violations. | -| `lint:cpp-format-check` | Runs the C++ formatters. | -| `lint:cpp-format-fix` | Runs the C++ formatters and fixes some violations. | -| `lint:cpp-static-check` | Runs the C++ static analyzers. | -| `lint:cpp-static-fix` | Runs the C++ static analyzers and fixes some violations. | -| `lint:yml-check` | Runs the YAML linters. | -| `lint:yml-fix` | Runs the YAML linters and fixes some violations. | +| Task | Description | +|-------------------------|----------------------------------------------------------------| +| `lint:cmake-check` | Runs the CMake linters. | +| `lint:cmake-fix` | Runs the CMake linters and fixes any violations. | +| `lint:cpp-check` | Runs the C++ linters (formatters and static analyzers). | +| `lint:cpp-fix` | Runs the C++ linters and fixes some violations. | +| `lint:cpp-format-check` | Runs the C++ formatters. | +| `lint:cpp-format-fix` | Runs the C++ formatters and fixes some violations. | +| `lint:cpp-static-check` | Runs the C++ static analyzers. | +| `lint:cpp-static-fix` | Runs the C++ static analyzers and fixes some violations. | +| `lint:toml-check` | Runs the TOML linters and formatter. | +| `lint:toml-fix` | Runs the TOML linters and formatter and fixes some violations. | +| `lint:yml-check` | Runs the YAML linters. | +| `lint:yml-fix` | Runs the YAML linters and fixes some violations. | [spider-docs]: https://docs.yscope.com/spider/main/ [Task]: https://taskfile.dev diff --git a/lint-tasks.yaml b/lint-tasks.yaml index 842e61eb1..54ca4611c 100644 --- a/lint-tasks.yaml +++ b/lint-tasks.yaml @@ -10,12 +10,14 @@ tasks: - task: "cmake-check" - task: "cpp-check" - task: "py-check" + - task: "toml-check" - task: "yml-check" fix: cmds: - task: "cmake-fix" - task: "cpp-fix" + - task: "toml-fix" - task: "yml-fix" cmake-check: @@ -154,6 +156,36 @@ tasks: taskfile.yaml \ test-tasks.yaml + toml-check: + cmds: + - task: "toml-lint" + - task: "toml-format" + vars: + FLAGS: "--check" + + toml-fix: + cmds: + - task: "toml-lint" + - task: "toml-format" + + toml-lint: + internal: true + deps: ["venv"] + cmds: + - |- + . "{{.G_LINT_VENV_DIR}}/bin/activate" + tombi lint "{{.ROOT_DIR}}" + + toml-format: + internal: true + deps: ["venv"] + vars: + FLAGS: "{{.FLAGS | default \"\"}}" + cmds: + - |- + . "{{.G_LINT_VENV_DIR}}/bin/activate" + tombi format {{.FLAGS}} "{{.ROOT_DIR}}" + cmake: internal: true requires: diff --git a/requirements-dev.txt b/requirements-dev.txt index bff7a4049..a5e8717f2 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,9 +2,10 @@ clang-format>=20.1.0 # Lock to v19.x until we can upgrade our code to fix new v20 issues. clang-tidy~=19.1 -ruff>=0.4.4 -mypy>=1.12.0 gersemi>=0.16.2 +mypy>=1.12.0 +ruff>=0.4.4 +tombi>=0.4.35 yamllint>=1.35.1 # Test dependencies diff --git a/ruff.toml b/ruff.toml index 3bde2f52d..141cff11f 100644 --- a/ruff.toml +++ b/ruff.toml @@ -4,31 +4,31 @@ line-length = 100 select = ["ALL"] extend-select = ["PT"] ignore = [ - "COM812", # Redundant and conflicts with ruff format - "D203", # No blank line before docstrings (D211) - "D205", # Breaks if summary is larger than one line due to wrapping or if no summary exists - "D212", # Enforce docstring summary line on the next line after quotes (D213) - "D400", # First line of docstrings may not end in period - "D401", # Docstrings should be written in present tense (not imperative) - "D415", # First line of docstrings may not end in a period, question mark, or exclamation point - "FA102", # Allow use of PEP 604 union in type annotations - "FBT", # Allow bool positional parameters since other value positions are allowed - "FIX002", # Allow todo statements - "PERF401", # Allow for loops when creating lists - "PERF403", # Allow for loops when creating dicts - "S311", # Allow usage of `random` package - "SIM102", # Allow collapsible if statements for readability - "TD002", # Author unnecessary for todo statement - "TD003", # Issue link unnecessary for todo statement - "UP015", # Explicit open modes are helpful + "COM812", # Redundant and conflicts with ruff format + "D203", # No blank line before docstrings (D211) + "D205", # Breaks if summary is larger than one line due to wrapping or if no summary exists + "D212", # Enforce docstring summary line on the next line after quotes (D213) + "D400", # First line of docstrings may not end in period + "D401", # Docstrings should be written in present tense (not imperative) + "D415", # First line of docstrings may not end in a period, question mark, or exclamation point + "FA102", # Allow use of PEP 604 union in type annotations + "FBT", # Allow bool positional parameters since other value positions are allowed + "FIX002", # Allow todo statements + "PERF401", # Allow for loops when creating lists + "PERF403", # Allow for loops when creating dicts + "S311", # Allow usage of `random` package + "SIM102", # Allow collapsible if statements for readability + "TD002", # Author unnecessary for todo statement + "TD003", # Issue link unnecessary for todo statement + "UP015", # Explicit open modes are helpful ] isort.order-by-type = false [lint.per-file-ignores] "tests/integration/test_*.py" = [ - "S101", # Allow use of `assert` (security warning) - "S603", # Allow use of `subprocess.Popen` (security warning) - "T201", # Allow use of `print` (testing) + "S101", # Allow use of `assert` (security warning) + "S603", # Allow use of `subprocess.Popen` (security warning) + "T201", # Allow use of `print` (testing) ] [format] diff --git a/tests/integration/utils.py b/tests/integration/utils.py index a04ce6bb5..e04b33455 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -2,8 +2,6 @@ import socket -AddrType = tuple[str, int] - def _get_free_tcp_port() -> int: """:return: A free TCP port number.""" diff --git a/tombi.toml b/tombi.toml new file mode 100644 index 000000000..428d19c2b --- /dev/null +++ b/tombi.toml @@ -0,0 +1,35 @@ +toml-version = "v1.0.0" + +[files] +include = ["**/*.toml"] +exclude = ["tools/yscope-dev-utils/**", "build/**"] + +[format] + +[lint] +[lint.rules] +dotted-keys-out-of-order = "warn" +key-empty = "warn" +tables-out-of-order = "warn" + +[schema] +enabled = true +strict = true +catalog = { + paths = [ + "tombi://json.schemastore.org/api/json/catalog.json", + "https://json.schemastore.org/api/json/catalog.json", + ], +} + +[[schemas]] +path = "tombi://json.schemastore.org/tombi.json" +include = ["tombi.toml"] + +[[schemas]] +path = "https://json.schemastore.org/pyproject.json" +include = ["pyproject.toml"] + +[[schemas]] +path = "https://json.schemastore.org/ruff.json" +include = ["ruff.toml"]