@opendesignai/harness 0.0.0-stage → 0.2.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/LICENSE +201 -0
  2. package/README.md +132 -2
  3. package/dist/cli.d.mts +1 -0
  4. package/dist/cli.mjs +1723 -0
  5. package/dist/eslint-comments.d.mts +40 -0
  6. package/dist/eslint-comments.mjs +182 -0
  7. package/dist/paths-DBoYPrGy.mjs +59 -0
  8. package/dist/plugin.d.mts +41 -0
  9. package/dist/plugin.mjs +1410 -0
  10. package/docs/adopting.md +224 -0
  11. package/docs/baseline-move.md +56 -0
  12. package/docs/clones.md +51 -0
  13. package/docs/decisions/0001-oxlint.md +74 -0
  14. package/docs/decisions/0002-react-compiler-rules.md +34 -0
  15. package/docs/decisions/0003-agent-harness.md +37 -0
  16. package/docs/hooks.md +128 -0
  17. package/docs/ratchet.md +65 -0
  18. package/docs/rules/no-api-path-literal.md +35 -0
  19. package/docs/rules/no-cjk-literal.md +38 -0
  20. package/docs/rules/no-constant-flag.md +33 -0
  21. package/docs/rules/no-error-message-match.md +63 -0
  22. package/docs/rules/no-locale-branch.md +55 -0
  23. package/docs/rules/no-process-env.md +37 -0
  24. package/docs/rules/no-product-literal.md +41 -0
  25. package/docs/rules/no-raw-fetch.md +33 -0
  26. package/docs/rules/no-raw-storage.md +43 -0
  27. package/docs/rules/no-shell-imports-product.md +48 -0
  28. package/docs/rules/no-swallowed-catch.md +76 -0
  29. package/docs/rules/no-window-bus.md +35 -0
  30. package/docs/size.md +52 -0
  31. package/docs/unused.md +76 -0
  32. package/package.json +75 -3
  33. package/presets/base.json +7 -0
  34. package/presets/platform-boundary.json +4 -0
  35. package/presets/product.json +4 -0
  36. package/presets/react-compiler.json +13 -0
  37. package/presets/rules/base.json +49 -0
  38. package/presets/rules/platform-boundary.json +6 -0
  39. package/presets/rules/product.json +5 -0
@@ -0,0 +1,40 @@
1
+ interface Position {
2
+ line: number;
3
+ column: number;
4
+ }
5
+ type Loc = Position | {
6
+ start: Position;
7
+ end?: Position | null;
8
+ };
9
+ interface UpstreamRuleMeta {
10
+ messages?: Record<string, string>;
11
+ [key: string]: unknown;
12
+ }
13
+ interface UpstreamRule {
14
+ meta?: UpstreamRuleMeta;
15
+ create(context: object): object;
16
+ }
17
+ export interface WrappedPlugin {
18
+ meta: {
19
+ name: string;
20
+ };
21
+ rules: Record<string, UpstreamRule>;
22
+ }
23
+ export interface ParsedDirective {
24
+ prefix: "eslint" | "oxlint";
25
+ kind: "disable" | "disable-next-line" | "disable-line" | "enable";
26
+ ruleList: string;
27
+ names: string[];
28
+ }
29
+ /** Moves negative columns to 0; a negative start becomes a zero-width location at column 0. */
30
+ export declare function clampLoc(loc: Loc): Loc;
31
+ /**
32
+ * Parses a comment's inner text the same way Oxlint's Rust side (`disable_directives.rs`) does:
33
+ * leading Unicode whitespace, directive keyword followed by Unicode whitespace or EOL, description
34
+ * cut off at `--` or `<ws>-<ws>`, and rule names split on `,` or Unicode whitespace.
35
+ */
36
+ export declare function parseRustDirective(commentValue: string): ParsedDirective | null;
37
+ /** The rule with `context.report` locations passed through `clampLoc`. */
38
+ export declare function wrapRule(rule: UpstreamRule): UpstreamRule;
39
+ declare const plugin: WrappedPlugin;
40
+ export { plugin as default };
@@ -0,0 +1,182 @@
1
+ import upstream from "@eslint-community/eslint-plugin-eslint-comments";
2
+ // src/eslint-comments/index.ts
3
+ const IS_UNICODE_WS = /^\p{White_Space}$/u;
4
+ const TRIM_UNICODE_WS = /^\p{White_Space}+|\p{White_Space}+$/gu;
5
+ const DIRECTIVE_LABEL = /^\p{White_Space}*(eslint|oxlint)-(disable-next-line|disable-line|disable|enable)(?=\p{White_Space}|$)/u;
6
+ const INVALID_PATH_RULE_NAME = /^(?:[/\\]|\.\.?(?:$|[/\\]))/;
7
+ function atColumnZero(position) {
8
+ return {
9
+ line: position.line,
10
+ column: 0
11
+ };
12
+ }
13
+ /** Moves negative columns to 0; a negative start becomes a zero-width location at column 0. */
14
+ function clampLoc(loc) {
15
+ if (!("start" in loc)) return loc.column < 0 ? atColumnZero(loc) : loc;
16
+ const { start, end } = loc;
17
+ if (start.column < 0) {
18
+ const at = atColumnZero(start);
19
+ return {
20
+ start: at,
21
+ end: at
22
+ };
23
+ }
24
+ if (end && end.column < 0) return {
25
+ start,
26
+ end: start
27
+ };
28
+ return loc;
29
+ }
30
+ function clampDescriptor(descriptor) {
31
+ if (typeof descriptor !== "object" || descriptor === null || !("loc" in descriptor)) return descriptor;
32
+ const { loc } = descriptor;
33
+ if (typeof loc !== "object" || loc === null) return descriptor;
34
+ return {
35
+ ...descriptor,
36
+ loc: clampLoc(loc)
37
+ };
38
+ }
39
+ /**
40
+ * Parses a comment's inner text the same way Oxlint's Rust side (`disable_directives.rs`) does:
41
+ * leading Unicode whitespace, directive keyword followed by Unicode whitespace or EOL, description
42
+ * cut off at `--` or `<ws>-<ws>`, and rule names split on `,` or Unicode whitespace.
43
+ */
44
+ function parseRustDirective(commentValue) {
45
+ const match = DIRECTIVE_LABEL.exec(commentValue);
46
+ if (!match) return null;
47
+ const prefix = match[1];
48
+ const kind = match[2];
49
+ const chars = Array.from(commentValue.slice(match[0].length));
50
+ const names = [];
51
+ let ruleStart = null;
52
+ let ruleEnd = chars.length;
53
+ let previous;
54
+ for (let i = 0; i < chars.length; i++) {
55
+ const ch = chars[i];
56
+ const next = chars[i + 1];
57
+ if (ch === "-" && next !== void 0 && (next === "-" || previous !== void 0 && IS_UNICODE_WS.test(previous) && IS_UNICODE_WS.test(next))) {
58
+ ruleEnd = i;
59
+ break;
60
+ }
61
+ if (ch === "," || IS_UNICODE_WS.test(ch)) {
62
+ if (ruleStart !== null) {
63
+ names.push(chars.slice(ruleStart, i).join(""));
64
+ ruleStart = null;
65
+ }
66
+ } else if (ruleStart === null) ruleStart = i;
67
+ previous = ch;
68
+ }
69
+ if (ruleStart !== null) names.push(chars.slice(ruleStart, ruleEnd).join(""));
70
+ return {
71
+ prefix,
72
+ kind,
73
+ ruleList: chars.slice(0, ruleEnd).join("").replace(TRIM_UNICODE_WS, ""),
74
+ names
75
+ };
76
+ }
77
+ function isGuardRule(name) {
78
+ return name.startsWith("eslint-comments/") || name === "no-abusive-eslint-disable" || name.endsWith("/no-abusive-eslint-disable");
79
+ }
80
+ /**
81
+ * Throws an unsuppressible error when a file tries to disable a guard or uses a directive form
82
+ * that Oxlint's Rust side applies but its JS side misreads or skips.
83
+ */
84
+ function assertNoGuardTampering(context) {
85
+ const sourceCode = context.sourceCode;
86
+ if (!sourceCode) return;
87
+ const file = context.filename ?? "<unknown>";
88
+ for (const comment of sourceCode.getAllComments()) {
89
+ if (comment.type === "Shebang") continue;
90
+ const parsed = parseRustDirective(comment.value);
91
+ if (!parsed) continue;
92
+ const line = comment.loc.start.line;
93
+ if (parsed.kind !== "enable") {
94
+ const guardName = parsed.names.find(isGuardRule);
95
+ if (guardName) throw new Error(`od-harness: ${file}:${line}: inline disable directive targets lint guard '${guardName}', which cannot be disabled. Remove the directive; to exempt a file from a protected rule, add a reviewed 'overrides' entry in the lint config instead.`);
96
+ }
97
+ if (comment.value.includes("…")) throw new Error(`od-harness: ${file}:${line}: inline disable directive contains U+0085 (NEL), which Oxlint parses as whitespace while the JS guard does not. Remove the directive or replace U+0085 with regular ASCII spaces.`);
98
+ if (parsed.kind === "disable-line" && comment.loc.start.line !== comment.loc.end.line) throw new Error(`od-harness: ${file}:${line}: multi-line '${parsed.prefix}-disable-line' block comment is applied by Oxlint but skipped by the JS guard. Remove the directive or put it on a single line (and use a reviewed 'overrides' entry in the lint config for protected rules).`);
99
+ }
100
+ }
101
+ function sanitizeDirectiveList(directives, report) {
102
+ const sanitized = [];
103
+ for (const directive of directives) {
104
+ if (directive.type === "enable" || !directive.value) {
105
+ sanitized.push(directive);
106
+ continue;
107
+ }
108
+ const parsed = parseRustDirective(directive.node.value);
109
+ const rawList = parsed ? parsed.ruleList : directive.value.trim();
110
+ const names = parsed ? parsed.names : rawList.split(/[\s,]+/u).filter(Boolean);
111
+ if (rawList.startsWith(",") || rawList.endsWith(",")) report({
112
+ loc: clampLoc(directive.node.loc),
113
+ messageId: "emptyRuleName"
114
+ });
115
+ const valid = [];
116
+ const invalid = [];
117
+ for (const name of names) if (INVALID_PATH_RULE_NAME.test(name)) invalid.push(name);
118
+ else valid.push(name);
119
+ for (const ruleId of invalid) report({
120
+ loc: clampLoc(directive.node.loc),
121
+ messageId: "invalidRuleName",
122
+ data: { ruleId }
123
+ });
124
+ if (valid.length === 0 && invalid.length > 0) continue;
125
+ sanitized.push({
126
+ ...directive,
127
+ value: valid.join(", ")
128
+ });
129
+ }
130
+ return sanitized;
131
+ }
132
+ /** The rule with `context.report` locations passed through `clampLoc`. */
133
+ function wrapRule(rule) {
134
+ return {
135
+ ...rule,
136
+ create(context) {
137
+ const report = context.report;
138
+ const derived = Object.create(context, { report: { value: (descriptor, ...rest) => report.call(context, clampDescriptor(descriptor), ...rest) } });
139
+ return rule.create(derived);
140
+ }
141
+ };
142
+ }
143
+ function guardNoRestrictedDisable(rule) {
144
+ const wrapped = wrapRule(rule);
145
+ const meta = {
146
+ ...rule.meta,
147
+ messages: {
148
+ ...rule.meta?.messages,
149
+ invalidRuleName: "Invalid rule name '{{ruleId}}' in disable directive (must not start with '/', './', or '../', or be '.' or '..'). Remove or fix the rule name.",
150
+ emptyRuleName: "Empty rule name in disable directive (leading or trailing comma). Remove the stray comma."
151
+ }
152
+ };
153
+ return {
154
+ ...wrapped,
155
+ meta,
156
+ create(context) {
157
+ const ctx = context;
158
+ assertNoGuardTampering(ctx);
159
+ if (Array.isArray(ctx.options) && ctx.options.length === 0) return {};
160
+ const sourceCode = ctx.sourceCode;
161
+ if (!sourceCode || typeof sourceCode.getDisableDirectives !== "function") return wrapped.create(context);
162
+ const origGetDisableDirectives = sourceCode.getDisableDirectives.bind(sourceCode);
163
+ const report = (descriptor) => {
164
+ ctx.report(clampDescriptor(descriptor));
165
+ };
166
+ const derivedSourceCode = Object.create(sourceCode, { getDisableDirectives: { value: () => {
167
+ const result = origGetDisableDirectives();
168
+ return {
169
+ ...result,
170
+ directives: sanitizeDirectiveList(result.directives, report)
171
+ };
172
+ } } });
173
+ const derivedContext = Object.create(context, { sourceCode: { value: derivedSourceCode } });
174
+ return wrapped.create(derivedContext);
175
+ }
176
+ };
177
+ }
178
+ const plugin = {
179
+ meta: { name: "eslint-comments" },
180
+ rules: Object.fromEntries(Object.entries(upstream.rules).map(([name, rule]) => [name, name === "no-restricted-disable" ? guardNoRestrictedDisable(rule) : wrapRule(rule)]))
181
+ };
182
+ export { clampLoc, plugin as default, parseRustDirective, wrapRule };
@@ -0,0 +1,59 @@
1
+ import { realpathSync } from "node:fs";
2
+ import path from "node:path";
3
+ // src/plugin/utils/paths.ts
4
+ function toPosix(p) {
5
+ return p.split(path.sep).join("/");
6
+ }
7
+ const realCache = /* @__PURE__ */ new Map();
8
+ function real(p) {
9
+ let cached = realCache.get(p);
10
+ if (cached === void 0) {
11
+ try {
12
+ cached = realpathSync(p);
13
+ } catch {
14
+ cached = p;
15
+ }
16
+ realCache.set(p, cached);
17
+ }
18
+ return cached;
19
+ }
20
+ /**
21
+ * Path of the linted file relative to the working directory the linter was started in (the
22
+ * repository root in CI and hooks), with forward slashes. Both linters report absolute paths, but
23
+ * one of them may have resolved symlinks (for example /tmp → /private/tmp on macOS).
24
+ */
25
+ function repoRelativePath(context) {
26
+ const cwd = context.cwd;
27
+ const file = path.isAbsolute(context.filename) ? context.filename : path.join(cwd, context.filename);
28
+ let rel = path.relative(cwd, file);
29
+ if (rel.startsWith("..")) rel = path.relative(real(cwd), real(file));
30
+ return toPosix(rel);
31
+ }
32
+ /**
33
+ * Compile repo-relative path patterns. Supported forms:
34
+ * - `dir/` — the directory and everything below it;
35
+ * - globs with `**` (any depth), `*` (one segment) and `?`; `dir/**` also matches `dir` itself;
36
+ * - anything else is an exact path.
37
+ */
38
+ function compilePathPatterns(patterns) {
39
+ const regexes = patterns.map(patternToRegExp);
40
+ return (rel) => regexes.some((re) => re.test(rel));
41
+ }
42
+ function patternToRegExp(pattern) {
43
+ const glob = pattern.endsWith("/") ? `${pattern}**` : pattern;
44
+ let out = "";
45
+ for (let i = 0; i < glob.length; i++) {
46
+ const ch = glob[i];
47
+ if (ch === "*") {
48
+ if (glob[i + 1] === "*") {
49
+ const slashAfter = glob[i + 2] === "/";
50
+ if (i + 2 === glob.length && out.endsWith("/")) out = `${out.slice(0, -1)}(?:/.*)?`;
51
+ else out += slashAfter ? "(?:.*/)?" : ".*";
52
+ i += slashAfter ? 2 : 1;
53
+ } else out += "[^/]*";
54
+ } else if (ch === "?") out += "[^/]";
55
+ else out += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
56
+ }
57
+ return new RegExp(`^${out}$`);
58
+ }
59
+ export { repoRelativePath as n, compilePathPatterns as t };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * A node handler. Declared through a method so that its parameter is checked bivariantly: each
3
+ * handler declares its concrete node type, and ESLint's and Oxlint's listener types accept it.
4
+ */
5
+ type NodeHandler = {
6
+ handle(node: unknown): void;
7
+ }["handle"];
8
+ type RuleListener = Record<string, NodeHandler>;
9
+ /** The parts of the rule context the od rules read. ESLint's and Oxlint's contexts have them. */
10
+ interface RuleContextLike {
11
+ readonly id: string;
12
+ readonly options: readonly unknown[];
13
+ readonly filename: string;
14
+ readonly cwd: string;
15
+ readonly sourceCode: object;
16
+ report(descriptor: object): void;
17
+ }
18
+ interface RuleMeta {
19
+ type: "problem" | "suggestion" | "layout";
20
+ docs: {
21
+ description: string;
22
+ url: string;
23
+ };
24
+ schema: readonly unknown[];
25
+ messages: Record<string, string>;
26
+ }
27
+ interface PluginRule {
28
+ meta: RuleMeta;
29
+ create(context: RuleContextLike): RuleListener;
30
+ }
31
+ interface Plugin {
32
+ meta: {
33
+ name: string;
34
+ version: string;
35
+ };
36
+ rules: Record<string, PluginRule>;
37
+ }
38
+ /** Kept in sync with package.json by test/plugin.test.ts. */
39
+ export declare const VERSION = "0.2.0-alpha.0";
40
+ declare const plugin: Plugin;
41
+ export { type Plugin, type PluginRule, type RuleContextLike, type RuleMeta, plugin as default };