cleargate 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.
- cleargate-0.1.0/.gitignore +20 -0
- cleargate-0.1.0/CHANGELOG.md +31 -0
- cleargate-0.1.0/LICENSE +21 -0
- cleargate-0.1.0/PKG-INFO +329 -0
- cleargate-0.1.0/README.md +291 -0
- cleargate-0.1.0/pyproject.toml +116 -0
- cleargate-0.1.0/src/cleargate/__init__.py +7 -0
- cleargate-0.1.0/src/cleargate/__main__.py +12 -0
- cleargate-0.1.0/src/cleargate/catalogue/SCHEMA.md +35 -0
- cleargate-0.1.0/src/cleargate/catalogue/__init__.py +153 -0
- cleargate-0.1.0/src/cleargate/catalogue/rules/frontend.toml +205 -0
- cleargate-0.1.0/src/cleargate/catalogue/rules/maintainability.toml +686 -0
- cleargate-0.1.0/src/cleargate/catalogue/rules/reliability.toml +163 -0
- cleargate-0.1.0/src/cleargate/catalogue/rules/security.toml +392 -0
- cleargate-0.1.0/src/cleargate/catalogue/rules/shell_docker.toml +62 -0
- cleargate-0.1.0/src/cleargate/cli.py +117 -0
- cleargate-0.1.0/src/cleargate/commands/__init__.py +5 -0
- cleargate-0.1.0/src/cleargate/commands/explain.py +80 -0
- cleargate-0.1.0/src/cleargate/commands/fix.py +269 -0
- cleargate-0.1.0/src/cleargate/commands/gate.py +175 -0
- cleargate-0.1.0/src/cleargate/commands/init_config.py +46 -0
- cleargate-0.1.0/src/cleargate/commands/loc.py +197 -0
- cleargate-0.1.0/src/cleargate/commands/plan.py +335 -0
- cleargate-0.1.0/src/cleargate/commands/pr.py +168 -0
- cleargate-0.1.0/src/cleargate/commands/rules.py +97 -0
- cleargate-0.1.0/src/cleargate/commands/scan.py +79 -0
- cleargate-0.1.0/src/cleargate/config.py +121 -0
- cleargate-0.1.0/src/cleargate/detectors/__init__.py +5 -0
- cleargate-0.1.0/src/cleargate/detectors/base.py +522 -0
- cleargate-0.1.0/src/cleargate/detectors/css.py +198 -0
- cleargate-0.1.0/src/cleargate/detectors/docker.py +176 -0
- cleargate-0.1.0/src/cleargate/detectors/js.py +182 -0
- cleargate-0.1.0/src/cleargate/detectors/python/__init__.py +34 -0
- cleargate-0.1.0/src/cleargate/detectors/python/_common.py +307 -0
- cleargate-0.1.0/src/cleargate/detectors/python/clear_text_http.py +101 -0
- cleargate-0.1.0/src/cleargate/detectors/python/complexity.py +74 -0
- cleargate-0.1.0/src/cleargate/detectors/python/composite_assert.py +176 -0
- cleargate-0.1.0/src/cleargate/detectors/python/duplicate_literal.py +124 -0
- cleargate-0.1.0/src/cleargate/detectors/python/fastapi_status.py +239 -0
- cleargate-0.1.0/src/cleargate/detectors/python/float_equality.py +246 -0
- cleargate-0.1.0/src/cleargate/detectors/python/hardcoded_ip.py +89 -0
- cleargate-0.1.0/src/cleargate/detectors/python/log_injection.py +297 -0
- cleargate-0.1.0/src/cleargate/detectors/python/regex.py +424 -0
- cleargate-0.1.0/src/cleargate/detectors/python/suppression.py +210 -0
- cleargate-0.1.0/src/cleargate/detectors/shell.py +189 -0
- cleargate-0.1.0/src/cleargate/detectors/text/__init__.py +12 -0
- cleargate-0.1.0/src/cleargate/detectors/text/common.py +199 -0
- cleargate-0.1.0/src/cleargate/detectors/text/unicode_tag.py +105 -0
- cleargate-0.1.0/src/cleargate/exit_codes.py +19 -0
- cleargate-0.1.0/src/cleargate/explain/__init__.py +5 -0
- cleargate-0.1.0/src/cleargate/explain/ai.py +150 -0
- cleargate-0.1.0/src/cleargate/explain/offline.py +87 -0
- cleargate-0.1.0/src/cleargate/fixers/__init__.py +5 -0
- cleargate-0.1.0/src/cleargate/gate/__init__.py +5 -0
- cleargate-0.1.0/src/cleargate/gate/newcode.py +87 -0
- cleargate-0.1.0/src/cleargate/gate/publish.py +133 -0
- cleargate-0.1.0/src/cleargate/gate/rating.py +130 -0
- cleargate-0.1.0/src/cleargate/loc/__init__.py +5 -0
- cleargate-0.1.0/src/cleargate/loc/advisor.py +217 -0
- cleargate-0.1.0/src/cleargate/loc/ncloc.py +345 -0
- cleargate-0.1.0/src/cleargate/loc/props.py +181 -0
- cleargate-0.1.0/src/cleargate/loc/sonarglob.py +101 -0
- cleargate-0.1.0/src/cleargate/model.py +132 -0
- cleargate-0.1.0/src/cleargate/pr/__init__.py +5 -0
- cleargate-0.1.0/src/cleargate/pr/annotations.py +89 -0
- cleargate-0.1.0/src/cleargate/pr/github.py +234 -0
- cleargate-0.1.0/src/cleargate/pr/link.py +130 -0
- cleargate-0.1.0/src/cleargate/pr/mapper.py +215 -0
- cleargate-0.1.0/src/cleargate/pr/status.py +89 -0
- cleargate-0.1.0/src/cleargate/py.typed +0 -0
- cleargate-0.1.0/src/cleargate/report/__init__.py +43 -0
- cleargate-0.1.0/src/cleargate/report/json_report.py +38 -0
- cleargate-0.1.0/src/cleargate/report/markdown.py +90 -0
- cleargate-0.1.0/src/cleargate/report/sarif.py +193 -0
- cleargate-0.1.0/src/cleargate/report/text.py +45 -0
- cleargate-0.1.0/src/cleargate/ruffcfg.py +63 -0
- cleargate-0.1.0/src/cleargate/rule_ids.py +90 -0
- cleargate-0.1.0/tests/data/annotations.json +5 -0
- cleargate-0.1.0/tests/data/check_runs.json +5 -0
- cleargate-0.1.0/tests/data/check_runs_rejected.json +3 -0
- cleargate-0.1.0/tests/data/pr_head.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-BASH-TEST/bad.sh +7 -0
- cleargate-0.1.0/tests/fixtures/CG-BASH-TEST/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-BASH-TEST/fix_after.sh +5 -0
- cleargate-0.1.0/tests/fixtures/CG-BASH-TEST/fix_before.sh +5 -0
- cleargate-0.1.0/tests/fixtures/CG-BASH-TEST/good.sh +6 -0
- cleargate-0.1.0/tests/fixtures/CG-CSS-DUP-SELECTOR/bad.css +12 -0
- cleargate-0.1.0/tests/fixtures/CG-CSS-DUP-SELECTOR/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-CSS-DUP-SELECTOR/good.css +8 -0
- cleargate-0.1.0/tests/fixtures/CG-CSS-WORD-BREAK/bad.css +5 -0
- cleargate-0.1.0/tests/fixtures/CG-CSS-WORD-BREAK/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-CSS-WORD-BREAK/fix_after.css +2 -0
- cleargate-0.1.0/tests/fixtures/CG-CSS-WORD-BREAK/fix_before.css +2 -0
- cleargate-0.1.0/tests/fixtures/CG-CSS-WORD-BREAK/good.css +2 -0
- cleargate-0.1.0/tests/fixtures/CG-DOCKER-RUN-MERGE/bad.dockerfile +9 -0
- cleargate-0.1.0/tests/fixtures/CG-DOCKER-RUN-MERGE/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-DOCKER-RUN-MERGE/good.dockerfile +6 -0
- cleargate-0.1.0/tests/fixtures/CG-JS-NUMBER-GLOBALS/bad.js +6 -0
- cleargate-0.1.0/tests/fixtures/CG-JS-NUMBER-GLOBALS/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-JS-NUMBER-GLOBALS/fix_after.js +2 -0
- cleargate-0.1.0/tests/fixtures/CG-JS-NUMBER-GLOBALS/fix_before.js +2 -0
- cleargate-0.1.0/tests/fixtures/CG-JS-NUMBER-GLOBALS/good.js +4 -0
- cleargate-0.1.0/tests/fixtures/CG-JS-VAR/bad.js +7 -0
- cleargate-0.1.0/tests/fixtures/CG-JS-VAR/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-JS-VAR/fix_after.js +5 -0
- cleargate-0.1.0/tests/fixtures/CG-JS-VAR/fix_before.js +5 -0
- cleargate-0.1.0/tests/fixtures/CG-JS-VAR/good.js +4 -0
- cleargate-0.1.0/tests/fixtures/CG-PT018/bad.py +8 -0
- cleargate-0.1.0/tests/fixtures/CG-PT018/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-PT018/fix_after.py +11 -0
- cleargate-0.1.0/tests/fixtures/CG-PT018/fix_before.py +9 -0
- cleargate-0.1.0/tests/fixtures/CG-PT018/good.py +8 -0
- cleargate-0.1.0/tests/fixtures/CG-S1192/bad.py +15 -0
- cleargate-0.1.0/tests/fixtures/CG-S1192/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-S1192/good.py +15 -0
- cleargate-0.1.0/tests/fixtures/CG-S1244/bad.py +11 -0
- cleargate-0.1.0/tests/fixtures/CG-S1244/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-S1244/fix_after.py +10 -0
- cleargate-0.1.0/tests/fixtures/CG-S1244/fix_before.py +9 -0
- cleargate-0.1.0/tests/fixtures/CG-S1244/good.py +13 -0
- cleargate-0.1.0/tests/fixtures/CG-S1313/bad.py +6 -0
- cleargate-0.1.0/tests/fixtures/CG-S1313/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-S1313/good.py +9 -0
- cleargate-0.1.0/tests/fixtures/CG-S3776/bad.py +18 -0
- cleargate-0.1.0/tests/fixtures/CG-S3776/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-S3776/good.py +9 -0
- cleargate-0.1.0/tests/fixtures/CG-S5145/bad.py +23 -0
- cleargate-0.1.0/tests/fixtures/CG-S5145/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-S5145/good.py +25 -0
- cleargate-0.1.0/tests/fixtures/CG-S5332/bad.py +6 -0
- cleargate-0.1.0/tests/fixtures/CG-S5332/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-S5332/good.py +6 -0
- cleargate-0.1.0/tests/fixtures/CG-S5852/bad.py +7 -0
- cleargate-0.1.0/tests/fixtures/CG-S5852/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-S5852/good.py +7 -0
- cleargate-0.1.0/tests/fixtures/CG-S6019/bad.py +5 -0
- cleargate-0.1.0/tests/fixtures/CG-S6019/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-S6019/good.py +5 -0
- cleargate-0.1.0/tests/fixtures/CG-S6352/bad.py +22 -0
- cleargate-0.1.0/tests/fixtures/CG-S6352/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-S6352/good.py +23 -0
- cleargate-0.1.0/tests/fixtures/CG-S6505/bad.dockerfile +6 -0
- cleargate-0.1.0/tests/fixtures/CG-S6505/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-S6505/fix_after.dockerfile +2 -0
- cleargate-0.1.0/tests/fixtures/CG-S6505/fix_before.dockerfile +2 -0
- cleargate-0.1.0/tests/fixtures/CG-S6505/good.dockerfile +4 -0
- cleargate-0.1.0/tests/fixtures/CG-SUPPRESSION/bad.py +7 -0
- cleargate-0.1.0/tests/fixtures/CG-SUPPRESSION/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-SUPPRESSION/fix_after.py +7 -0
- cleargate-0.1.0/tests/fixtures/CG-SUPPRESSION/fix_before.py +7 -0
- cleargate-0.1.0/tests/fixtures/CG-SUPPRESSION/good.py +7 -0
- cleargate-0.1.0/tests/fixtures/CG-UNICODE-TAG/bad.txt +4 -0
- cleargate-0.1.0/tests/fixtures/CG-UNICODE-TAG/expected.json +1 -0
- cleargate-0.1.0/tests/fixtures/CG-UNICODE-TAG/fix_after.txt +2 -0
- cleargate-0.1.0/tests/fixtures/CG-UNICODE-TAG/fix_before.txt +2 -0
- cleargate-0.1.0/tests/fixtures/CG-UNICODE-TAG/good.txt +2 -0
- cleargate-0.1.0/tests/fixtures/README.md +21 -0
- cleargate-0.1.0/tests/test_base.py +111 -0
- cleargate-0.1.0/tests/test_catalogue_content.py +103 -0
- cleargate-0.1.0/tests/test_catalogue_schema.py +70 -0
- cleargate-0.1.0/tests/test_cli.py +49 -0
- cleargate-0.1.0/tests/test_cli_catalogue.py +91 -0
- cleargate-0.1.0/tests/test_explain.py +207 -0
- cleargate-0.1.0/tests/test_fixtures_meta.py +53 -0
- cleargate-0.1.0/tests/test_gate_core.py +334 -0
- cleargate-0.1.0/tests/test_integration.py +231 -0
- cleargate-0.1.0/tests/test_leak.py +121 -0
- cleargate-0.1.0/tests/test_loc_command.py +108 -0
- cleargate-0.1.0/tests/test_loc_ncloc.py +105 -0
- cleargate-0.1.0/tests/test_model.py +60 -0
- cleargate-0.1.0/tests/test_nonpython_fixtures.py +136 -0
- cleargate-0.1.0/tests/test_nonpython_rules.py +137 -0
- cleargate-0.1.0/tests/test_pr_github.py +121 -0
- cleargate-0.1.0/tests/test_pr_mapper.py +256 -0
- cleargate-0.1.0/tests/test_pr_status.py +64 -0
- cleargate-0.1.0/tests/test_python_detectors.py +204 -0
- cleargate-0.1.0/tests/test_python_fixers.py +101 -0
- cleargate-0.1.0/tests/test_python_perf.py +70 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Git ignore rules for cleargate.
|
|
2
|
+
# Author: Pandiyaraj Karuppasamy
|
|
3
|
+
# Date: Nov-23-2026
|
|
4
|
+
__pycache__/
|
|
5
|
+
*.py[cod]
|
|
6
|
+
.venv/
|
|
7
|
+
venv/
|
|
8
|
+
build/
|
|
9
|
+
dist/
|
|
10
|
+
*.egg-info/
|
|
11
|
+
.pytest_cache/
|
|
12
|
+
.mypy_cache/
|
|
13
|
+
.ruff_cache/
|
|
14
|
+
.coverage
|
|
15
|
+
htmlcov/
|
|
16
|
+
*.sarif
|
|
17
|
+
plan.md
|
|
18
|
+
# Untracked denylists used by the leak check (tests/test_leak.py).
|
|
19
|
+
.leak-denylist.txt
|
|
20
|
+
.leakdeny
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!-- cleargate changelog. Author: Pandiyaraj Karuppasamy | Date: Nov-23-2026 | Modified: Nov-23-2026 -->
|
|
2
|
+
# Changelog
|
|
3
|
+
|
|
4
|
+
## 0.1.0 (unreleased)
|
|
5
|
+
|
|
6
|
+
First release.
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- `cleargate scan`: SonarCloud-style detectors for Python (log injection,
|
|
11
|
+
clear-text HTTP, hard-coded IPs, float equality, cognitive complexity,
|
|
12
|
+
duplicated literals, regex backtracking, undocumented FastAPI status codes,
|
|
13
|
+
composite asserts, suppression comments), hidden Unicode tag characters,
|
|
14
|
+
shell, Dockerfiles, CSS and JavaScript. Text, JSON, Markdown and SARIF 2.1.0
|
|
15
|
+
output; `# cleargate: ignore[...]` suppressions.
|
|
16
|
+
- `cleargate fix`: safe fixers shown as a diff (default) or applied with
|
|
17
|
+
`--apply`; behaviour-changing fixers only with `--unsafe`.
|
|
18
|
+
- `cleargate explain` and `cleargate rules`: a catalogue of 54 rules with why,
|
|
19
|
+
bad and good examples and the fix, offline or with Claude (`--ai`).
|
|
20
|
+
- `cleargate plan`: a Markdown fix plan ordered by category, severity and rule
|
|
21
|
+
size, optionally merged with a pull request's findings and Claude's advice.
|
|
22
|
+
- `cleargate pr`: reads a pull request's SonarCloud annotations, maps them to
|
|
23
|
+
rules, links them to local detections and diagnoses a rejected scan (exit 3).
|
|
24
|
+
- `cleargate loc`: lines-of-code estimate from `sonar-project.properties`,
|
|
25
|
+
with the changes that free lines (undeclared test folders, generated code).
|
|
26
|
+
- `cleargate gate`: a fallback gate on new code with SonarCloud-style ratings,
|
|
27
|
+
published as a GitHub check run, and `--auto` to run only when SonarCloud
|
|
28
|
+
refused the scan.
|
|
29
|
+
- `cleargate init-config`: recommended ruff and `sonar-project.properties`
|
|
30
|
+
settings.
|
|
31
|
+
- `[tool.cleargate]` configuration in `pyproject.toml`.
|
cleargate-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pandiyaraj Karuppasamy
|
|
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.
|
cleargate-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cleargate
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Find, explain, fix and plan SonarCloud-style issues locally, read PR findings, and keep a quality gate when the cloud scan is refused.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Pandiyarajk/cleargate
|
|
6
|
+
Project-URL: Repository, https://github.com/Pandiyarajk/cleargate
|
|
7
|
+
Project-URL: Issues, https://github.com/Pandiyarajk/cleargate/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Pandiyarajk/cleargate/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Pandiyaraj Karuppasamy
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: autofix,code-quality,github-actions,lint,linter,quality-gate,sarif,sonarcloud,sonarqube,static-analysis
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Classifier: Topic :: Software Development :: Testing
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Requires-Dist: cognitive-complexity>=1.3
|
|
26
|
+
Provides-Extra: ai
|
|
27
|
+
Requires-Dist: anthropic>=0.40; extra == 'ai'
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: black>=24.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
32
|
+
Requires-Dist: pylint>=3.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-timeout>=2.3; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
36
|
+
Requires-Dist: twine>=4.0; extra == 'dev'
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
<!-- cleargate README. Author: Pandiyaraj Karuppasamy | Date: Nov-23-2026 | Modified: Nov-23-2026 -->
|
|
40
|
+
# cleargate
|
|
41
|
+
|
|
42
|
+
Find, explain and fix SonarCloud-style issues on your own machine, before you
|
|
43
|
+
push. cleargate also reads a pull request's real SonarCloud findings, writes a
|
|
44
|
+
prioritised fix plan, estimates your lines of code against a plan limit, and
|
|
45
|
+
keeps a quality gate running when SonarCloud refuses to scan a pull request
|
|
46
|
+
(for example when an organisation is over its lines-of-code limit).
|
|
47
|
+
|
|
48
|
+
- **scan**: SonarCloud-style rules for Python, shell, Dockerfiles, CSS and
|
|
49
|
+
JavaScript, with file, line, column and the offending code.
|
|
50
|
+
- **explain**: why a rule matters and how to fix it, offline, or with Claude
|
|
51
|
+
(`--ai`).
|
|
52
|
+
- **fix**: safe automatic fixes, shown as a diff or applied.
|
|
53
|
+
- **plan**: a Markdown fix plan, most important rules first.
|
|
54
|
+
- **pr**: a pull request's SonarCloud findings, mapped to rules and explained.
|
|
55
|
+
- **loc**: a lines-of-code estimate and the configuration changes that free
|
|
56
|
+
lines.
|
|
57
|
+
- **gate**: a fallback quality gate on new code, published as a GitHub check.
|
|
58
|
+
|
|
59
|
+
cleargate is not affiliated with, endorsed by or connected to SonarSource.
|
|
60
|
+
SonarCloud and SonarQube are trademarks of SonarSource SA. Rule keys such as
|
|
61
|
+
`python:S1244` are used only to point at the matching public rule.
|
|
62
|
+
|
|
63
|
+
## Install
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install cleargate # core
|
|
67
|
+
pip install "cleargate[ai]" # adds optional Claude explanations and plans
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Requires Python 3.11 or newer. `pr` and `gate --publish` use the GitHub CLI
|
|
71
|
+
(`gh`), logged in or with `GH_TOKEN` set. `--ai` needs `ANTHROPIC_API_KEY`;
|
|
72
|
+
without it cleargate prints one warning and uses the offline text.
|
|
73
|
+
|
|
74
|
+
## Quickstart
|
|
75
|
+
|
|
76
|
+
### scan
|
|
77
|
+
|
|
78
|
+
```console
|
|
79
|
+
$ cleargate scan .
|
|
80
|
+
app/main.py:6:10: CG-S1313 Hard-coded IP address 192.0.2.10; read it from configuration.
|
|
81
|
+
SERVER = "192.0.2.10"
|
|
82
|
+
app/main.py:11:5: CG-S5145 Log call writes request-derived data (name); log a length, count or flag instead.
|
|
83
|
+
log.info("reading %s", name)
|
|
84
|
+
tests/test_ratio.py:2:12: CG-S1244 Equality test on a float literal; compare with a tolerance (pytest.approx or math.isclose). [fixable]
|
|
85
|
+
assert 1 / 4 == 0.25
|
|
86
|
+
|
|
87
|
+
3 issues found.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`--format text|json|sarif|md` picks the output; SARIF 2.1.0 carries rule
|
|
91
|
+
metadata and fingerprints for code-scanning tools. `--fail-on` sets the lowest
|
|
92
|
+
severity that makes the exit code 1. Silence one line with
|
|
93
|
+
`# cleargate: ignore[CG-S1313]`.
|
|
94
|
+
|
|
95
|
+
### explain
|
|
96
|
+
|
|
97
|
+
```console
|
|
98
|
+
$ cleargate explain S1244
|
|
99
|
+
CG-S1244: Floating point numbers should not be tested for equality
|
|
100
|
+
Severity: major Category: reliability
|
|
101
|
+
|
|
102
|
+
Why it matters:
|
|
103
|
+
Floating point arithmetic rounds, so 0.1 + 0.2 is not exactly 0.3 and an exact
|
|
104
|
+
comparison can fail on one machine and pass on another. ...
|
|
105
|
+
|
|
106
|
+
Noncompliant:
|
|
107
|
+
assert score == 0.2
|
|
108
|
+
|
|
109
|
+
Compliant:
|
|
110
|
+
assert score == pytest.approx(0.2)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The rule can be given as `CG-S1244`, `S1244` or `python:S1244`. Add `--ai` for
|
|
114
|
+
an explanation from Claude; only the rule text and a short snippet are sent.
|
|
115
|
+
|
|
116
|
+
### fix
|
|
117
|
+
|
|
118
|
+
```console
|
|
119
|
+
$ cleargate fix .
|
|
120
|
+
--- a/tests/test_ratio.py
|
|
121
|
+
+++ b/tests/test_ratio.py
|
|
122
|
+
@@ -1,2 +1,3 @@
|
|
123
|
+
+import pytest
|
|
124
|
+
def test_ratio():
|
|
125
|
+
- assert 1 / 4 == 0.25
|
|
126
|
+
+ assert 1 / 4 == pytest.approx(0.25)
|
|
127
|
+
1 finding(s) in 1 file(s) can be fixed.
|
|
128
|
+
|
|
129
|
+
$ cleargate fix . --apply
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`--diff` is the default and changes nothing. `--apply` writes a file only when
|
|
133
|
+
every fix for it succeeded and, for Python, the result still parses.
|
|
134
|
+
`--rule ID` limits the fixers. Fixers that can change behaviour (JavaScript
|
|
135
|
+
`var`, the Dockerfile pip flag) run only with `--unsafe`.
|
|
136
|
+
|
|
137
|
+
### plan
|
|
138
|
+
|
|
139
|
+
```console
|
|
140
|
+
$ cleargate plan . -o plan.md
|
|
141
|
+
$ head plan.md
|
|
142
|
+
# cleargate fix plan
|
|
143
|
+
|
|
144
|
+
3 finding(s) across 3 rule(s); 1 can be fixed automatically.
|
|
145
|
+
|
|
146
|
+
## Security
|
|
147
|
+
|
|
148
|
+
### 1. CG-S1313: Using hardcoded IP addresses is security-sensitive (minor, 1 finding)
|
|
149
|
+
|
|
150
|
+
Why: An IP address in code ties the program to one network, leaks internal topology ...
|
|
151
|
+
Fix: Read real hosts from configuration.
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Security comes first, then reliability, then maintainability; within each,
|
|
155
|
+
the most severe rules, and among those the rules with the most findings. Each
|
|
156
|
+
rule lists its files and lines, and the `cleargate fix --rule` command when it
|
|
157
|
+
can be fixed automatically. `--from-pr owner/repo#123` merges that pull
|
|
158
|
+
request's SonarCloud findings into the plan; `--ai` appends Claude's suggested
|
|
159
|
+
approach. `-o -` prints to stdout.
|
|
160
|
+
|
|
161
|
+
### pr
|
|
162
|
+
|
|
163
|
+
```console
|
|
164
|
+
$ cleargate pr owner/repo 123
|
|
165
|
+
1a2b3c4 issues Quality Gate failed
|
|
166
|
+
app/main.py:11:5: CG-S5145 (Logging should not be vulnerable to injection attacks)
|
|
167
|
+
Change this code to not log user-controlled data.
|
|
168
|
+
> log.info("reading %s", name)
|
|
169
|
+
|
|
170
|
+
1 finding(s), 1 also found by a local scan
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Each annotation from the SonarCloud check run is mapped to a catalogue rule
|
|
174
|
+
(by rule key, phrase or wording); findings that match nothing are reported as
|
|
175
|
+
`CG-UNKNOWN`. When the same rule fires locally on the same line, the finding
|
|
176
|
+
gets the local column and fixable flag. `--sha` reads another commit and
|
|
177
|
+
`--root` points at the checkout used for snippets.
|
|
178
|
+
|
|
179
|
+
When SonarCloud cancelled the analysis or reported "analysis failed" with no
|
|
180
|
+
annotations, `pr` prints `sonar-rejected`, the likely cause (such as the
|
|
181
|
+
organisation's line limit) and the fixes, and exits 3.
|
|
182
|
+
|
|
183
|
+
### loc
|
|
184
|
+
|
|
185
|
+
```console
|
|
186
|
+
$ cleargate loc . --limit 100000
|
|
187
|
+
Estimated ncloc (sonar.sources minus sonar.tests and exclusions):
|
|
188
|
+
python 92,400
|
|
189
|
+
TOTAL 92,400
|
|
190
|
+
limit 100,000 (92.4% used, headroom 7,600)
|
|
191
|
+
|
|
192
|
+
Suggestions:
|
|
193
|
+
undeclared-tests: app/tests saves 9,260 lines (41 files)
|
|
194
|
+
sonar.tests += app/tests; sonar.exclusions += app/tests/**
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The estimate follows `sonar-project.properties` (`sonar.sources`,
|
|
198
|
+
`sonar.tests`, `sonar.exclusions`). It finds test folders that sit under
|
|
199
|
+
`sonar.sources` but are not declared as tests, and generated or vendored code.
|
|
200
|
+
`--ref` counts a git ref instead of the working tree; `--write` applies the
|
|
201
|
+
suggested properties change.
|
|
202
|
+
|
|
203
|
+
### gate
|
|
204
|
+
|
|
205
|
+
```console
|
|
206
|
+
$ cleargate gate --base origin/main
|
|
207
|
+
a.py:4:12: CG-S1244 Equality test on a float literal; compare with a tolerance (pytest.approx or math.isclose).
|
|
208
|
+
assert 1 / 4 == 0.25
|
|
209
|
+
a.py:5:10: CG-S1313 Hard-coded IP address 192.0.2.1; read it from configuration.
|
|
210
|
+
SERVER = "192.0.2.1"
|
|
211
|
+
|
|
212
|
+
2 issues found.
|
|
213
|
+
|
|
214
|
+
Gate failed: Security B, Reliability C, Maintainability A (fails at B)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The fallback gate scans only the lines your branch changes, rates them the way
|
|
218
|
+
SonarCloud rates new code (one major bug gives Reliability C, one minor
|
|
219
|
+
vulnerability gives Security B) and fails at `--fail-on` (default B).
|
|
220
|
+
`--publish` posts the result as a GitHub check run named "cleargate gate" with
|
|
221
|
+
one annotation per finding; `--sarif` writes a SARIF file. `--auto` runs only
|
|
222
|
+
when the SonarCloud check on the pull request was rejected.
|
|
223
|
+
|
|
224
|
+
### rules and init-config
|
|
225
|
+
|
|
226
|
+
`cleargate rules` lists the catalogue (`--category`, `--language`,
|
|
227
|
+
`--search`). `cleargate init-config --ruff` prints a ruff `extend-select` that
|
|
228
|
+
catches several of these rules in the editor, and `--sonar` prints a
|
|
229
|
+
`sonar-project.properties` with a separate `sonar.tests` scope.
|
|
230
|
+
|
|
231
|
+
## Rules
|
|
232
|
+
|
|
233
|
+
`cleargate rules` lists 54 rules. The ones marked "local" have a detector:
|
|
234
|
+
|
|
235
|
+
| Area | Detected locally |
|
|
236
|
+
|---|---|
|
|
237
|
+
| Security | log injection (S5145), clear-text HTTP (S5332), hard-coded IPs (S1313), hidden Unicode tag characters, `pip install` running setup scripts (S6505) |
|
|
238
|
+
| Reliability | float equality (S1244) |
|
|
239
|
+
| Maintainability | cognitive complexity (S3776), duplicated literals (S1192), regex backtracking (S5852, S6019), undocumented FastAPI status codes (S6352), composite asserts, malformed suppression comments |
|
|
240
|
+
| Shell, Docker | `[` instead of `[[` in bash, consecutive `RUN` steps |
|
|
241
|
+
| CSS, JavaScript | duplicated selectors, `word-break: break-word`, `var`, global `parseInt`/`isNaN` |
|
|
242
|
+
|
|
243
|
+
The other rules are catalogue entries: `explain`, `plan` and `pr` use them to
|
|
244
|
+
explain findings that SonarCloud reports but cleargate does not detect itself.
|
|
245
|
+
|
|
246
|
+
## Configuration
|
|
247
|
+
|
|
248
|
+
Settings live in `pyproject.toml`:
|
|
249
|
+
|
|
250
|
+
```toml
|
|
251
|
+
[tool.cleargate]
|
|
252
|
+
select = [] # only these rule ids (empty: all)
|
|
253
|
+
ignore = ["CG-S3776"] # never report these
|
|
254
|
+
exclude = ["migrations/**"] # paths to skip
|
|
255
|
+
fail_on = "major" # scan: lowest failing severity
|
|
256
|
+
duplicate_literal_min = 3 # S1192: uses before a literal is reported
|
|
257
|
+
duplicate_literal_in_tests = false # S1192: also check test files
|
|
258
|
+
complexity_max = 15 # S3776 threshold
|
|
259
|
+
allowed_hosts = ["localhost"] # S5332: hosts allowed over http
|
|
260
|
+
allowed_ips = [] # S1313: added to 127.0.0.1, ::1, 0.0.0.0, ::
|
|
261
|
+
loc_limit = 100000 # default --limit for loc
|
|
262
|
+
sonar_check_name = "SonarCloud Code Analysis"
|
|
263
|
+
ai_model = "claude-sonnet-5-5"
|
|
264
|
+
ai_max_tokens = 800
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Exit codes
|
|
268
|
+
|
|
269
|
+
| Code | Meaning |
|
|
270
|
+
|---|---|
|
|
271
|
+
| 0 | clean, the gate passed, or nothing to fix |
|
|
272
|
+
| 1 | findings at or above the fail level, a failed gate, or fixes available (`fix --diff`) |
|
|
273
|
+
| 2 | a usage or environment problem (bad option, `gh` missing, unknown rule) |
|
|
274
|
+
| 3 | SonarCloud rejected the pull request's scan |
|
|
275
|
+
|
|
276
|
+
## GitHub Actions
|
|
277
|
+
|
|
278
|
+
Run the fallback gate next to the SonarCloud check. With `--auto` it does
|
|
279
|
+
nothing while SonarCloud is scanning normally, and takes over when the scan is
|
|
280
|
+
rejected:
|
|
281
|
+
|
|
282
|
+
```yaml
|
|
283
|
+
name: cleargate
|
|
284
|
+
on:
|
|
285
|
+
pull_request:
|
|
286
|
+
|
|
287
|
+
permissions:
|
|
288
|
+
checks: write
|
|
289
|
+
contents: read
|
|
290
|
+
|
|
291
|
+
jobs:
|
|
292
|
+
gate:
|
|
293
|
+
runs-on: ubuntu-latest
|
|
294
|
+
steps:
|
|
295
|
+
- uses: actions/checkout@v4
|
|
296
|
+
with:
|
|
297
|
+
fetch-depth: 0
|
|
298
|
+
- uses: actions/setup-python@v5
|
|
299
|
+
with:
|
|
300
|
+
python-version: "3.12"
|
|
301
|
+
- run: pip install cleargate
|
|
302
|
+
- name: Fallback quality gate
|
|
303
|
+
env:
|
|
304
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
305
|
+
run: >
|
|
306
|
+
cleargate gate --auto --publish
|
|
307
|
+
--repo ${{ github.repository }}
|
|
308
|
+
--pr ${{ github.event.pull_request.number }}
|
|
309
|
+
--base origin/${{ github.base_ref }}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
`--auto` reads the SonarCloud check on the pull request head, so run this job
|
|
313
|
+
after that check has finished (for example in a later job, or on a
|
|
314
|
+
`check_run: completed` trigger) if the two race.
|
|
315
|
+
|
|
316
|
+
## Development
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
python -m venv .venv && . .venv/bin/activate
|
|
320
|
+
pip install -e ".[dev,ai]"
|
|
321
|
+
pytest
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
`scripts/release_gate.ps1` runs the dash check, ruff, black, pylint, mypy, the
|
|
325
|
+
tests, the build and `twine check`.
|
|
326
|
+
|
|
327
|
+
## License
|
|
328
|
+
|
|
329
|
+
MIT
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
<!-- cleargate README. Author: Pandiyaraj Karuppasamy | Date: Nov-23-2026 | Modified: Nov-23-2026 -->
|
|
2
|
+
# cleargate
|
|
3
|
+
|
|
4
|
+
Find, explain and fix SonarCloud-style issues on your own machine, before you
|
|
5
|
+
push. cleargate also reads a pull request's real SonarCloud findings, writes a
|
|
6
|
+
prioritised fix plan, estimates your lines of code against a plan limit, and
|
|
7
|
+
keeps a quality gate running when SonarCloud refuses to scan a pull request
|
|
8
|
+
(for example when an organisation is over its lines-of-code limit).
|
|
9
|
+
|
|
10
|
+
- **scan**: SonarCloud-style rules for Python, shell, Dockerfiles, CSS and
|
|
11
|
+
JavaScript, with file, line, column and the offending code.
|
|
12
|
+
- **explain**: why a rule matters and how to fix it, offline, or with Claude
|
|
13
|
+
(`--ai`).
|
|
14
|
+
- **fix**: safe automatic fixes, shown as a diff or applied.
|
|
15
|
+
- **plan**: a Markdown fix plan, most important rules first.
|
|
16
|
+
- **pr**: a pull request's SonarCloud findings, mapped to rules and explained.
|
|
17
|
+
- **loc**: a lines-of-code estimate and the configuration changes that free
|
|
18
|
+
lines.
|
|
19
|
+
- **gate**: a fallback quality gate on new code, published as a GitHub check.
|
|
20
|
+
|
|
21
|
+
cleargate is not affiliated with, endorsed by or connected to SonarSource.
|
|
22
|
+
SonarCloud and SonarQube are trademarks of SonarSource SA. Rule keys such as
|
|
23
|
+
`python:S1244` are used only to point at the matching public rule.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install cleargate # core
|
|
29
|
+
pip install "cleargate[ai]" # adds optional Claude explanations and plans
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Requires Python 3.11 or newer. `pr` and `gate --publish` use the GitHub CLI
|
|
33
|
+
(`gh`), logged in or with `GH_TOKEN` set. `--ai` needs `ANTHROPIC_API_KEY`;
|
|
34
|
+
without it cleargate prints one warning and uses the offline text.
|
|
35
|
+
|
|
36
|
+
## Quickstart
|
|
37
|
+
|
|
38
|
+
### scan
|
|
39
|
+
|
|
40
|
+
```console
|
|
41
|
+
$ cleargate scan .
|
|
42
|
+
app/main.py:6:10: CG-S1313 Hard-coded IP address 192.0.2.10; read it from configuration.
|
|
43
|
+
SERVER = "192.0.2.10"
|
|
44
|
+
app/main.py:11:5: CG-S5145 Log call writes request-derived data (name); log a length, count or flag instead.
|
|
45
|
+
log.info("reading %s", name)
|
|
46
|
+
tests/test_ratio.py:2:12: CG-S1244 Equality test on a float literal; compare with a tolerance (pytest.approx or math.isclose). [fixable]
|
|
47
|
+
assert 1 / 4 == 0.25
|
|
48
|
+
|
|
49
|
+
3 issues found.
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`--format text|json|sarif|md` picks the output; SARIF 2.1.0 carries rule
|
|
53
|
+
metadata and fingerprints for code-scanning tools. `--fail-on` sets the lowest
|
|
54
|
+
severity that makes the exit code 1. Silence one line with
|
|
55
|
+
`# cleargate: ignore[CG-S1313]`.
|
|
56
|
+
|
|
57
|
+
### explain
|
|
58
|
+
|
|
59
|
+
```console
|
|
60
|
+
$ cleargate explain S1244
|
|
61
|
+
CG-S1244: Floating point numbers should not be tested for equality
|
|
62
|
+
Severity: major Category: reliability
|
|
63
|
+
|
|
64
|
+
Why it matters:
|
|
65
|
+
Floating point arithmetic rounds, so 0.1 + 0.2 is not exactly 0.3 and an exact
|
|
66
|
+
comparison can fail on one machine and pass on another. ...
|
|
67
|
+
|
|
68
|
+
Noncompliant:
|
|
69
|
+
assert score == 0.2
|
|
70
|
+
|
|
71
|
+
Compliant:
|
|
72
|
+
assert score == pytest.approx(0.2)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The rule can be given as `CG-S1244`, `S1244` or `python:S1244`. Add `--ai` for
|
|
76
|
+
an explanation from Claude; only the rule text and a short snippet are sent.
|
|
77
|
+
|
|
78
|
+
### fix
|
|
79
|
+
|
|
80
|
+
```console
|
|
81
|
+
$ cleargate fix .
|
|
82
|
+
--- a/tests/test_ratio.py
|
|
83
|
+
+++ b/tests/test_ratio.py
|
|
84
|
+
@@ -1,2 +1,3 @@
|
|
85
|
+
+import pytest
|
|
86
|
+
def test_ratio():
|
|
87
|
+
- assert 1 / 4 == 0.25
|
|
88
|
+
+ assert 1 / 4 == pytest.approx(0.25)
|
|
89
|
+
1 finding(s) in 1 file(s) can be fixed.
|
|
90
|
+
|
|
91
|
+
$ cleargate fix . --apply
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`--diff` is the default and changes nothing. `--apply` writes a file only when
|
|
95
|
+
every fix for it succeeded and, for Python, the result still parses.
|
|
96
|
+
`--rule ID` limits the fixers. Fixers that can change behaviour (JavaScript
|
|
97
|
+
`var`, the Dockerfile pip flag) run only with `--unsafe`.
|
|
98
|
+
|
|
99
|
+
### plan
|
|
100
|
+
|
|
101
|
+
```console
|
|
102
|
+
$ cleargate plan . -o plan.md
|
|
103
|
+
$ head plan.md
|
|
104
|
+
# cleargate fix plan
|
|
105
|
+
|
|
106
|
+
3 finding(s) across 3 rule(s); 1 can be fixed automatically.
|
|
107
|
+
|
|
108
|
+
## Security
|
|
109
|
+
|
|
110
|
+
### 1. CG-S1313: Using hardcoded IP addresses is security-sensitive (minor, 1 finding)
|
|
111
|
+
|
|
112
|
+
Why: An IP address in code ties the program to one network, leaks internal topology ...
|
|
113
|
+
Fix: Read real hosts from configuration.
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Security comes first, then reliability, then maintainability; within each,
|
|
117
|
+
the most severe rules, and among those the rules with the most findings. Each
|
|
118
|
+
rule lists its files and lines, and the `cleargate fix --rule` command when it
|
|
119
|
+
can be fixed automatically. `--from-pr owner/repo#123` merges that pull
|
|
120
|
+
request's SonarCloud findings into the plan; `--ai` appends Claude's suggested
|
|
121
|
+
approach. `-o -` prints to stdout.
|
|
122
|
+
|
|
123
|
+
### pr
|
|
124
|
+
|
|
125
|
+
```console
|
|
126
|
+
$ cleargate pr owner/repo 123
|
|
127
|
+
1a2b3c4 issues Quality Gate failed
|
|
128
|
+
app/main.py:11:5: CG-S5145 (Logging should not be vulnerable to injection attacks)
|
|
129
|
+
Change this code to not log user-controlled data.
|
|
130
|
+
> log.info("reading %s", name)
|
|
131
|
+
|
|
132
|
+
1 finding(s), 1 also found by a local scan
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Each annotation from the SonarCloud check run is mapped to a catalogue rule
|
|
136
|
+
(by rule key, phrase or wording); findings that match nothing are reported as
|
|
137
|
+
`CG-UNKNOWN`. When the same rule fires locally on the same line, the finding
|
|
138
|
+
gets the local column and fixable flag. `--sha` reads another commit and
|
|
139
|
+
`--root` points at the checkout used for snippets.
|
|
140
|
+
|
|
141
|
+
When SonarCloud cancelled the analysis or reported "analysis failed" with no
|
|
142
|
+
annotations, `pr` prints `sonar-rejected`, the likely cause (such as the
|
|
143
|
+
organisation's line limit) and the fixes, and exits 3.
|
|
144
|
+
|
|
145
|
+
### loc
|
|
146
|
+
|
|
147
|
+
```console
|
|
148
|
+
$ cleargate loc . --limit 100000
|
|
149
|
+
Estimated ncloc (sonar.sources minus sonar.tests and exclusions):
|
|
150
|
+
python 92,400
|
|
151
|
+
TOTAL 92,400
|
|
152
|
+
limit 100,000 (92.4% used, headroom 7,600)
|
|
153
|
+
|
|
154
|
+
Suggestions:
|
|
155
|
+
undeclared-tests: app/tests saves 9,260 lines (41 files)
|
|
156
|
+
sonar.tests += app/tests; sonar.exclusions += app/tests/**
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
The estimate follows `sonar-project.properties` (`sonar.sources`,
|
|
160
|
+
`sonar.tests`, `sonar.exclusions`). It finds test folders that sit under
|
|
161
|
+
`sonar.sources` but are not declared as tests, and generated or vendored code.
|
|
162
|
+
`--ref` counts a git ref instead of the working tree; `--write` applies the
|
|
163
|
+
suggested properties change.
|
|
164
|
+
|
|
165
|
+
### gate
|
|
166
|
+
|
|
167
|
+
```console
|
|
168
|
+
$ cleargate gate --base origin/main
|
|
169
|
+
a.py:4:12: CG-S1244 Equality test on a float literal; compare with a tolerance (pytest.approx or math.isclose).
|
|
170
|
+
assert 1 / 4 == 0.25
|
|
171
|
+
a.py:5:10: CG-S1313 Hard-coded IP address 192.0.2.1; read it from configuration.
|
|
172
|
+
SERVER = "192.0.2.1"
|
|
173
|
+
|
|
174
|
+
2 issues found.
|
|
175
|
+
|
|
176
|
+
Gate failed: Security B, Reliability C, Maintainability A (fails at B)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The fallback gate scans only the lines your branch changes, rates them the way
|
|
180
|
+
SonarCloud rates new code (one major bug gives Reliability C, one minor
|
|
181
|
+
vulnerability gives Security B) and fails at `--fail-on` (default B).
|
|
182
|
+
`--publish` posts the result as a GitHub check run named "cleargate gate" with
|
|
183
|
+
one annotation per finding; `--sarif` writes a SARIF file. `--auto` runs only
|
|
184
|
+
when the SonarCloud check on the pull request was rejected.
|
|
185
|
+
|
|
186
|
+
### rules and init-config
|
|
187
|
+
|
|
188
|
+
`cleargate rules` lists the catalogue (`--category`, `--language`,
|
|
189
|
+
`--search`). `cleargate init-config --ruff` prints a ruff `extend-select` that
|
|
190
|
+
catches several of these rules in the editor, and `--sonar` prints a
|
|
191
|
+
`sonar-project.properties` with a separate `sonar.tests` scope.
|
|
192
|
+
|
|
193
|
+
## Rules
|
|
194
|
+
|
|
195
|
+
`cleargate rules` lists 54 rules. The ones marked "local" have a detector:
|
|
196
|
+
|
|
197
|
+
| Area | Detected locally |
|
|
198
|
+
|---|---|
|
|
199
|
+
| Security | log injection (S5145), clear-text HTTP (S5332), hard-coded IPs (S1313), hidden Unicode tag characters, `pip install` running setup scripts (S6505) |
|
|
200
|
+
| Reliability | float equality (S1244) |
|
|
201
|
+
| Maintainability | cognitive complexity (S3776), duplicated literals (S1192), regex backtracking (S5852, S6019), undocumented FastAPI status codes (S6352), composite asserts, malformed suppression comments |
|
|
202
|
+
| Shell, Docker | `[` instead of `[[` in bash, consecutive `RUN` steps |
|
|
203
|
+
| CSS, JavaScript | duplicated selectors, `word-break: break-word`, `var`, global `parseInt`/`isNaN` |
|
|
204
|
+
|
|
205
|
+
The other rules are catalogue entries: `explain`, `plan` and `pr` use them to
|
|
206
|
+
explain findings that SonarCloud reports but cleargate does not detect itself.
|
|
207
|
+
|
|
208
|
+
## Configuration
|
|
209
|
+
|
|
210
|
+
Settings live in `pyproject.toml`:
|
|
211
|
+
|
|
212
|
+
```toml
|
|
213
|
+
[tool.cleargate]
|
|
214
|
+
select = [] # only these rule ids (empty: all)
|
|
215
|
+
ignore = ["CG-S3776"] # never report these
|
|
216
|
+
exclude = ["migrations/**"] # paths to skip
|
|
217
|
+
fail_on = "major" # scan: lowest failing severity
|
|
218
|
+
duplicate_literal_min = 3 # S1192: uses before a literal is reported
|
|
219
|
+
duplicate_literal_in_tests = false # S1192: also check test files
|
|
220
|
+
complexity_max = 15 # S3776 threshold
|
|
221
|
+
allowed_hosts = ["localhost"] # S5332: hosts allowed over http
|
|
222
|
+
allowed_ips = [] # S1313: added to 127.0.0.1, ::1, 0.0.0.0, ::
|
|
223
|
+
loc_limit = 100000 # default --limit for loc
|
|
224
|
+
sonar_check_name = "SonarCloud Code Analysis"
|
|
225
|
+
ai_model = "claude-sonnet-5-5"
|
|
226
|
+
ai_max_tokens = 800
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Exit codes
|
|
230
|
+
|
|
231
|
+
| Code | Meaning |
|
|
232
|
+
|---|---|
|
|
233
|
+
| 0 | clean, the gate passed, or nothing to fix |
|
|
234
|
+
| 1 | findings at or above the fail level, a failed gate, or fixes available (`fix --diff`) |
|
|
235
|
+
| 2 | a usage or environment problem (bad option, `gh` missing, unknown rule) |
|
|
236
|
+
| 3 | SonarCloud rejected the pull request's scan |
|
|
237
|
+
|
|
238
|
+
## GitHub Actions
|
|
239
|
+
|
|
240
|
+
Run the fallback gate next to the SonarCloud check. With `--auto` it does
|
|
241
|
+
nothing while SonarCloud is scanning normally, and takes over when the scan is
|
|
242
|
+
rejected:
|
|
243
|
+
|
|
244
|
+
```yaml
|
|
245
|
+
name: cleargate
|
|
246
|
+
on:
|
|
247
|
+
pull_request:
|
|
248
|
+
|
|
249
|
+
permissions:
|
|
250
|
+
checks: write
|
|
251
|
+
contents: read
|
|
252
|
+
|
|
253
|
+
jobs:
|
|
254
|
+
gate:
|
|
255
|
+
runs-on: ubuntu-latest
|
|
256
|
+
steps:
|
|
257
|
+
- uses: actions/checkout@v4
|
|
258
|
+
with:
|
|
259
|
+
fetch-depth: 0
|
|
260
|
+
- uses: actions/setup-python@v5
|
|
261
|
+
with:
|
|
262
|
+
python-version: "3.12"
|
|
263
|
+
- run: pip install cleargate
|
|
264
|
+
- name: Fallback quality gate
|
|
265
|
+
env:
|
|
266
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
267
|
+
run: >
|
|
268
|
+
cleargate gate --auto --publish
|
|
269
|
+
--repo ${{ github.repository }}
|
|
270
|
+
--pr ${{ github.event.pull_request.number }}
|
|
271
|
+
--base origin/${{ github.base_ref }}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
`--auto` reads the SonarCloud check on the pull request head, so run this job
|
|
275
|
+
after that check has finished (for example in a later job, or on a
|
|
276
|
+
`check_run: completed` trigger) if the two race.
|
|
277
|
+
|
|
278
|
+
## Development
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
python -m venv .venv && . .venv/bin/activate
|
|
282
|
+
pip install -e ".[dev,ai]"
|
|
283
|
+
pytest
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
`scripts/release_gate.ps1` runs the dash check, ruff, black, pylint, mypy, the
|
|
287
|
+
tests, the build and `twine check`.
|
|
288
|
+
|
|
289
|
+
## License
|
|
290
|
+
|
|
291
|
+
MIT
|