@opendesignai/harness 0.2.0-alpha.0 → 0.4.0-alpha.0

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 (39) hide show
  1. package/README.md +90 -44
  2. package/dist/THIRD-PARTY-LICENSES.md +63 -0
  3. package/dist/child-env-cPBUueQI.mjs +17 -0
  4. package/dist/cli.mjs +4916 -209
  5. package/dist/config.d.mts +68 -0
  6. package/dist/config.mjs +12 -0
  7. package/dist/eslint-comments.mjs +1679 -4
  8. package/dist/hook.d.mts +19 -0
  9. package/dist/hook.mjs +9843 -0
  10. package/dist/plugin.d.mts +1 -1
  11. package/dist/plugin.mjs +283 -27
  12. package/dist/report.d.mts +40 -0
  13. package/dist/report.mjs +34 -0
  14. package/docs/adopting.md +107 -11
  15. package/docs/agent-setup.md +21 -0
  16. package/docs/agents.md +42 -0
  17. package/docs/comments.md +33 -0
  18. package/docs/decisions/0001-oxlint.md +28 -1
  19. package/docs/decisions/0002-react-compiler-rules.md +39 -0
  20. package/docs/decisions/0004-type-aware-rules.md +43 -0
  21. package/docs/decisions/0005-test-weakening-rules.md +28 -0
  22. package/docs/diagnostics.md +58 -0
  23. package/docs/hooks.md +152 -36
  24. package/docs/ratchet.md +23 -21
  25. package/docs/rules/no-commented-out-code.md +47 -0
  26. package/docs/rules/no-swallowed-catch.md +18 -7
  27. package/docs/size.md +3 -1
  28. package/docs/verify.md +80 -0
  29. package/package.json +30 -6
  30. package/presets/react-compiler.json +2 -1
  31. package/presets/rules/base.json +5 -0
  32. package/presets/strict-types.json +5 -0
  33. package/presets/testing.json +22 -0
  34. package/presets/type-aware.json +69 -0
  35. package/skills/od-feature-intake/SKILL.md +22 -0
  36. package/skills/od-pre-pr-review/SKILL.md +46 -0
  37. package/dist/cli.d.mts +0 -1
  38. package/dist/eslint-comments.d.mts +0 -40
  39. package/dist/paths-DBoYPrGy.mjs +0 -59
package/dist/plugin.d.mts CHANGED
@@ -36,6 +36,6 @@ interface Plugin {
36
36
  rules: Record<string, PluginRule>;
37
37
  }
38
38
  /** Kept in sync with package.json by test/plugin.test.ts. */
39
- export declare const VERSION = "0.2.0-alpha.0";
39
+ export declare const VERSION = "0.4.0-alpha.0";
40
40
  declare const plugin: Plugin;
41
41
  export { type Plugin, type PluginRule, type RuleContextLike, type RuleMeta, plugin as default };
package/dist/plugin.mjs CHANGED
@@ -1,5 +1,6 @@
1
+ import { parseSync } from "oxc-parser";
1
2
  import path from "node:path";
2
- import { n as repoRelativePath, t as compilePathPatterns } from "./paths-DBoYPrGy.mjs";
3
+ import { realpathSync } from "node:fs";
3
4
  // src/plugin/meta.ts
4
5
  const DOCS_BASE = "https://github.com/nexu-io/od-harness/blob/main/docs/rules";
5
6
  function docsUrl(rule) {
@@ -207,14 +208,14 @@ function compileRegExp(pattern, flags, option) {
207
208
  }
208
209
  }
209
210
  // src/plugin/rules/no-api-path-literal.ts
210
- const RULE$11 = "no-api-path-literal";
211
+ const RULE$12 = "no-api-path-literal";
211
212
  const DEFAULT_PREFIXES = ["/api/", "/motion-api/"];
212
213
  const noApiPathLiteral = {
213
214
  meta: {
214
215
  type: "problem",
215
216
  docs: {
216
217
  description: "Disallow API path literals outside the API client layer",
217
- url: docsUrl(RULE$11)
218
+ url: docsUrl(RULE$12)
218
219
  },
219
220
  schema: [{
220
221
  type: "object",
@@ -227,7 +228,7 @@ const noApiPathLiteral = {
227
228
  },
228
229
  additionalProperties: false
229
230
  }],
230
- messages: { apiPath: message(RULE$11, {
231
+ messages: { apiPath: message(RULE$12, {
231
232
  violation: "API path literal starting with {{prefix}} outside the API client layer; when the backend prefix or parameters change, every copy has to be found by hand.",
232
233
  fix: "build the URL with a helper in {{client}} (add one if it does not exist) and call that helper.",
233
234
  exemption: CONFIG_EXEMPTION
@@ -268,21 +269,21 @@ const noApiPathLiteral = {
268
269
  }
269
270
  };
270
271
  // src/plugin/rules/no-cjk-literal.ts
271
- const RULE$10 = "no-cjk-literal";
272
+ const RULE$11 = "no-cjk-literal";
272
273
  const DEFAULT_PATTERN$1 = "[\\p{Script=Han}\\p{Script=Hiragana}\\p{Script=Katakana}\\p{Script=Hangul}]";
273
274
  const noCjkLiteral = {
274
275
  meta: {
275
276
  type: "problem",
276
277
  docs: {
277
278
  description: "Disallow CJK text in source literals outside the i18n catalogs",
278
- url: docsUrl(RULE$10)
279
+ url: docsUrl(RULE$11)
279
280
  },
280
281
  schema: [{
281
282
  type: "object",
282
283
  properties: { pattern: { type: "string" } },
283
284
  additionalProperties: false
284
285
  }],
285
- messages: { cjk: message(RULE$10, {
286
+ messages: { cjk: message(RULE$11, {
286
287
  violation: "CJK text in a source literal: {{sample}}. Copy hard-coded in code skips translation review and cannot follow the user's locale.",
287
288
  fix: "move user-facing copy into the i18n catalog (every supported locale) and render it with `t('<key>')`; write logs, error messages and identifiers in English.",
288
289
  exemption: "i18n catalogs, tests and fixtures are excluded by the lint config (`ignorePatterns` / `overrides`, owner review); inline disable comments are rejected and existing debt stays in oxlint-suppressions.json."
@@ -317,6 +318,175 @@ const noCjkLiteral = {
317
318
  };
318
319
  }
319
320
  };
321
+ // src/plugin/rules/no-commented-out-code.ts
322
+ const RULE$10 = "no-commented-out-code";
323
+ const TOOL_MARKERS = [
324
+ /^(?:eslint-|oxlint-|eslint [\w/@-]+\s*:|globals? [\w$]+(?:\s*[:,]|\s*$))/,
325
+ /^(?:@ts-(?:expect-error|ignore|nocheck|check|self-types)|\/ ?<reference|@flow\b)/,
326
+ /^(?:prettier-ignore|biome-ignore|oxfmt-ignore|dprint-ignore|@format\b)/,
327
+ /^(?:(?:istanbul|c8|v8) ignore|@(?:vitest|jest)-environment)/,
328
+ /^(?:[#@]__(?:PURE|NO_SIDE_EFFECTS)__|@vite-ignore|webpack[A-Z]|@jsx|@refresh)/,
329
+ /^(?:@license|@preserve|sourceMappingURL|@internal\b$)/,
330
+ /^(?:#(?:end)?region\b|(?:end)?region$)/,
331
+ /^(?:fail-open|knip-ignore|fallow-ignore|jscpd:|harness-|cspell:)/,
332
+ /^(?:html|css|sql|gql|graphql|glsl|svg)$/
333
+ ];
334
+ const CODE_PUNCTUATION = /[;(){}=<>[\]]/;
335
+ const JSX_CODE = /<[A-Z][\w.]*|=\{|>\s*\{/;
336
+ const STRONG_STATEMENTS = /* @__PURE__ */ new Set([
337
+ "VariableDeclaration",
338
+ "FunctionDeclaration",
339
+ "ClassDeclaration",
340
+ "ImportDeclaration",
341
+ "ExportNamedDeclaration",
342
+ "ExportDefaultDeclaration",
343
+ "ExportAllDeclaration",
344
+ "IfStatement",
345
+ "ForStatement",
346
+ "ForOfStatement",
347
+ "ForInStatement",
348
+ "WhileStatement",
349
+ "DoWhileStatement",
350
+ "TryStatement",
351
+ "SwitchStatement",
352
+ "TSInterfaceDeclaration",
353
+ "TSTypeAliasDeclaration",
354
+ "TSEnumDeclaration"
355
+ ]);
356
+ function isToolMarker(value) {
357
+ const text = value.trim();
358
+ return TOOL_MARKERS.some((pattern) => pattern.test(text));
359
+ }
360
+ function ownCommentLines(comments, lines) {
361
+ const boundaries = /* @__PURE__ */ new Map();
362
+ const own = /* @__PURE__ */ new Set();
363
+ function cover(line, from, to) {
364
+ const previous = boundaries.get(line);
365
+ const gap = lines[line - 1]?.slice(previous?.end ?? 0, from) ?? "";
366
+ boundaries.set(line, {
367
+ end: to,
368
+ outside: (previous?.outside ?? "") + gap
369
+ });
370
+ }
371
+ for (const { loc } of comments) {
372
+ const { start, end } = loc;
373
+ if (start.line === end.line) cover(start.line, start.column, end.column);
374
+ else {
375
+ cover(start.line, start.column, lines[start.line - 1]?.length ?? 0);
376
+ cover(end.line, 0, end.column);
377
+ if (lines[start.line - 1]?.slice(0, start.column).trim() === "{" && lines[end.line - 1]?.slice(end.column).trim() === "}") own.add(start.line);
378
+ }
379
+ }
380
+ for (const [line, { end, outside }] of boundaries) {
381
+ const before = outside.trim();
382
+ const after = lines[line - 1]?.slice(end).trim() ?? "";
383
+ if (before === "" && after === "" || before === "{" && after === "}") own.add(line);
384
+ }
385
+ return own;
386
+ }
387
+ function isStrongExpression(expression, hasSemicolon, hasJsxCode) {
388
+ switch (expression.type) {
389
+ case "ChainExpression": return isStrongExpression(expression.expression, hasSemicolon, hasJsxCode);
390
+ case "AwaitExpression":
391
+ case "NewExpression":
392
+ case "UpdateExpression":
393
+ case "ArrowFunctionExpression": return true;
394
+ case "JSXElement":
395
+ case "JSXFragment": return hasJsxCode;
396
+ case "CallExpression": return expression.callee.type !== "Identifier" || hasSemicolon || expression.arguments.some((argument) => argument.type === "ArrowFunctionExpression" || argument.type === "FunctionExpression");
397
+ case "AssignmentExpression": return hasSemicolon || expression.left.type === "MemberExpression";
398
+ default: return false;
399
+ }
400
+ }
401
+ function isStrongStatement(statement, hasSemicolon, hasJsxCode) {
402
+ switch (statement.type) {
403
+ case "ReturnStatement":
404
+ case "ThrowStatement": return hasSemicolon || !!(statement.argument && statement.argument.type !== "Identifier");
405
+ case "ExpressionStatement": return isStrongExpression(statement.expression, hasSemicolon, hasJsxCode);
406
+ case "BlockStatement": return statement.body.some((child) => isStrongStatement(child, hasSemicolon, hasJsxCode));
407
+ default: return STRONG_STATEMENTS.has(statement.type);
408
+ }
409
+ }
410
+ function parseBody(code) {
411
+ try {
412
+ const result = parseSync("comment.tsx", code);
413
+ return result.errors.length === 0 ? result.program.body : [];
414
+ } catch {
415
+ return [];
416
+ }
417
+ }
418
+ function hasStrongStatement(body, hasSemicolon, hasJsxCode) {
419
+ return body.every((statement) => statement.type !== "EmptyStatement") && body.some((statement) => isStrongStatement(statement, hasSemicolon, hasJsxCode));
420
+ }
421
+ function isCode(text) {
422
+ if (text.length < 3 || !CODE_PUNCTUATION.test(text)) return false;
423
+ if (isToolMarker(text) || /^https?:\/\//.test(text)) return false;
424
+ const hasSemicolon = /;\s*(?:\n|$)/.test(text);
425
+ const hasJsxCode = JSX_CODE.test(text);
426
+ if (hasStrongStatement(parseBody(text), hasSemicolon, hasJsxCode)) return true;
427
+ const functionBody = parseBody(`async function wrapped() {\n${text}\n}`);
428
+ const fn = functionBody[0];
429
+ if (fn?.type === "FunctionDeclaration" && functionBody.length === 1 && fn.body && hasStrongStatement(fn.body.body, hasSemicolon, hasJsxCode)) return true;
430
+ const classBody = parseBody(`class Wrapped {\n${text}\n}`);
431
+ const cls = classBody[0];
432
+ if (cls?.type === "ClassDeclaration" && classBody.length === 1 && cls.body.body.some((member) => member.type === "MethodDefinition" && member.value.body || member.type === "PropertyDefinition" && member.value && hasSemicolon)) return true;
433
+ if (!hasJsxCode) return false;
434
+ const jsxBody = parseBody(`<>\n${text}\n</>`);
435
+ const jsx = jsxBody[0];
436
+ if (jsxBody.length !== 1 || jsx?.type !== "ExpressionStatement" || jsx.expression.type !== "JSXFragment") return false;
437
+ const { children } = jsx.expression;
438
+ return children.some((child) => child.type === "JSXElement" || child.type === "JSXExpressionContainer") && children.every((child) => child.type !== "JSXText" || child.value.trim() === "");
439
+ }
440
+ const noCommentedOutCode = {
441
+ meta: {
442
+ type: "problem",
443
+ docs: {
444
+ description: "Disallow commented-out code",
445
+ url: docsUrl(RULE$10)
446
+ },
447
+ schema: [],
448
+ messages: { commentedOutCode: message(RULE$10, {
449
+ violation: "This comment contains code that has been commented out.",
450
+ fix: "Delete the commented-out code. Use git history to recover old code. Move examples into documentation or tests.",
451
+ exemption: CONFIG_EXEMPTION
452
+ }) }
453
+ },
454
+ create(context) {
455
+ return { Program() {
456
+ const { sourceCode } = context;
457
+ const comments = sourceCode.getAllComments().filter((comment) => comment.type !== "Shebang");
458
+ if (comments.length === 0) return;
459
+ const own = ownCommentLines(comments, sourceCode.lines);
460
+ for (let index = 0; index < comments.length; index++) {
461
+ const first = comments[index];
462
+ if (!first || !own.has(first.loc.start.line) || isToolMarker(first.value)) continue;
463
+ let last = first;
464
+ let text = first.value;
465
+ if (first.type === "Block") {
466
+ if (text.startsWith("*") && !text.startsWith("**")) continue;
467
+ text = text.replace(/^[^\S\r\n\u2028\u2029]*\*+ ?/gm, "");
468
+ } else {
469
+ const lines = [text];
470
+ for (let next = comments[index + 1]; next; next = comments[index + 1]) {
471
+ const line = next.loc.start.line;
472
+ if (next.type !== "Line" || line !== last.loc.end.line + 1 || !own.has(line) || isToolMarker(next.value)) break;
473
+ lines.push(next.value);
474
+ last = next;
475
+ index++;
476
+ }
477
+ text = lines.join("\n");
478
+ }
479
+ if (isCode(text.trim())) context.report({
480
+ loc: {
481
+ start: first.loc.start,
482
+ end: last.loc.end
483
+ },
484
+ messageId: "commentedOutCode"
485
+ });
486
+ }
487
+ } };
488
+ }
489
+ };
320
490
  // src/plugin/rules/no-constant-flag.ts
321
491
  const RULE$9 = "no-constant-flag";
322
492
  const DEFAULT_PATTERN = [
@@ -424,6 +594,11 @@ function isDestructuredFromErrorCall(node, errRe) {
424
594
  return arg?.type === "Identifier" && errRe.test(arg.name);
425
595
  });
426
596
  }
597
+ /** A non-empty static string: equality with "" asks whether there is a message, not what it says. */
598
+ function isWording(node) {
599
+ const text = staticString(node);
600
+ return text !== null && text !== "";
601
+ }
427
602
  function isRegex(node) {
428
603
  const n = unwrap(node);
429
604
  return n?.type === "Literal" && "regex" in n && n.regex !== void 0;
@@ -535,11 +710,7 @@ const noErrorMessageMatch = {
535
710
  for (const node of pending) {
536
711
  if (node.type === "BinaryExpression") {
537
712
  const left = node.left;
538
- const wording = (other) => {
539
- const text = staticString(other);
540
- return text !== null && text !== "";
541
- };
542
- if (isMessage(left) && wording(node.right) || isMessage(node.right) && wording(left)) report(node);
713
+ if (isMessage(left) && isWording(node.right) || isMessage(node.right) && isWording(left)) report(node);
543
714
  continue;
544
715
  }
545
716
  if (node.type !== "CallExpression") continue;
@@ -1068,6 +1239,62 @@ const noRawStorage = {
1068
1239
  };
1069
1240
  }
1070
1241
  };
1242
+ // src/plugin/utils/paths.ts
1243
+ function toPosix(p) {
1244
+ return p.split(path.sep).join("/");
1245
+ }
1246
+ const realCache = /* @__PURE__ */ new Map();
1247
+ function real(p) {
1248
+ let cached = realCache.get(p);
1249
+ if (cached === void 0) {
1250
+ try {
1251
+ cached = realpathSync(p);
1252
+ } catch {
1253
+ cached = p;
1254
+ }
1255
+ realCache.set(p, cached);
1256
+ }
1257
+ return cached;
1258
+ }
1259
+ /**
1260
+ * Path of the linted file relative to the working directory the linter was started in (the
1261
+ * repository root in CI and hooks), with forward slashes. Both linters report absolute paths, but
1262
+ * one of them may have resolved symlinks (for example /tmp → /private/tmp on macOS).
1263
+ */
1264
+ function repoRelativePath(context) {
1265
+ const cwd = context.cwd;
1266
+ const file = path.isAbsolute(context.filename) ? context.filename : path.join(cwd, context.filename);
1267
+ let rel = path.relative(cwd, file);
1268
+ if (rel.startsWith("..")) rel = path.relative(real(cwd), real(file));
1269
+ return toPosix(rel);
1270
+ }
1271
+ /**
1272
+ * Compile repo-relative path patterns. Supported forms:
1273
+ * - `dir/` — the directory and everything below it;
1274
+ * - globs with `**` (any depth), `*` (one segment) and `?`; `dir/**` also matches `dir` itself;
1275
+ * - anything else is an exact path.
1276
+ */
1277
+ function compilePathPatterns(patterns) {
1278
+ const regexes = patterns.map(patternToRegExp);
1279
+ return (rel) => regexes.some((re) => re.test(rel));
1280
+ }
1281
+ function patternToRegExp(pattern) {
1282
+ const glob = pattern.endsWith("/") ? `${pattern}**` : pattern;
1283
+ let out = "";
1284
+ for (let i = 0; i < glob.length; i++) {
1285
+ const ch = glob[i];
1286
+ if (ch === "*") {
1287
+ if (glob[i + 1] === "*") {
1288
+ const slashAfter = glob[i + 2] === "/";
1289
+ if (i + 2 === glob.length && out.endsWith("/")) out = `${out.slice(0, -1)}(?:/.*)?`;
1290
+ else out += slashAfter ? "(?:.*/)?" : ".*";
1291
+ i += slashAfter ? 2 : 1;
1292
+ } else out += "[^/]*";
1293
+ } else if (ch === "?") out += "[^/]";
1294
+ else out += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
1295
+ }
1296
+ return new RegExp(`^${out}$`);
1297
+ }
1071
1298
  // src/plugin/rules/no-shell-imports-product.ts
1072
1299
  const RULE$2 = "no-shell-imports-product";
1073
1300
  function isTypeOnly(node) {
@@ -1135,7 +1362,7 @@ const noShellImportsProduct = {
1135
1362
  const rel = repoRelativePath(context);
1136
1363
  if (!isShell(rel) || isProduct(rel)) return {};
1137
1364
  const dir = path.posix.dirname(rel);
1138
- const aliases = Object.entries(options.aliases ?? {}).sort((a, b) => b[0].length - a[0].length);
1365
+ const aliases = Object.entries(options.aliases ?? {}).toSorted((a, b) => b[0].length - a[0].length);
1139
1366
  function resolve(spec) {
1140
1367
  if (spec.startsWith(".")) return path.posix.join(dir, spec);
1141
1368
  for (const [prefix, target] of aliases) if (aliasMatches(spec, prefix)) return path.posix.join(target, spec.slice(prefix.length));
@@ -1201,19 +1428,43 @@ function isInert(statement) {
1201
1428
  if (statement.type === "EmptyStatement") return true;
1202
1429
  return statement.type === "BlockStatement" && statement.body.every(isInert);
1203
1430
  }
1204
- /** What a block does once inert statements are dropped: nothing, or only `return <constant>`. */
1205
- function swallows(block) {
1431
+ /** The sole effective statement, null for an empty block, or undefined for multiple statements. */
1432
+ function onlyStatement(block) {
1206
1433
  const statements = block.body.filter((s) => !isInert(s));
1207
- if (statements.length === 0) return "empty";
1208
- const only = statements[0];
1209
- if (statements.length === 1 && only?.type === "ReturnStatement" && isConstant(only.argument)) return "constant";
1210
- return null;
1434
+ if (statements.length === 0) return null;
1435
+ if (statements.length > 1) return void 0;
1436
+ const [statement] = statements;
1437
+ return statement?.type === "BlockStatement" ? onlyStatement(statement) : statement;
1438
+ }
1439
+ function isSwallowedValue(input) {
1440
+ return isConstant(input) && (staticString(input)?.length ?? 0) === 0;
1441
+ }
1442
+ function swallows(statement) {
1443
+ return statement === null || statement?.type === "ReturnStatement" && isSwallowedValue(statement.argument);
1444
+ }
1445
+ function returnsBoolean(statement, value) {
1446
+ if (statement?.type !== "ReturnStatement") return false;
1447
+ const argument = unwrap(statement.argument);
1448
+ return argument?.type === "Literal" && argument.value === value;
1449
+ }
1450
+ function isChainedCall(callee) {
1451
+ let target = unwrap(callee);
1452
+ while (target?.type === "MemberExpression") target = unwrap(target.object);
1453
+ return target?.type === "CallExpression" || target?.type === "NewExpression";
1454
+ }
1455
+ function isProbePredicate(tryBlock, catchBlock, visitorKeys) {
1456
+ const [probe, success] = tryBlock.body;
1457
+ if (tryBlock.body.length !== 2 || probe?.type !== "ExpressionStatement" || !returnsBoolean(success, true) || catchBlock.body.length !== 1 || !returnsBoolean(catchBlock.body[0], false)) return false;
1458
+ let expression = unwrap(probe.expression);
1459
+ if (expression?.type === "AwaitExpression") expression = unwrap(expression.argument);
1460
+ if (expression?.type !== "CallExpression") return false;
1461
+ return !someNode(expression, visitorKeys, (node) => node.type === "AssignmentExpression" || node.type === "UpdateExpression" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "CallExpression" && isChainedCall(node.callee));
1211
1462
  }
1212
1463
  function isSwallowingHandler(input) {
1213
1464
  const fn = unwrap(input);
1214
1465
  if (!fn || fn.type !== "ArrowFunctionExpression" && fn.type !== "FunctionExpression") return false;
1215
- if (fn.body.type !== "BlockStatement") return isConstant(fn.body);
1216
- return swallows(fn.body) !== null;
1466
+ if (fn.body.type !== "BlockStatement") return isSwallowedValue(fn.body);
1467
+ return swallows(onlyStatement(fn.body));
1217
1468
  }
1218
1469
  /** The rejection handler of `.catch(handler)` or `.then(onFulfilled, handler)`. */
1219
1470
  function rejectionHandler(node) {
@@ -1241,7 +1492,7 @@ const noSwallowedCatch = {
1241
1492
  }],
1242
1493
  messages: { swallowed: message(RULE$1, {
1243
1494
  violation: "{{what}} discards the error without logging, reporting or rethrowing it, so failures (including failed writes) vanish silently.",
1244
- fix: "handle it: log with context and report it to telemetry, return an explicit error result, or rethrow; if the caller can proceed, say why in code.",
1495
+ fix: "log with context and report it to telemetry, return an explicit error result, or rethrow.",
1245
1496
  exemption: "when ignoring the error is genuinely correct, put a `// fail-open: <reason>` comment inside the handler or on the line of (or just above) the catch; best-effort cleanup calls (close, cancel, rm, …) are allowed without a comment. Inline disable comments are rejected."
1246
1497
  }) }
1247
1498
  },
@@ -1267,14 +1518,17 @@ const noSwallowedCatch = {
1267
1518
  }
1268
1519
  return {
1269
1520
  CatchClause(node) {
1270
- if (swallows(node.body) !== "empty") return;
1521
+ const statement = onlyStatement(node.body);
1522
+ if (!swallows(statement)) return;
1271
1523
  const tryStatement = node.parent;
1524
+ if (tryStatement?.type === "TryStatement" && isProbePredicate(tryStatement.block, node.body, context.sourceCode.visitorKeys)) return;
1272
1525
  if (tryStatement?.type === "TryStatement" && tryStatement.block.body.length > 0 && tryStatement.block.body.every((s) => s.type === "ExpressionStatement" && isCleanupCall(s.expression))) return;
1273
1526
  if (hasFailOpen(node.body, node.loc.start.line)) return;
1527
+ const what = statement === null ? "this empty catch block" : "this catch block, which only returns a constant,";
1274
1528
  context.report({
1275
1529
  node,
1276
1530
  messageId: "swallowed",
1277
- data: { what: "this empty catch block" }
1531
+ data: { what }
1278
1532
  });
1279
1533
  },
1280
1534
  CallExpression(node) {
@@ -1384,9 +1638,10 @@ const noWindowBus = {
1384
1638
  };
1385
1639
  }
1386
1640
  };
1387
- // src/plugin/index.ts
1641
+ // src/plugin/version.ts
1388
1642
  /** Kept in sync with package.json by test/plugin.test.ts. */
1389
- const VERSION = "0.2.0-alpha.0";
1643
+ const VERSION = "0.4.0-alpha.0";
1644
+ // src/plugin/index.ts
1390
1645
  const plugin = {
1391
1646
  meta: {
1392
1647
  name: "od",
@@ -1404,7 +1659,8 @@ const plugin = {
1404
1659
  "no-process-env": noProcessEnv,
1405
1660
  "no-error-message-match": noErrorMessageMatch,
1406
1661
  "no-cjk-literal": noCjkLiteral,
1407
- "no-constant-flag": noConstantFlag
1662
+ "no-constant-flag": noConstantFlag,
1663
+ "no-commented-out-code": noCommentedOutCode
1408
1664
  }
1409
1665
  };
1410
1666
  export { VERSION, plugin as default };
@@ -0,0 +1,40 @@
1
+ interface Diagnostic {
2
+ file: string;
3
+ line?: number;
4
+ column?: number;
5
+ kind: string;
6
+ severity?: "error" | "notice";
7
+ rule?: string;
8
+ message: string;
9
+ fix?: string;
10
+ exemption?: string;
11
+ docs?: string;
12
+ isNew?: boolean;
13
+ }
14
+ interface DiagnosticReport {
15
+ ok: boolean;
16
+ diagnostics: (Diagnostic & {
17
+ line: number;
18
+ })[];
19
+ summary?: string;
20
+ notes?: string[];
21
+ }
22
+ interface VerifyCheck extends DiagnosticReport {
23
+ id: string;
24
+ status: "passed" | "failed" | "error" | "skipped";
25
+ durationMs: number;
26
+ }
27
+ interface VerifyReport extends DiagnosticReport {
28
+ mode: "quick" | "default" | "ci";
29
+ base: string;
30
+ changedFiles: string[];
31
+ checks: VerifyCheck[];
32
+ exitCode: 0 | 1;
33
+ durationMs: number;
34
+ }
35
+ /** Print one diagnostic to stderr, with a GitHub annotation when requested or in Actions. */
36
+ export declare function reportDiagnostic(diagnostic: Diagnostic, { format, annotate }?: {
37
+ format?: "text" | "github";
38
+ annotate?: boolean;
39
+ }): void;
40
+ export type { Diagnostic, DiagnosticReport, VerifyCheck, VerifyReport };
@@ -0,0 +1,34 @@
1
+ import { r as isGitHubActions } from "./child-env-cPBUueQI.mjs";
2
+ // src/cli/diagnostic.ts
3
+ function diagnosticMessage({ message, fix, exemption, docs, severity }) {
4
+ return [
5
+ `${severity === "notice" ? "Notice" : "Violation"}: ${message}`,
6
+ fix ? `Fix: ${fix}` : "",
7
+ exemption ? `Exemption: ${exemption}` : "",
8
+ docs ? `Docs: ${docs}` : ""
9
+ ].filter(Boolean).join(" ");
10
+ }
11
+ // src/cli/github-annotation.ts
12
+ function escapeAnnotationData(value) {
13
+ return value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
14
+ }
15
+ function escapeAnnotationProperty(value) {
16
+ return escapeAnnotationData(value).replaceAll(":", "%3A").replaceAll(",", "%2C");
17
+ }
18
+ // src/cli/report.ts
19
+ /** Print one diagnostic to stderr, with a GitHub annotation when requested or in Actions. */
20
+ function reportDiagnostic(diagnostic, { format = "text", annotate = isGitHubActions() } = {}) {
21
+ const { file, line = 1, severity = "error" } = diagnostic;
22
+ const message = diagnosticMessage(diagnostic);
23
+ if (format === "text") console.error(file ? `${JSON.stringify(file)}: ${message}` : message);
24
+ if (format === "github" || annotate) {
25
+ if (!file) {
26
+ console.error(`::${severity}::${escapeAnnotationData(message)}`);
27
+ return;
28
+ }
29
+ const annotationLine = Number.isInteger(line) && line >= 1 ? line : 1;
30
+ const property = escapeAnnotationProperty(file);
31
+ console.error(`::${severity} file=${property},line=${annotationLine}::${escapeAnnotationData(message)}`);
32
+ }
33
+ }
34
+ export { reportDiagnostic };