@sarj/eslint-plugin 16.38.54 → 16.39.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/dist/{_docs-IZjowAEc.d.cts → _docs-_eXGTNOq.d.cts} +1 -1
- package/dist/{_docs-IZjowAEc.d.ts → _docs-_eXGTNOq.d.ts} +1 -1
- package/dist/index.cjs +565 -472
- package/dist/index.d.cts +34 -215
- package/dist/index.d.ts +34 -215
- package/dist/index.js +550 -457
- package/dist/rule-examples.cjs +6 -3
- package/dist/rule-examples.d.cts +5 -1
- package/dist/rule-examples.d.ts +5 -1
- package/dist/rule-examples.js +6 -3
- package/package.json +2 -1
package/dist/rule-examples.cjs
CHANGED
|
@@ -201,7 +201,7 @@ async function verifyRuleExamples(rule, setup = {}) {
|
|
|
201
201
|
plugins: { "@sarj": { rules: { [spec.ruleId]: rule } } },
|
|
202
202
|
rules: { [ruleId]: ["error", ...example.ruleOptions ?? rule.defaultOptions ?? []] }
|
|
203
203
|
};
|
|
204
|
-
await verifyExample(new import_eslint.Linter({ cwd: root }), config, example, root, ruleId);
|
|
204
|
+
await verifyExample(new import_eslint.Linter({ cwd: root }), config, example, root, ruleId, setup.formatFixedSource);
|
|
205
205
|
} finally {
|
|
206
206
|
parser2.clearCaches();
|
|
207
207
|
await (0, import_promises.rm)(root, { recursive: true, force: true });
|
|
@@ -225,7 +225,7 @@ function validateFixtureSyntax(exampleId, file, path) {
|
|
|
225
225
|
throw new Error(`${exampleId}: invalid fixture ${file.path}`, { cause: error });
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
async function verifyExample(linter, config, example, root, ruleId) {
|
|
228
|
+
async function verifyExample(linter, config, example, root, ruleId, formatFixedSource) {
|
|
229
229
|
const focus = example.files.find((file) => file.path === example.focusPath);
|
|
230
230
|
if (focus === void 0) throw new Error(`${example.id}: focus file is missing`);
|
|
231
231
|
const filename = fixturePath(root, focus.path);
|
|
@@ -257,12 +257,15 @@ async function verifyExample(linter, config, example, root, ruleId) {
|
|
|
257
257
|
if (input === void 0) throw new Error(`${example.id}: fixed file has no original`);
|
|
258
258
|
const options = { filename: fixturePath(root, input.path) };
|
|
259
259
|
const fixed = linter.verifyAndFix(input.source, config, options);
|
|
260
|
-
if (fixed.output !== expected.source) throw new Error(`${example.id}: unexpected fixed source`);
|
|
260
|
+
if (formatFixedSource === void 0 && fixed.output !== expected.source) throw new Error(`${example.id}: unexpected fixed source`);
|
|
261
261
|
await (0, import_promises.writeFile)(options.filename, fixed.output);
|
|
262
262
|
const repeated = linter.verifyAndFix(fixed.output, config, options);
|
|
263
263
|
if (repeated.fixed || repeated.output !== fixed.output || repeated.messages.length > 0) {
|
|
264
264
|
throw new Error(`${example.id}: fix is not clean and idempotent`);
|
|
265
265
|
}
|
|
266
|
+
if (formatFixedSource !== void 0 && await formatFixedSource({ path: input.path, source: fixed.output }, example) !== expected.source) {
|
|
267
|
+
throw new Error(`${example.id}: unexpected fixed source`);
|
|
268
|
+
}
|
|
266
269
|
}
|
|
267
270
|
}
|
|
268
271
|
function verifyExpectedDiagnostics(example, messages, source, lines) {
|
package/dist/rule-examples.d.cts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { E as ExampleFile, R as RuleExample } from './_docs-_eXGTNOq.cjs';
|
|
1
2
|
import { DocumentedRule } from './index.cjs';
|
|
2
3
|
import '@typescript-eslint/utils';
|
|
3
4
|
|
|
5
|
+
type FixedSourceFormatter = (file: ExampleFile, example: RuleExample) => string | Promise<string>;
|
|
4
6
|
/** Execute all authored examples, including private regressions, in isolated projects. */
|
|
5
7
|
declare function verifyRuleExamples<Options extends readonly unknown[], MessageIds extends string>(rule: DocumentedRule<Options, MessageIds>, setup?: {
|
|
6
8
|
readonly installedDependencyRoot?: string;
|
|
9
|
+
readonly formatFixedSource?: FixedSourceFormatter;
|
|
7
10
|
}): Promise<number>;
|
|
8
11
|
|
|
9
|
-
export { verifyRuleExamples };
|
|
12
|
+
export { ExampleFile, RuleExample, verifyRuleExamples };
|
|
13
|
+
export type { FixedSourceFormatter };
|
package/dist/rule-examples.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { E as ExampleFile, R as RuleExample } from './_docs-_eXGTNOq.js';
|
|
1
2
|
import { DocumentedRule } from './index.js';
|
|
2
3
|
import '@typescript-eslint/utils';
|
|
3
4
|
|
|
5
|
+
type FixedSourceFormatter = (file: ExampleFile, example: RuleExample) => string | Promise<string>;
|
|
4
6
|
/** Execute all authored examples, including private regressions, in isolated projects. */
|
|
5
7
|
declare function verifyRuleExamples<Options extends readonly unknown[], MessageIds extends string>(rule: DocumentedRule<Options, MessageIds>, setup?: {
|
|
6
8
|
readonly installedDependencyRoot?: string;
|
|
9
|
+
readonly formatFixedSource?: FixedSourceFormatter;
|
|
7
10
|
}): Promise<number>;
|
|
8
11
|
|
|
9
|
-
export { verifyRuleExamples };
|
|
12
|
+
export { ExampleFile, RuleExample, verifyRuleExamples };
|
|
13
|
+
export type { FixedSourceFormatter };
|
package/dist/rule-examples.js
CHANGED
|
@@ -167,7 +167,7 @@ async function verifyRuleExamples(rule, setup = {}) {
|
|
|
167
167
|
plugins: { "@sarj": { rules: { [spec.ruleId]: rule } } },
|
|
168
168
|
rules: { [ruleId]: ["error", ...example.ruleOptions ?? rule.defaultOptions ?? []] }
|
|
169
169
|
};
|
|
170
|
-
await verifyExample(new Linter({ cwd: root }), config, example, root, ruleId);
|
|
170
|
+
await verifyExample(new Linter({ cwd: root }), config, example, root, ruleId, setup.formatFixedSource);
|
|
171
171
|
} finally {
|
|
172
172
|
parser2.clearCaches();
|
|
173
173
|
await rm(root, { recursive: true, force: true });
|
|
@@ -191,7 +191,7 @@ function validateFixtureSyntax(exampleId, file, path) {
|
|
|
191
191
|
throw new Error(`${exampleId}: invalid fixture ${file.path}`, { cause: error });
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
async function verifyExample(linter, config, example, root, ruleId) {
|
|
194
|
+
async function verifyExample(linter, config, example, root, ruleId, formatFixedSource) {
|
|
195
195
|
const focus = example.files.find((file) => file.path === example.focusPath);
|
|
196
196
|
if (focus === void 0) throw new Error(`${example.id}: focus file is missing`);
|
|
197
197
|
const filename = fixturePath(root, focus.path);
|
|
@@ -223,12 +223,15 @@ async function verifyExample(linter, config, example, root, ruleId) {
|
|
|
223
223
|
if (input === void 0) throw new Error(`${example.id}: fixed file has no original`);
|
|
224
224
|
const options = { filename: fixturePath(root, input.path) };
|
|
225
225
|
const fixed = linter.verifyAndFix(input.source, config, options);
|
|
226
|
-
if (fixed.output !== expected.source) throw new Error(`${example.id}: unexpected fixed source`);
|
|
226
|
+
if (formatFixedSource === void 0 && fixed.output !== expected.source) throw new Error(`${example.id}: unexpected fixed source`);
|
|
227
227
|
await writeFile(options.filename, fixed.output);
|
|
228
228
|
const repeated = linter.verifyAndFix(fixed.output, config, options);
|
|
229
229
|
if (repeated.fixed || repeated.output !== fixed.output || repeated.messages.length > 0) {
|
|
230
230
|
throw new Error(`${example.id}: fix is not clean and idempotent`);
|
|
231
231
|
}
|
|
232
|
+
if (formatFixedSource !== void 0 && await formatFixedSource({ path: input.path, source: fixed.output }, example) !== expected.source) {
|
|
233
|
+
throw new Error(`${example.id}: unexpected fixed source`);
|
|
234
|
+
}
|
|
232
235
|
}
|
|
233
236
|
}
|
|
234
237
|
function verifyExpectedDiagnostics(example, messages, source, lines) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sarj/eslint-plugin",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.39.0",
|
|
4
4
|
"packageManager": "npm@12.2.1",
|
|
5
5
|
"description": "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
6
6
|
"type": "module",
|
|
@@ -88,6 +88,7 @@
|
|
|
88
88
|
"eslint-plugin-zod": "^5.2.2",
|
|
89
89
|
"globals": "17.13.0",
|
|
90
90
|
"jiti": "2.7.0",
|
|
91
|
+
"prettier": "3.9.10",
|
|
91
92
|
"tsup": "9.0.0",
|
|
92
93
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
93
94
|
"typescript-eslint": "^8.72.0",
|