@opendesignai/harness 0.1.0-alpha.0 → 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.
- package/README.md +17 -12
- package/dist/cli.mjs +1438 -95
- package/dist/eslint-comments.d.mts +17 -1
- package/dist/eslint-comments.mjs +134 -2
- package/dist/plugin.d.mts +20 -4
- package/dist/plugin.mjs +429 -59
- package/docs/adopting.md +84 -17
- package/docs/baseline-move.md +56 -0
- package/docs/clones.md +51 -0
- package/docs/decisions/0003-agent-harness.md +37 -0
- package/docs/hooks.md +128 -0
- package/docs/ratchet.md +25 -9
- package/docs/rules/no-api-path-literal.md +1 -1
- package/docs/rules/no-cjk-literal.md +1 -1
- package/docs/rules/no-error-message-match.md +11 -3
- package/docs/rules/no-locale-branch.md +9 -5
- package/docs/rules/no-process-env.md +11 -1
- package/docs/rules/no-product-literal.md +6 -0
- package/docs/rules/no-raw-storage.md +4 -2
- package/docs/rules/no-shell-imports-product.md +4 -2
- package/docs/rules/no-swallowed-catch.md +5 -4
- package/docs/size.md +1 -0
- package/docs/unused.md +76 -0
- package/package.json +6 -4
- package/presets/rules/base.json +5 -3
|
@@ -6,8 +6,12 @@ type Loc = Position | {
|
|
|
6
6
|
start: Position;
|
|
7
7
|
end?: Position | null;
|
|
8
8
|
};
|
|
9
|
+
interface UpstreamRuleMeta {
|
|
10
|
+
messages?: Record<string, string>;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
9
13
|
interface UpstreamRule {
|
|
10
|
-
meta?:
|
|
14
|
+
meta?: UpstreamRuleMeta;
|
|
11
15
|
create(context: object): object;
|
|
12
16
|
}
|
|
13
17
|
export interface WrappedPlugin {
|
|
@@ -16,8 +20,20 @@ export interface WrappedPlugin {
|
|
|
16
20
|
};
|
|
17
21
|
rules: Record<string, UpstreamRule>;
|
|
18
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
|
+
}
|
|
19
29
|
/** Moves negative columns to 0; a negative start becomes a zero-width location at column 0. */
|
|
20
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;
|
|
21
37
|
/** The rule with `context.report` locations passed through `clampLoc`. */
|
|
22
38
|
export declare function wrapRule(rule: UpstreamRule): UpstreamRule;
|
|
23
39
|
declare const plugin: WrappedPlugin;
|
package/dist/eslint-comments.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import upstream from "@eslint-community/eslint-plugin-eslint-comments";
|
|
2
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 = /^(?:[/\\]|\.\.?(?:$|[/\\]))/;
|
|
3
7
|
function atColumnZero(position) {
|
|
4
8
|
return {
|
|
5
9
|
line: position.line,
|
|
@@ -32,6 +36,99 @@ function clampDescriptor(descriptor) {
|
|
|
32
36
|
loc: clampLoc(loc)
|
|
33
37
|
};
|
|
34
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
|
+
}
|
|
35
132
|
/** The rule with `context.report` locations passed through `clampLoc`. */
|
|
36
133
|
function wrapRule(rule) {
|
|
37
134
|
return {
|
|
@@ -43,8 +140,43 @@ function wrapRule(rule) {
|
|
|
43
140
|
}
|
|
44
141
|
};
|
|
45
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
|
+
}
|
|
46
178
|
const plugin = {
|
|
47
179
|
meta: { name: "eslint-comments" },
|
|
48
|
-
rules: Object.fromEntries(Object.entries(upstream.rules).map(([name, rule]) => [name, wrapRule(rule)]))
|
|
180
|
+
rules: Object.fromEntries(Object.entries(upstream.rules).map(([name, rule]) => [name, name === "no-restricted-disable" ? guardNoRestrictedDisable(rule) : wrapRule(rule)]))
|
|
49
181
|
};
|
|
50
|
-
export { clampLoc, plugin as default, wrapRule };
|
|
182
|
+
export { clampLoc, plugin as default, parseRustDirective, wrapRule };
|
package/dist/plugin.d.mts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
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
|
+
}
|
|
2
18
|
interface RuleMeta {
|
|
3
19
|
type: "problem" | "suggestion" | "layout";
|
|
4
20
|
docs: {
|
|
@@ -10,7 +26,7 @@ interface RuleMeta {
|
|
|
10
26
|
}
|
|
11
27
|
interface PluginRule {
|
|
12
28
|
meta: RuleMeta;
|
|
13
|
-
create(context:
|
|
29
|
+
create(context: RuleContextLike): RuleListener;
|
|
14
30
|
}
|
|
15
31
|
interface Plugin {
|
|
16
32
|
meta: {
|
|
@@ -20,6 +36,6 @@ interface Plugin {
|
|
|
20
36
|
rules: Record<string, PluginRule>;
|
|
21
37
|
}
|
|
22
38
|
/** Kept in sync with package.json by test/plugin.test.ts. */
|
|
23
|
-
export declare const VERSION = "0.
|
|
39
|
+
export declare const VERSION = "0.2.0-alpha.0";
|
|
24
40
|
declare const plugin: Plugin;
|
|
25
|
-
export { type Plugin, type PluginRule, type RuleMeta, plugin as default };
|
|
41
|
+
export { type Plugin, type PluginRule, type RuleContextLike, type RuleMeta, plugin as default };
|