tamperward 2.29.5 → 2.29.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.
Files changed (2) hide show
  1. package/dist/cli/index.js +57 -9
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -3432,22 +3432,53 @@ function isCommentLine(trimmed, lang) {
3432
3432
  return SLASH_COMMENT.test(trimmed);
3433
3433
  }
3434
3434
  function insideStringLiteral(line, idx, lang) {
3435
- const hash = HASH_COMMENT_LANGS.has(lang ?? "js");
3435
+ const l = lang ?? "js";
3436
+ const hash = HASH_COMMENT_LANGS.has(l);
3436
3437
  let quote = null;
3437
3438
  for (let j = 0; j < idx; j++) {
3438
3439
  const ch = line[j];
3439
3440
  if (quote) {
3440
3441
  if (ch === "\\") j++;
3441
- else if (ch === quote) quote = null;
3442
+ else if (quote.length === 3) {
3443
+ if (ch === quote[0] && line[j + 1] === quote[0] && line[j + 2] === quote[0]) {
3444
+ quote = null;
3445
+ j += 2;
3446
+ }
3447
+ } else if (ch === quote) quote = null;
3442
3448
  continue;
3443
3449
  }
3444
- if (ch === '"' || ch === "'" || ch === "`") quote = ch;
3450
+ if (l === "py" && (ch === '"' || ch === "'") && line[j + 1] === ch && line[j + 2] === ch) {
3451
+ quote = ch.repeat(3);
3452
+ j += 2;
3453
+ } else if (ch === '"' || ch === "'" || ch === "`") quote = ch;
3445
3454
  else if (ch === "/" && (line[j + 1] === "/" || line[j + 1] === "*")) return false;
3455
+ else if (l === "js" && ch === "/" && regexPosition(line.slice(0, j))) j = skipRegexLiteral(line, j);
3446
3456
  else if (hash && ch === "#") return false;
3447
3457
  }
3448
3458
  return quote !== null;
3449
3459
  }
3450
- var CODE, EXT, COMMON, IMPORTS, HASH_COMMENT, DEBUG_ONLY, SLASH_COMMENT, HASH_COMMENT_LANGS;
3460
+ function regexPosition(before) {
3461
+ const s = before.replace(/\s+$/, "");
3462
+ if (s === "") return true;
3463
+ const last = s[s.length - 1];
3464
+ if (/[\w$]/.test(last)) {
3465
+ const kw = /[A-Za-z_$][\w$]*$/.exec(s);
3466
+ return kw !== null && REGEX_KEYWORDS.has(kw[0]);
3467
+ }
3468
+ return last !== ")" && last !== "]" && last !== '"' && last !== "'" && last !== "`";
3469
+ }
3470
+ function skipRegexLiteral(line, start) {
3471
+ let inClass = false;
3472
+ for (let k = start + 1; k < line.length; k++) {
3473
+ const c = line[k];
3474
+ if (c === "\\") k++;
3475
+ else if (c === "[") inClass = true;
3476
+ else if (c === "]") inClass = false;
3477
+ else if (c === "/" && !inClass) return k;
3478
+ }
3479
+ return line.length - 1;
3480
+ }
3481
+ var CODE, EXT, COMMON, IMPORTS, HASH_COMMENT, DEBUG_ONLY, SLASH_COMMENT, HASH_COMMENT_LANGS, REGEX_KEYWORDS;
3451
3482
  var init_files = __esm({
3452
3483
  "src/detectors/files.ts"() {
3453
3484
  "use strict";
@@ -3479,6 +3510,21 @@ var init_files = __esm({
3479
3510
  DEBUG_ONLY = /^(?:console\.\w+\(.*\)\s*;?|debugger\s*;?)$/;
3480
3511
  SLASH_COMMENT = /^(?:\/\/|\/\*|\*(?:\s|\/|$))/;
3481
3512
  HASH_COMMENT_LANGS = /* @__PURE__ */ new Set(["py", "rb", "php"]);
3513
+ REGEX_KEYWORDS = /* @__PURE__ */ new Set([
3514
+ "return",
3515
+ "throw",
3516
+ "case",
3517
+ "yield",
3518
+ "do",
3519
+ "else",
3520
+ "in",
3521
+ "of",
3522
+ "typeof",
3523
+ "void",
3524
+ "delete",
3525
+ "instanceof",
3526
+ "new"
3527
+ ]);
3482
3528
  }
3483
3529
  });
3484
3530
 
@@ -3890,8 +3936,8 @@ var init_lint_suppression = __esm({
3890
3936
  { re: /\bbiome-ignore\b/, why: "biome-ignore suppresses Biome diagnostics" }
3891
3937
  ],
3892
3938
  py: [
3893
- { re: /#\s*noqa\b/, why: "# noqa suppresses flake8/ruff findings" },
3894
- { re: /#\s*(?:ruff|flake8):\s*noqa\b/, why: "# ruff: noqa / # flake8: noqa suppresses every finding in the file" },
3939
+ { re: /#\s*noqa\b/i, why: "# noqa suppresses flake8/ruff findings" },
3940
+ { re: /#\s*(?:ruff|flake8):\s*noqa\b/i, why: "# ruff: noqa / # flake8: noqa suppresses every finding in the file" },
3895
3941
  { re: /#\s*type:\s*ignore\b/, why: "# type: ignore suppresses the type checker" },
3896
3942
  { re: /#\s*mypy:\s*ignore-errors\b/, why: "# mypy: ignore-errors suppresses the type checker for the file" },
3897
3943
  { re: /#\s*pyright:\s*ignore\b/, why: "# pyright: ignore suppresses the type checker" },
@@ -9868,7 +9914,7 @@ function namesProtectedSnapshot(seg, policy) {
9868
9914
  }
9869
9915
  return null;
9870
9916
  }
9871
- var RULE12, RUNNER3, PM_TEST_SCRIPT, UPDATE_ANY, UPDATE_WITH_RUNNER, INSTA_ACCEPT, UPDATE_EXPECT, REGEN_SCRIPT, MUTATE, snapshotRewrite;
9917
+ var RULE12, RUNNER3, PM_TEST_SCRIPT, UPDATE_ANY, UPDATE_WITH_RUNNER, INSTA_ACCEPT, UPDATE_EXPECT, TAP_SNAPSHOT, REGEN_SCRIPT, MUTATE, snapshotRewrite;
9872
9918
  var init_snapshot_rewrite = __esm({
9873
9919
  "src/detectors/snapshot-rewrite.ts"() {
9874
9920
  "use strict";
@@ -9876,12 +9922,13 @@ var init_snapshot_rewrite = __esm({
9876
9922
  init_finding();
9877
9923
  init_command();
9878
9924
  RULE12 = "snapshot-rewrite";
9879
- RUNNER3 = /\b(?:jest|vitest|playwright|ava)\b/;
9925
+ RUNNER3 = /\b(?:jest|vitest|playwright|ava|tap)\b/;
9880
9926
  PM_TEST_SCRIPT = /(?:^|\s)(?:npm|pnpm|yarn|bun)\s+(?:t|tst|test|run(?:-script)?\s+\S*test\S*)(?:\s|$)/;
9881
9927
  UPDATE_ANY = /--(?:update-?[sS]napshots?|test-update-snapshots|snapshot-update)\b/;
9882
- UPDATE_WITH_RUNNER = /(?:^|\s)(?:-u|--update)(?:\s|$)/;
9928
+ UPDATE_WITH_RUNNER = /(?:^|\s)(?:-u|--update|--snapshot)(?:=(?:1|true))?(?:\s|$)/;
9883
9929
  INSTA_ACCEPT = /\bcargo\s+insta\s+(?:accept\b|.*\s--accept\b)/;
9884
9930
  UPDATE_EXPECT = /(?:^|\s)UPDATE_EXPECT=\S+/;
9931
+ TAP_SNAPSHOT = /(?:^|\s)TAP_SNAPSHOT=1(?:\s|$)/;
9885
9932
  REGEN_SCRIPT = /\b(?:update|regen(?:erate)?|re?bless)[-_.]?(?:golden|snapshots?|baselines?|expected)\b/i;
9886
9933
  MUTATE = /(?:^|\s)(?:rm|cp|mv|tee|truncate|dd)(?:\s|$)|sed\s+-i|>{1,2}|\bfind\b.*\s-(?:delete\b|exec\s+rm\b)|\bgit\s+(?:checkout|restore)\b/;
9887
9934
  snapshotRewrite = {
@@ -9899,6 +9946,7 @@ var init_snapshot_rewrite = __esm({
9899
9946
  else if ((RUNNER3.test(seg) || PM_TEST_SCRIPT.test(seg)) && UPDATE_WITH_RUNNER.test(seg)) why = "running the test runner in update mode rewrites failing snapshots to match current output";
9900
9947
  else if (INSTA_ACCEPT.test(seg)) why = "cargo insta accept rewrites every pending snapshot to match current output";
9901
9948
  else if (UPDATE_EXPECT.test(seg)) why = "UPDATE_EXPECT=1 rewrites every expect-test expectation to match current output";
9949
+ else if (TAP_SNAPSHOT.test(seg)) why = "TAP_SNAPSHOT=1 rewrites every node-tap snapshot to match current output";
9902
9950
  else if (REGEN_SCRIPT.test(seg)) why = "a regeneration script rewrites the recorded expected output from current output";
9903
9951
  else {
9904
9952
  const path = MUTATE.test(seg) ? namesProtectedSnapshot(seg, policy) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tamperward",
3
- "version": "2.29.5",
3
+ "version": "2.29.7",
4
4
  "description": "The deterministic agent-integrity gate. One ruleset, evaluated on the actual diff/commands as a verdict, enforced everywhere a change can be made.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "hexrift",