lintsure 0.3.6 → 0.3.7

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.
@@ -1,2 +1,8 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ /** Splits --flag=value into two tokens and checks every flag, so a CI gate can't silently fail open
3
+ * because of a typo or a bad value (improvement review, P25). Returns an error message or the parsed args. Pure. */
4
+ export declare function parseArgs(argv: string[]): {
5
+ rest: string[];
6
+ } | {
7
+ error: string;
8
+ };
package/dist/src/index.js CHANGED
@@ -33,12 +33,45 @@ fingerprint from lintsure-report.json, your reason, your name and the date.
33
33
  ${DISCLAIMER}
34
34
  Lintsure never sends your code anywhere.`;
35
35
  const VALUE_FLAGS = ["--framework", "--fail-on", "--project"];
36
+ const BOOL_FLAGS = ["--json", "--sarif", "--report", "--new-only", "--github", "--save-record"];
37
+ const FAIL_ON = ["gap", "partial"];
38
+ /** Splits --flag=value into two tokens and checks every flag, so a CI gate can't silently fail open
39
+ * because of a typo or a bad value (improvement review, P25). Returns an error message or the parsed args. Pure. */
40
+ export function parseArgs(argv) {
41
+ const rest = argv.flatMap((a) => (a.startsWith("--") && a.includes("=") ? [a.slice(0, a.indexOf("=")), a.slice(a.indexOf("=") + 1)] : [a]));
42
+ for (let i = 0; i < rest.length; i++) {
43
+ const a = rest[i];
44
+ if (!a.startsWith("--"))
45
+ continue;
46
+ if (VALUE_FLAGS.includes(a)) {
47
+ const v = rest[i + 1];
48
+ if (v === undefined || v.startsWith("--"))
49
+ return { error: `${a} needs a value.` };
50
+ if (a === "--fail-on" && !FAIL_ON.includes(v.toLowerCase()))
51
+ return { error: `--fail-on must be "gap" or "partial", not "${v}".` };
52
+ i++;
53
+ continue;
54
+ }
55
+ if (!BOOL_FLAGS.includes(a))
56
+ return { error: `Unknown option: ${a}. Run lintsure without arguments for help.` };
57
+ }
58
+ const positional = rest.filter((a, i) => !a.startsWith("--") && !VALUE_FLAGS.includes(rest[i - 1]));
59
+ if (positional.length > 1)
60
+ return { error: `Expected one folder to scan, got: ${positional.join(", ")}` };
61
+ return { rest };
62
+ }
36
63
  async function main(argv) {
37
- const [cmd, ...rest] = argv;
64
+ const [cmd, ...raw] = argv;
38
65
  if (cmd !== "scan" && cmd !== "baseline") {
39
66
  console.log(HELP);
40
67
  return cmd ? 2 : 0;
41
68
  }
69
+ const parsed = parseArgs(raw);
70
+ if ("error" in parsed) {
71
+ console.error(parsed.error);
72
+ return 2;
73
+ }
74
+ const { rest } = parsed;
42
75
  const flag = (n) => { const i = rest.indexOf(n); return i >= 0 ? rest[i + 1] : undefined; };
43
76
  const path = resolve(rest.find((a, i) => !a.startsWith("--") && !VALUE_FLAGS.includes(rest[i - 1])) ?? ".");
44
77
  const wanted = flag("--framework")?.split(",").map((s) => s.trim());
@@ -81,7 +114,8 @@ async function main(argv) {
81
114
  const accepted = report.findings.length - open.length;
82
115
  if (report.record)
83
116
  console.log(`Record ${report.record.id} · ${report.record.createdAt.replace("T", " ").slice(0, 16)} UTC · ${report.record.counts.checkPoints} check points`);
84
- console.log(`✓ ${open.length} open findings · ${n("gap")} gap · ${n("partial")} partial${accepted ? ` · ${accepted} accepted` : ""} · ${report.met.length} rules met · ${report.outside.length} outside code`);
117
+ // A check mark only when nothing is open: "✓ 3 gaps" read as a pass.
118
+ console.log(`${open.length ? "!" : "✓"} ${open.length} open findings · ${n("gap")} gap · ${n("partial")} partial${accepted ? ` · ${accepted} accepted` : ""} · ${report.met.length} rules met · ${report.outside.length} outside code`);
85
119
  if (report.baseline)
86
120
  console.log(` Since the baseline of ${report.baseline.created}: ${report.baseline.newCount} new, ${report.baseline.fixed.length} fixed, ${report.baseline.unchangedCount} unchanged`);
87
121
  for (const f of report.findings)
@@ -97,7 +131,7 @@ async function main(argv) {
97
131
  console.log("\nNext steps:");
98
132
  nextSteps(report).forEach((x, i) => console.log(` ${i + 1}. ${x}`));
99
133
  console.log(`\n${DISCLAIMER}`);
100
- const failOn = flag("--fail-on");
134
+ const failOn = flag("--fail-on")?.toLowerCase();
101
135
  const counted = rest.includes("--new-only") && report.baseline ? open.filter((f) => f.change === "new") : open;
102
136
  if (failOn === "gap" && counted.some((f) => f.status === "gap"))
103
137
  return 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lintsure",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "Readiness checks for the code your AI writes: EU AI Act, GDPR, OWASP, CWE Top 25, EU Cyber Resilience Act. Runs locally. Not an audit or legal advice.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -13,7 +13,7 @@
13
13
  "LICENSE"
14
14
  ],
15
15
  "dependencies": {
16
- "@lintsure/core": "0.3.6"
16
+ "@lintsure/core": "0.3.7"
17
17
  },
18
18
  "author": "Lintsure <hello@lintsure.com>",
19
19
  "homepage": "https://lintsure.com/docs",