codefactory-cli 0.20.1__py3-none-any.whl
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.
- codefactory/__init__.py +3 -0
- codefactory/__main__.py +5 -0
- codefactory/accept.py +68 -0
- codefactory/analyzers/__init__.py +55 -0
- codefactory/analyzers/generic.py +392 -0
- codefactory/analyzers/parallel.py +113 -0
- codefactory/analyzers/python.py +279 -0
- codefactory/analyzers/python_parse.py +402 -0
- codefactory/analyzers/treewalk.py +299 -0
- codefactory/analyzers/ts_helper.js +483 -0
- codefactory/analyzers/typescript.py +118 -0
- codefactory/apple.py +80 -0
- codefactory/audit.py +227 -0
- codefactory/baseline.py +58 -0
- codefactory/brief.py +330 -0
- codefactory/cache.py +93 -0
- codefactory/checks.py +608 -0
- codefactory/cli.py +782 -0
- codefactory/config.py +157 -0
- codefactory/coverage.py +104 -0
- codefactory/deps.py +182 -0
- codefactory/diff.py +197 -0
- codefactory/efficiency.py +250 -0
- codefactory/flags.py +263 -0
- codefactory/graph.py +95 -0
- codefactory/hotspots.py +344 -0
- codefactory/infra.py +242 -0
- codefactory/intent.py +106 -0
- codefactory/layers.py +143 -0
- codefactory/org.py +131 -0
- codefactory/owners.py +72 -0
- codefactory/patch.py +81 -0
- codefactory/paths.py +93 -0
- codefactory/plan.py +476 -0
- codefactory/privacy.py +221 -0
- codefactory/profile.py +667 -0
- codefactory/rerank.py +161 -0
- codefactory/review.py +1504 -0
- codefactory/rules.py +50 -0
- codefactory/sarif.py +661 -0
- codefactory/sbom.py +78 -0
- codefactory/security.py +537 -0
- codefactory/similar.py +199 -0
- codefactory/skill.py +144 -0
- codefactory/skill_template/SKILL.md +68 -0
- codefactory/skill_template/__init__.py +0 -0
- codefactory/sqlgraph.py +109 -0
- codefactory/suppress.py +92 -0
- codefactory/taint.py +439 -0
- codefactory/trace.py +72 -0
- codefactory/viewer/__init__.py +19 -0
- codefactory/viewer/dashboard.html +43 -0
- codefactory/viewer/factory.css +61 -0
- codefactory/viewer/factory.js +665 -0
- codefactory/viewer/template.html +47 -0
- codefactory_cli-0.20.1.dist-info/METADATA +250 -0
- codefactory_cli-0.20.1.dist-info/RECORD +61 -0
- codefactory_cli-0.20.1.dist-info/WHEEL +5 -0
- codefactory_cli-0.20.1.dist-info/entry_points.txt +2 -0
- codefactory_cli-0.20.1.dist-info/licenses/LICENSE +21 -0
- codefactory_cli-0.20.1.dist-info/top_level.txt +1 -0
codefactory/rules.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Custom pattern rules from factory.toml ([[rule]]): a team's own checks, without writing code.
|
|
2
|
+
|
|
3
|
+
[[rule]]
|
|
4
|
+
id = "no-raw-print"
|
|
5
|
+
pattern = "\\\\bprint\\\\("
|
|
6
|
+
files = ["src/**/*.py"]
|
|
7
|
+
severity = "info"
|
|
8
|
+
message = "Use the logger: print output is lost in production"
|
|
9
|
+
|
|
10
|
+
Each match becomes a `custom` finding on the function that holds it, so silencing, the baseline, SARIF, the review
|
|
11
|
+
and `diff` treat it like any built-in check.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from fnmatch import fnmatch
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
from .config import Config
|
|
20
|
+
from .graph import Flag, Graph
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def custom_flags(g: Graph, root: Path, cfg: Config) -> list[Flag]:
|
|
24
|
+
if not cfg.rules:
|
|
25
|
+
return []
|
|
26
|
+
by_file: dict[str, list] = {}
|
|
27
|
+
for fn in g.functions:
|
|
28
|
+
by_file.setdefault(fn.file, []).append(fn)
|
|
29
|
+
out = []
|
|
30
|
+
for f in g.files:
|
|
31
|
+
rules = [
|
|
32
|
+
r for r in cfg.rules if any(fnmatch(f.id, glob) or fnmatch(f.id, glob.replace("**/", "")) for glob in r["files"])
|
|
33
|
+
]
|
|
34
|
+
if not rules:
|
|
35
|
+
continue
|
|
36
|
+
try:
|
|
37
|
+
lines = (root / f.id).read_text(encoding="utf-8", errors="replace").splitlines()
|
|
38
|
+
except OSError:
|
|
39
|
+
continue
|
|
40
|
+
fns = by_file.get(f.id, [])
|
|
41
|
+
for i, line in enumerate(lines, 1):
|
|
42
|
+
for r in rules:
|
|
43
|
+
if r["regex"].search(line):
|
|
44
|
+
holding = [fn for fn in fns if fn.kind != "module" and fn.line <= i <= fn.end]
|
|
45
|
+
module = next((fn for fn in fns if fn.kind == "module"), None)
|
|
46
|
+
owner = min(holding, key=lambda fn: fn.end - fn.line) if holding else module
|
|
47
|
+
target = owner.id if owner else f.id
|
|
48
|
+
msg = f"[{r['id']}] {r['message']}" + (f" Fix: {r['fix']}" if r["fix"] else "")
|
|
49
|
+
out.append(Flag("custom", r["severity"], target, msg, line=i, detail=r["id"]))
|
|
50
|
+
return out
|