kvb-quality 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.
Files changed (90) hide show
  1. kvb_quality-0.1.0/LICENSE +21 -0
  2. kvb_quality-0.1.0/PKG-INFO +98 -0
  3. kvb_quality-0.1.0/README.md +84 -0
  4. kvb_quality-0.1.0/pyproject.toml +39 -0
  5. kvb_quality-0.1.0/rules/architecture.yml +19 -0
  6. kvb_quality-0.1.0/rules/ast-grep/data/hcl.yml +20 -0
  7. kvb_quality-0.1.0/rules/ast-grep/data/json.yml +15 -0
  8. kvb_quality-0.1.0/rules/ast-grep/data/nix.yml +6 -0
  9. kvb_quality-0.1.0/rules/ast-grep/data/yaml.yml +19 -0
  10. kvb_quality-0.1.0/rules/ast-grep/native/c.yml +9 -0
  11. kvb_quality-0.1.0/rules/ast-grep/native/cpp.yml +9 -0
  12. kvb_quality-0.1.0/rules/ast-grep/native/csharp.yml +52 -0
  13. kvb_quality-0.1.0/rules/ast-grep/native/go.yml +13 -0
  14. kvb_quality-0.1.0/rules/ast-grep/native/java.yml +37 -0
  15. kvb_quality-0.1.0/rules/ast-grep/native/kotlin.yml +7 -0
  16. kvb_quality-0.1.0/rules/ast-grep/native/rust.yml +47 -0
  17. kvb_quality-0.1.0/rules/ast-grep/script/bash.yml +76 -0
  18. kvb_quality-0.1.0/rules/ast-grep/script/lua.yml +6 -0
  19. kvb_quality-0.1.0/rules/ast-grep/script/php.yml +8 -0
  20. kvb_quality-0.1.0/rules/ast-grep/script/python.yml +199 -0
  21. kvb_quality-0.1.0/rules/ast-grep/script/ruby.yml +9 -0
  22. kvb_quality-0.1.0/rules/ast-grep/shared.yml +154 -0
  23. kvb_quality-0.1.0/rules/ast-grep/web/css.yml +9 -0
  24. kvb_quality-0.1.0/rules/ast-grep/web/html.yml +17 -0
  25. kvb_quality-0.1.0/rules/ast-grep/web/javascript.yml +74 -0
  26. kvb_quality-0.1.0/rules/ast-grep/web/tsx.yml +88 -0
  27. kvb_quality-0.1.0/rules/ast-grep/web/typescript.yml +88 -0
  28. kvb_quality-0.1.0/rules/clean.yml +162 -0
  29. kvb_quality-0.1.0/rules/coding.yml +153 -0
  30. kvb_quality-0.1.0/rules/comments.yml +123 -0
  31. kvb_quality-0.1.0/rules/kinds.yml +147 -0
  32. kvb_quality-0.1.0/rules/legal.yml +158 -0
  33. kvb_quality-0.1.0/rules/limits.yml +4 -0
  34. kvb_quality-0.1.0/rules/security.yml +220 -0
  35. kvb_quality-0.1.0/rules/semgrep/javascript.yml +18 -0
  36. kvb_quality-0.1.0/rules/tools.yml +128 -0
  37. kvb_quality-0.1.0/setup.cfg +4 -0
  38. kvb_quality-0.1.0/src/kvb_quality.egg-info/PKG-INFO +98 -0
  39. kvb_quality-0.1.0/src/kvb_quality.egg-info/SOURCES.txt +88 -0
  40. kvb_quality-0.1.0/src/kvb_quality.egg-info/dependency_links.txt +1 -0
  41. kvb_quality-0.1.0/src/kvb_quality.egg-info/entry_points.txt +2 -0
  42. kvb_quality-0.1.0/src/kvb_quality.egg-info/requires.txt +2 -0
  43. kvb_quality-0.1.0/src/kvb_quality.egg-info/top_level.txt +1 -0
  44. kvb_quality-0.1.0/src/quality/__init__.py +19 -0
  45. kvb_quality-0.1.0/src/quality/adapters/__init__.py +489 -0
  46. kvb_quality-0.1.0/src/quality/adapters/actionlint.py +44 -0
  47. kvb_quality-0.1.0/src/quality/adapters/astgrep.py +298 -0
  48. kvb_quality-0.1.0/src/quality/adapters/base.py +146 -0
  49. kvb_quality-0.1.0/src/quality/adapters/builtin.py +334 -0
  50. kvb_quality-0.1.0/src/quality/adapters/gitleaks.py +366 -0
  51. kvb_quality-0.1.0/src/quality/adapters/hadolint.py +74 -0
  52. kvb_quality-0.1.0/src/quality/adapters/jscpd.py +98 -0
  53. kvb_quality-0.1.0/src/quality/adapters/lizard.py +49 -0
  54. kvb_quality-0.1.0/src/quality/adapters/osvscanner.py +407 -0
  55. kvb_quality-0.1.0/src/quality/adapters/phpmode.py +226 -0
  56. kvb_quality-0.1.0/src/quality/adapters/rg.py +120 -0
  57. kvb_quality-0.1.0/src/quality/adapters/ruff.py +172 -0
  58. kvb_quality-0.1.0/src/quality/adapters/scancode.py +178 -0
  59. kvb_quality-0.1.0/src/quality/adapters/semgrep.py +157 -0
  60. kvb_quality-0.1.0/src/quality/adapters/shellcheck.py +31 -0
  61. kvb_quality-0.1.0/src/quality/adapters/trivy.py +110 -0
  62. kvb_quality-0.1.0/src/quality/architecture/__init__.py +0 -0
  63. kvb_quality-0.1.0/src/quality/architecture/contract.py +254 -0
  64. kvb_quality-0.1.0/src/quality/architecture/depcruise.py +132 -0
  65. kvb_quality-0.1.0/src/quality/architecture/importlinter.py +161 -0
  66. kvb_quality-0.1.0/src/quality/cli.py +152 -0
  67. kvb_quality-0.1.0/src/quality/db.py +445 -0
  68. kvb_quality-0.1.0/src/quality/doctor.py +205 -0
  69. kvb_quality-0.1.0/src/quality/environment.py +107 -0
  70. kvb_quality-0.1.0/src/quality/gate.py +375 -0
  71. kvb_quality-0.1.0/src/quality/heredoc.py +77 -0
  72. kvb_quality-0.1.0/src/quality/history.py +64 -0
  73. kvb_quality-0.1.0/src/quality/ignorefile.py +210 -0
  74. kvb_quality-0.1.0/src/quality/kinds.py +150 -0
  75. kvb_quality-0.1.0/src/quality/legal/__init__.py +0 -0
  76. kvb_quality-0.1.0/src/quality/legal/checks.py +299 -0
  77. kvb_quality-0.1.0/src/quality/legal/dependencies.py +149 -0
  78. kvb_quality-0.1.0/src/quality/legal/index.py +167 -0
  79. kvb_quality-0.1.0/src/quality/legal/origin.py +166 -0
  80. kvb_quality-0.1.0/src/quality/legal/registry.py +328 -0
  81. kvb_quality-0.1.0/src/quality/legal/spdx.py +210 -0
  82. kvb_quality-0.1.0/src/quality/modes.py +492 -0
  83. kvb_quality-0.1.0/src/quality/process.py +67 -0
  84. kvb_quality-0.1.0/src/quality/repo.py +473 -0
  85. kvb_quality-0.1.0/src/quality/report.py +177 -0
  86. kvb_quality-0.1.0/src/quality/ruledata.py +445 -0
  87. kvb_quality-0.1.0/src/quality/shellview.py +484 -0
  88. kvb_quality-0.1.0/src/quality/snapshot.py +338 -0
  89. kvb_quality-0.1.0/src/quality/suppress.py +255 -0
  90. kvb_quality-0.1.0/src/quality/waivers.py +51 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kevin Veen-Birkenbach
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,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: kvb-quality
3
+ Version: 0.1.0
4
+ Summary: One language-agnostic quality gate for staged changes and whole repositories
5
+ Author-email: Kevin Veen-Birkenbach <kevin@veen.world>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/infinito-nexus/quality
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: PyYAML
12
+ Requires-Dist: pathspec
13
+ Dynamic: license-file
14
+
15
+ # quality
16
+
17
+ Homepage: https://github.com/infinito-nexus/quality
18
+
19
+ ## Install
20
+
21
+ `flake.lock` is the only pin source ([requirement 001](docs/requirements/001-language-agnostic-quality-check.md), decision 18). On a host with Nix, install `packages.default`, the runner wrapped with every tool by absolute store path, and call it by absolute path:
22
+
23
+ ```sh
24
+ nix profile install github:infinito-nexus/quality/<release-tag>
25
+ ~/.nix-profile/bin/quality check --staged
26
+ ```
27
+
28
+ ## Dev stack
29
+
30
+ Hosts without Nix, CI and dev stacks use `packages.image` (`nix build .#image`), the OCI image of the same closure, published to ghcr by digest; the digest is in the release notes. A dev stack adds it as a compose service under the profile `tools` and a make target that runs it:
31
+
32
+ ```yaml
33
+ services:
34
+ quality:
35
+ image: ghcr.io/infinito-nexus/quality@sha256:<digest>
36
+ profiles: [tools]
37
+ network_mode: none
38
+ read_only: true
39
+ tmpfs: [/tmp]
40
+ user: "65534"
41
+ working_dir: /src
42
+ volumes:
43
+ - .:/src:ro
44
+ ```
45
+
46
+ ```make
47
+ quality-check:
48
+ docker compose --profile tools run --rm quality check --staged
49
+ ```
50
+
51
+ `--staged` needs no database. `--base` and `--all` add the deep tier, which reads the bundle of `quality db update`: mount it with `- <db>:/db:ro` and pass `--db /db`. `quality db update --licenses <repo>`, repeatable, also stores the registry licences of the exact pins at each named repository's HEAD and in its staging index for `legal.dependency-license`; a pin without an SPDX licence there stays `unchecked`, and an update without `--licenses` keeps the stored licences. Run the service from a main checkout, because a linked worktree's `.git` file points outside `/src`.
52
+
53
+ ## Layer contracts
54
+
55
+ A repository that holds `.quality/architecture.yml` gets the rules `architecture.layer` and `architecture.cycle` ([requirement 005](docs/requirements/005-architecture-score.md), decision 3); each new hit lowers the architecture score by 25. Python runs through `lint-imports` of import-linter, JavaScript through `depcruise` of dependency-cruiser, both bundled like every other tool. Each section is optional, every key inside it is required, and a malformed file stops the check with an error naming the key. `source` is the directory holding the code, `.` for the root, and for JavaScript also the scope of the cycle check; `layers` lists the highest layer first, and no layer may import one above it:
56
+
57
+ ```yaml
58
+ python:
59
+ source: src
60
+ packages: [shop]
61
+ layers: [shop.web, shop.domain]
62
+ forbidden:
63
+ - {from: [shop.domain], to: [shop.web]}
64
+ javascript:
65
+ source: web
66
+ layers: [web/ui, web/core]
67
+ forbidden: []
68
+ ```
69
+
70
+ ## Hosted scan
71
+
72
+ The role `web-app-cst-quality-check` serves the scan as a web page ([requirement 002](docs/requirements/002-hosted-quality-scan.md)).
73
+
74
+ | Command | What it does |
75
+ | --- | --- |
76
+ | `make up` | Builds the images and serves the page at <http://localhost:18098/>, or on the port `QUALITY_DEV_PORT` names; `make down` removes the stack and its volumes. Needs a vulnerability bundle at `$QUALITY_DEV_DB/bundle` (default `~/.cache/quality-check/dev-db/bundle`), created once with `quality db update --db <that path>`. An exported `INFINITO_CACHE_PACKAGE_URL` makes the Nix builds use that package cache's `raw-nixos-cache` repository. |
77
+ | `make test-service` | Unit tests of the web app and the launcher, in a virtual environment under `.venv/service`. |
78
+ | `make test-egress INFINITO_CORE_DIR=<core> EGRESS_RUNTIMES="<runtimes>"` | Egress tests against the stack of `make up`; the step flags run through that core checkout's container wrapper, and every launcher and test-proxy test runs once under each runtime of `EGRESS_RUNTIMES`, such as `"runc sysbox-runc"`, which `docker info` must offer. |
79
+ | `make verify-test INFINITO_CORE_DIR=<core>` | Pulls the role into a core checkout with custom-role support and runs core's full test suite, lints included. |
80
+ | `make verify-compose INFINITO_CORE_DIR=<core>` | Runs `verify-test` first, then deploys the role with Keycloak through that checkout and runs its Playwright spec. |
81
+
82
+ ## Distribution
83
+
84
+ | Command | What it does |
85
+ | --- | --- |
86
+ | `make test-distribution` | Builds `packages.default` and `packages.image`, then checks pins, notices, `quality doctor` and the image. |
87
+ | `make test-e2e QUALITY_E2E_SKILLS=<repo> QUALITY_E2E_PACKAGE_MANAGER=<repo> QUALITY_E2E_RUNTIME=<runtime>` | Builds both outputs and checks that the host binary and the image, run under that Docker runtime (core's `SANDBOX_RUNTIME`, such as `runsc`), print the same `quality doctor` output and report the same findings on both repositories; needs Docker and the test bundle `make test-integration` fetches. |
88
+
89
+ ## Benchmarks
90
+
91
+ The speed criteria of [requirement 001](docs/requirements/001-language-agnostic-quality-check.md) and its recall bound on core run apart from `test-unit` and `test-integration`. The core checkout is only read.
92
+
93
+ | Command | What it does |
94
+ | --- | --- |
95
+ | `make test-bench QUALITY_CORE_DIR=<core> QUALITY_DB_DIR=<db>` | Times `quality --version` of the built `packages.default` against 0.15 s as the median of 9 runs and its `quality check --all` on core, deep tier included, against 360 s on 20 CPUs, both timings skipped with the measured load as the reason when 50 % or more of the CPUs are busy in the 5 s before or after them, and checks that `clean.default-value` finds every shell, Python and JavaScript default of `tests/bench/default-value-hits.json`, the hits of `defaults.py` of the kvb-code-clean skill on the core commit named there, which `QUALITY_CORE_DIR` must hold. Needs `nix build .#default` of this tree and a fresh bundle of `quality db update`. |
96
+
97
+ ## Author
98
+ Kevin Veen-Birkenbach <kevin@veen.world>
@@ -0,0 +1,84 @@
1
+ # quality
2
+
3
+ Homepage: https://github.com/infinito-nexus/quality
4
+
5
+ ## Install
6
+
7
+ `flake.lock` is the only pin source ([requirement 001](docs/requirements/001-language-agnostic-quality-check.md), decision 18). On a host with Nix, install `packages.default`, the runner wrapped with every tool by absolute store path, and call it by absolute path:
8
+
9
+ ```sh
10
+ nix profile install github:infinito-nexus/quality/<release-tag>
11
+ ~/.nix-profile/bin/quality check --staged
12
+ ```
13
+
14
+ ## Dev stack
15
+
16
+ Hosts without Nix, CI and dev stacks use `packages.image` (`nix build .#image`), the OCI image of the same closure, published to ghcr by digest; the digest is in the release notes. A dev stack adds it as a compose service under the profile `tools` and a make target that runs it:
17
+
18
+ ```yaml
19
+ services:
20
+ quality:
21
+ image: ghcr.io/infinito-nexus/quality@sha256:<digest>
22
+ profiles: [tools]
23
+ network_mode: none
24
+ read_only: true
25
+ tmpfs: [/tmp]
26
+ user: "65534"
27
+ working_dir: /src
28
+ volumes:
29
+ - .:/src:ro
30
+ ```
31
+
32
+ ```make
33
+ quality-check:
34
+ docker compose --profile tools run --rm quality check --staged
35
+ ```
36
+
37
+ `--staged` needs no database. `--base` and `--all` add the deep tier, which reads the bundle of `quality db update`: mount it with `- <db>:/db:ro` and pass `--db /db`. `quality db update --licenses <repo>`, repeatable, also stores the registry licences of the exact pins at each named repository's HEAD and in its staging index for `legal.dependency-license`; a pin without an SPDX licence there stays `unchecked`, and an update without `--licenses` keeps the stored licences. Run the service from a main checkout, because a linked worktree's `.git` file points outside `/src`.
38
+
39
+ ## Layer contracts
40
+
41
+ A repository that holds `.quality/architecture.yml` gets the rules `architecture.layer` and `architecture.cycle` ([requirement 005](docs/requirements/005-architecture-score.md), decision 3); each new hit lowers the architecture score by 25. Python runs through `lint-imports` of import-linter, JavaScript through `depcruise` of dependency-cruiser, both bundled like every other tool. Each section is optional, every key inside it is required, and a malformed file stops the check with an error naming the key. `source` is the directory holding the code, `.` for the root, and for JavaScript also the scope of the cycle check; `layers` lists the highest layer first, and no layer may import one above it:
42
+
43
+ ```yaml
44
+ python:
45
+ source: src
46
+ packages: [shop]
47
+ layers: [shop.web, shop.domain]
48
+ forbidden:
49
+ - {from: [shop.domain], to: [shop.web]}
50
+ javascript:
51
+ source: web
52
+ layers: [web/ui, web/core]
53
+ forbidden: []
54
+ ```
55
+
56
+ ## Hosted scan
57
+
58
+ The role `web-app-cst-quality-check` serves the scan as a web page ([requirement 002](docs/requirements/002-hosted-quality-scan.md)).
59
+
60
+ | Command | What it does |
61
+ | --- | --- |
62
+ | `make up` | Builds the images and serves the page at <http://localhost:18098/>, or on the port `QUALITY_DEV_PORT` names; `make down` removes the stack and its volumes. Needs a vulnerability bundle at `$QUALITY_DEV_DB/bundle` (default `~/.cache/quality-check/dev-db/bundle`), created once with `quality db update --db <that path>`. An exported `INFINITO_CACHE_PACKAGE_URL` makes the Nix builds use that package cache's `raw-nixos-cache` repository. |
63
+ | `make test-service` | Unit tests of the web app and the launcher, in a virtual environment under `.venv/service`. |
64
+ | `make test-egress INFINITO_CORE_DIR=<core> EGRESS_RUNTIMES="<runtimes>"` | Egress tests against the stack of `make up`; the step flags run through that core checkout's container wrapper, and every launcher and test-proxy test runs once under each runtime of `EGRESS_RUNTIMES`, such as `"runc sysbox-runc"`, which `docker info` must offer. |
65
+ | `make verify-test INFINITO_CORE_DIR=<core>` | Pulls the role into a core checkout with custom-role support and runs core's full test suite, lints included. |
66
+ | `make verify-compose INFINITO_CORE_DIR=<core>` | Runs `verify-test` first, then deploys the role with Keycloak through that checkout and runs its Playwright spec. |
67
+
68
+ ## Distribution
69
+
70
+ | Command | What it does |
71
+ | --- | --- |
72
+ | `make test-distribution` | Builds `packages.default` and `packages.image`, then checks pins, notices, `quality doctor` and the image. |
73
+ | `make test-e2e QUALITY_E2E_SKILLS=<repo> QUALITY_E2E_PACKAGE_MANAGER=<repo> QUALITY_E2E_RUNTIME=<runtime>` | Builds both outputs and checks that the host binary and the image, run under that Docker runtime (core's `SANDBOX_RUNTIME`, such as `runsc`), print the same `quality doctor` output and report the same findings on both repositories; needs Docker and the test bundle `make test-integration` fetches. |
74
+
75
+ ## Benchmarks
76
+
77
+ The speed criteria of [requirement 001](docs/requirements/001-language-agnostic-quality-check.md) and its recall bound on core run apart from `test-unit` and `test-integration`. The core checkout is only read.
78
+
79
+ | Command | What it does |
80
+ | --- | --- |
81
+ | `make test-bench QUALITY_CORE_DIR=<core> QUALITY_DB_DIR=<db>` | Times `quality --version` of the built `packages.default` against 0.15 s as the median of 9 runs and its `quality check --all` on core, deep tier included, against 360 s on 20 CPUs, both timings skipped with the measured load as the reason when 50 % or more of the CPUs are busy in the 5 s before or after them, and checks that `clean.default-value` finds every shell, Python and JavaScript default of `tests/bench/default-value-hits.json`, the hits of `defaults.py` of the kvb-code-clean skill on the core commit named there, which `QUALITY_CORE_DIR` must hold. Needs `nix build .#default` of this tree and a fresh bundle of `quality db update`. |
82
+
83
+ ## Author
84
+ Kevin Veen-Birkenbach <kevin@veen.world>
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "kvb-quality"
7
+ dynamic = ["version"]
8
+ description = "One language-agnostic quality gate for staged changes and whole repositories"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ authors = [{ name = "Kevin Veen-Birkenbach", email = "kevin@veen.world" }]
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+ urls = { Homepage = "https://github.com/infinito-nexus/quality" }
15
+
16
+ dependencies = ["PyYAML", "pathspec"]
17
+
18
+ [project.scripts]
19
+ quality = "quality.cli:main"
20
+
21
+ [tool.setuptools]
22
+ packages = ["quality", "quality.adapters", "quality.architecture", "quality.legal", "quality.rules"]
23
+ include-package-data = false
24
+
25
+ [tool.setuptools.package-dir]
26
+ "" = "src"
27
+ "quality.rules" = "rules"
28
+
29
+ [tool.setuptools.package-data]
30
+ "quality.rules" = ["*.yml", "semgrep/*.yml", "ast-grep/*.yml", "ast-grep/*/*.yml"]
31
+
32
+ [tool.setuptools.dynamic]
33
+ version = { attr = "quality.__version__" }
34
+
35
+ [tool.pytest.ini_options]
36
+ addopts = "-p no:cacheprovider -rs"
37
+ pythonpath = ["src"]
38
+ testpaths = ["tests"]
39
+ markers = ["deep: runs the deep tier on the shared test bundle, which `quality db update` fetches"]
@@ -0,0 +1,19 @@
1
+ - id: architecture.layer
2
+ severity: medium
3
+ summary: Import breaks a layer or forbidden import of .quality/architecture.yml
4
+ lens: SRP
5
+ architecture: 25
6
+ enforcer:
7
+ python-contract:
8
+ tool: lint-imports
9
+ files: [.quality/architecture.yml]
10
+ javascript-contract: &depcruise-contract
11
+ tool: depcruise
12
+ files: [.quality/architecture.yml]
13
+ - id: architecture.cycle
14
+ severity: medium
15
+ summary: Modules import each other in a cycle
16
+ lens: SRP
17
+ architecture: 25
18
+ enforcer:
19
+ javascript-contract: *depcruise-contract
@@ -0,0 +1,20 @@
1
+ id: clean.default-value/variable
2
+ language: hcl
3
+ severity: warning
4
+ message: variable default; fail early on the missing input and name where to set it
5
+ rule:
6
+ kind: attribute
7
+ has:
8
+ kind: identifier
9
+ regex: '^default$'
10
+ not:
11
+ has:
12
+ kind: expression
13
+ regex: '^\s*(?:""|''''|``|(?i:false|none|null|nil|undefined)|\[\s*\]|\{\s*\}|\(\s*\))?\s*$'
14
+ inside:
15
+ kind: body
16
+ inside:
17
+ kind: block
18
+ has:
19
+ kind: identifier
20
+ regex: '^variable$'
@@ -0,0 +1,15 @@
1
+ id: coding.structural/duplicate-key
2
+ language: json
3
+ severity: warning
4
+ message: duplicate object key; the later value silently wins
5
+ rule:
6
+ kind: pair
7
+ has:
8
+ field: key
9
+ pattern: $KEY
10
+ follows:
11
+ kind: pair
12
+ has:
13
+ field: key
14
+ pattern: $KEY
15
+ stopBy: end
@@ -0,0 +1,6 @@
1
+ id: coding.structural/search-path
2
+ language: nix
3
+ severity: warning
4
+ message: an angle-bracket path reads NIX_PATH, so the result depends on the host
5
+ rule:
6
+ kind: spath_expression
@@ -0,0 +1,19 @@
1
+ id: coding.structural/duplicate-key
2
+ language: yaml
3
+ severity: warning
4
+ message: duplicate mapping key; the later value silently wins
5
+ rule:
6
+ any:
7
+ - kind: block_mapping_pair
8
+ - kind: flow_pair
9
+ has:
10
+ field: key
11
+ pattern: $KEY
12
+ follows:
13
+ any:
14
+ - kind: block_mapping_pair
15
+ - kind: flow_pair
16
+ has:
17
+ field: key
18
+ pattern: $KEY
19
+ stopBy: end
@@ -0,0 +1,9 @@
1
+ id: coding.structural/gets
2
+ language: c
3
+ severity: warning
4
+ message: gets cannot bound its input and was removed in C11
5
+ rule:
6
+ kind: call_expression
7
+ has:
8
+ field: function
9
+ regex: '^gets$'
@@ -0,0 +1,9 @@
1
+ id: coding.structural/gets
2
+ language: cpp
3
+ severity: warning
4
+ message: gets cannot bound its input and was removed in C++14
5
+ rule:
6
+ kind: call_expression
7
+ has:
8
+ field: function
9
+ regex: '^(?:std::)?gets$'
@@ -0,0 +1,52 @@
1
+ id: clean.default-value/parameter
2
+ language: csharp
3
+ severity: warning
4
+ message: optional parameter; fail early, make it required
5
+ rule:
6
+ kind: parameter
7
+ regex: '='
8
+ not:
9
+ regex: '=\s*(?:""|''''|``|(?i:false|none|null|nil|undefined|string\.empty)|\[\s*\]|\{\s*\}|\(\s*\))\s*$'
10
+ ---
11
+ id: clean.default-value/nullish
12
+ language: csharp
13
+ severity: warning
14
+ message: fallback after ??; fail early, check for null and throw an error that names the missing key and where to set it
15
+ rule:
16
+ any:
17
+ - pattern:
18
+ context: x = $LEFT ?? $RIGHT;
19
+ selector: binary_expression
20
+ - pattern:
21
+ context: $LEFT ??= $RIGHT;
22
+ selector: assignment_expression
23
+ has:
24
+ field: right
25
+ not:
26
+ any:
27
+ - kind: throw_expression
28
+ - regex: '^\s*(?:""|''''|``|(?i:false|none|null|nil|undefined|string\.empty)|\[\s*\]|\{\s*\}|\(\s*\))?\s*$'
29
+ ---
30
+ id: clean.default-value/get-or-default
31
+ language: csharp
32
+ severity: warning
33
+ message: lookup with a fallback; fail early, check for the missing key and throw an error that names the missing key and where to set it
34
+ rule:
35
+ kind: identifier
36
+ regex: '^(?:getOrDefault|GetValueOrDefault)$'
37
+ inside:
38
+ kind: member_access_expression
39
+ field: name
40
+ inside:
41
+ kind: invocation_expression
42
+ field: function
43
+ not:
44
+ has:
45
+ field: arguments
46
+ has:
47
+ regex: '^\s*(?:""|''''|``|(?i:false|none|null|nil|undefined|string\.empty)|\[\s*\]|\{\s*\}|\(\s*\))?\s*$'
48
+ all:
49
+ - nthChild: 2
50
+ - nthChild:
51
+ position: 1
52
+ reverse: true
@@ -0,0 +1,13 @@
1
+ id: coding.structural/defer-in-loop
2
+ language: go
3
+ severity: warning
4
+ message: defer inside a loop runs only when the function returns
5
+ rule:
6
+ kind: defer_statement
7
+ inside:
8
+ kind: for_statement
9
+ stopBy:
10
+ any:
11
+ - kind: function_declaration
12
+ - kind: method_declaration
13
+ - kind: func_literal
@@ -0,0 +1,37 @@
1
+ id: coding.structural/empty-catch
2
+ language: java
3
+ severity: warning
4
+ message: an empty catch block swallows the exception
5
+ rule:
6
+ kind: catch_clause
7
+ has:
8
+ field: body
9
+ regex: '^\{\s*\}$'
10
+ ---
11
+ id: coding.structural/print-stack-trace
12
+ language: java
13
+ severity: warning
14
+ message: printStackTrace bypasses the logger
15
+ rule:
16
+ pattern: $ERROR.printStackTrace()
17
+ ---
18
+ id: clean.default-value/get-or-default
19
+ language: java
20
+ severity: warning
21
+ message: lookup with a fallback; fail early, check for the missing key and throw an error that names the missing key and where to set it
22
+ rule:
23
+ kind: identifier
24
+ regex: '^(?:getOrDefault|GetValueOrDefault)$'
25
+ inside:
26
+ kind: method_invocation
27
+ field: name
28
+ not:
29
+ has:
30
+ field: arguments
31
+ has:
32
+ regex: '^\s*(?:""|''''|``|(?i:false|none|null|nil|undefined)|\[\s*\]|\{\s*\}|\(\s*\))?\s*$'
33
+ all:
34
+ - nthChild: 2
35
+ - nthChild:
36
+ position: 1
37
+ reverse: true
@@ -0,0 +1,7 @@
1
+ id: coding.structural/empty-catch
2
+ language: kotlin
3
+ severity: warning
4
+ message: an empty catch block swallows the exception
5
+ rule:
6
+ kind: catch_block
7
+ regex: '\{\s*\}$'
@@ -0,0 +1,47 @@
1
+ id: coding.structural/placeholder-macro
2
+ language: rust
3
+ severity: warning
4
+ message: todo, unimplemented or dbg macro left in code
5
+ rule:
6
+ kind: macro_invocation
7
+ has:
8
+ field: macro
9
+ regex: '^(?:todo|unimplemented|dbg)$'
10
+ ---
11
+ id: clean.default-value/unwrap-or
12
+ language: rust
13
+ severity: warning
14
+ message: unwrap_or with a value; fail early, return an error that names the missing key and where to set it
15
+ rule:
16
+ kind: field_identifier
17
+ regex: '^unwrap_or(?:_default)?$'
18
+ inside:
19
+ kind: field_expression
20
+ field: field
21
+ inside:
22
+ kind: call_expression
23
+ field: function
24
+ not:
25
+ all:
26
+ - has:
27
+ field: function
28
+ has:
29
+ field: field
30
+ regex: '^unwrap_or$'
31
+ - has:
32
+ field: arguments
33
+ has:
34
+ regex: '^\s*(?:""|''''|``|(?i:false|none|null|nil|undefined|string::new\(\)|vec::new\(\)|vec!\[\])|\[\s*\]|\{\s*\}|\(\s*\))?\s*$'
35
+ all:
36
+ - nthChild: 1
37
+ - nthChild:
38
+ position: 1
39
+ reverse: true
40
+ ---
41
+ id: clean.default-value/serde-default
42
+ language: rust
43
+ severity: warning
44
+ message: serde default; fail early, make the field required and deny unknown fields
45
+ rule:
46
+ kind: attribute_item
47
+ regex: '^#\[serde\([^\]]*\bdefault\b'
@@ -0,0 +1,76 @@
1
+ id: coding.structural/pipe-to-shell
2
+ language: bash
3
+ severity: warning
4
+ message: a downloaded script is piped straight into a shell
5
+ rule:
6
+ kind: pipeline
7
+ all:
8
+ - has:
9
+ kind: command
10
+ has:
11
+ field: name
12
+ regex: '^(?:curl|wget)$'
13
+ - has:
14
+ kind: command
15
+ has:
16
+ field: name
17
+ regex: '^(?:ba|da|z|k)?sh$'
18
+ ---
19
+ id: clean.default-value/expansion
20
+ language: bash
21
+ severity: warning
22
+ message: parameter expansion with a default; fail early with ${NAME:?set NAME in <where it is configured>}
23
+ rule:
24
+ kind: expansion
25
+ regex: '^\$\{(?:[A-Za-z_]\w*|\d+):?[-=]'
26
+ not:
27
+ regex: '^\$\{(?:[A-Za-z_]\w*|\d+):?[-=]\s*(?:""|''''|``|(?i:false|none|null|nil|undefined)|\[\s*\]|\{\s*\}|\(\s*\))?\s*\}$'
28
+ ---
29
+ id: clean.default-value/embedded
30
+ language: bash
31
+ severity: warning
32
+ message: parameter expansion with a default in a script a shell runs; fail early with ${NAME:?set NAME in <where it is configured>}
33
+ rule:
34
+ regex: '\$\{(?:[A-Za-z_]\w*|\d+):?[-=]'
35
+ any:
36
+ - kind: raw_string
37
+ follows:
38
+ kind: word
39
+ regex: '^-[A-Za-z]*c[A-Za-z]*$'
40
+ inside:
41
+ kind: command
42
+ has:
43
+ regex: '^(?:[^=]*/)?(?:(?:ba|da|z|k|a|mk|ya|tc|c|fi)?sh|su|runuser)$'
44
+ not:
45
+ has:
46
+ field: name
47
+ regex: '^(?:[^=]*/)?(?:echo|printf|print|:)$'
48
+ - kind: raw_string
49
+ inside:
50
+ kind: command
51
+ has:
52
+ field: name
53
+ regex: '^(?:eval|trap)$'
54
+ - kind: heredoc_body
55
+ regex: '\A#![ \t]*(?:\S*/)?(?:env[ \t]+(?:-\S+[ \t]+)*)?(?:ba|da|z|k)?sh\s'
56
+ follows:
57
+ kind: heredoc_start
58
+ regex: '[''"\\]'
59
+ metadata:
60
+ rows: '(?m)^(?:[^#\n]|(?<=[^ \t\n])#)*?(?<!\\)\$\{(?:[A-Za-z_]\w*|\d+):?[-=](?!\s*(?:""|''''|``|(?i:false|none|null|nil|undefined)|\[\s*\]|\{\s*\}|\(\s*\))?\s*\})'
61
+ ---
62
+ id: clean.default-value/escaped
63
+ language: bash
64
+ severity: warning
65
+ message: parameter expansion with a default in a script a heredoc writes; fail early with ${NAME:?set NAME in <where it is configured>}
66
+ rule:
67
+ kind: heredoc_body
68
+ all:
69
+ - regex: '\A#![ \t]*(?:\S*/)?(?:env[ \t]+(?:-\S+[ \t]+)*)?(?:ba|da|z|k)?sh\s'
70
+ - regex: '\\\$\{(?:[A-Za-z_]\w*|\d+):?[-=]'
71
+ follows:
72
+ kind: heredoc_start
73
+ not:
74
+ regex: '[''"\\]'
75
+ metadata:
76
+ rows: '(?m)^(?:[^#\n]|(?<=[^ \t\n])#)*?(?<!\\)\\\$\{(?:[A-Za-z_]\w*|\d+):?[-=](?!\s*(?:""|''''|``|(?i:false|none|null|nil|undefined)|\[\s*\]|\{\s*\}|\(\s*\))?\s*\})'
@@ -0,0 +1,6 @@
1
+ id: coding.structural/loadstring
2
+ language: lua
3
+ severity: warning
4
+ message: loadstring was removed in Lua 5.2; use load
5
+ rule:
6
+ pattern: loadstring($$$)
@@ -0,0 +1,8 @@
1
+ id: coding.structural/debug-output
2
+ language: php
3
+ severity: warning
4
+ message: debug dump left in code
5
+ rule:
6
+ any:
7
+ - pattern: var_dump($$$)
8
+ - pattern: var_export($VALUE)