@sarj/eslint-plugin 16.4.3 → 16.4.5

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.
@@ -38,7 +38,7 @@ var import_node_os = require("os");
38
38
  var import_node_path = require("path");
39
39
  var parser = __toESM(require("@typescript-eslint/parser"), 1);
40
40
  var import_eslint = require("eslint");
41
- async function verifyRuleExamples(rule) {
41
+ async function verifyRuleExamples(rule, setup = {}) {
42
42
  const spec = rule.documentation;
43
43
  if (spec === void 0 || !spec.publicExamples.some((item) => item.outcome === "match") || !spec.publicExamples.some((item) => item.outcome === "no-match")) {
44
44
  throw new Error("rule requires documented public matching and non-matching examples");
@@ -51,6 +51,15 @@ async function verifyRuleExamples(rule) {
51
51
  await (0, import_promises.mkdir)((0, import_node_path.dirname)(path), { recursive: true });
52
52
  await (0, import_promises.writeFile)(path, file.source);
53
53
  }
54
+ for (const dependency of example.installedDependencies ?? []) {
55
+ if (setup.installedDependencyRoot === void 0) throw new Error(`${example.id}: explicit installed dependency root is required`);
56
+ const packageFile = fixturePath((0, import_node_path.resolve)(setup.installedDependencyRoot), `node_modules/${dependency.module}/package.json`);
57
+ const metadata = JSON.parse(await (0, import_promises.readFile)(packageFile, "utf8"));
58
+ if (typeof metadata !== "object" || metadata === null || !("name" in metadata) || !("version" in metadata) || metadata.name !== dependency.module || metadata.version !== dependency.version) throw new Error(`${example.id}: installed dependency identity/version mismatch for ${dependency.module}`);
59
+ const destination = fixturePath(root, `node_modules/${dependency.module}`);
60
+ await (0, import_promises.mkdir)((0, import_node_path.dirname)(destination), { recursive: true });
61
+ await (0, import_promises.symlink)((0, import_node_path.dirname)(packageFile), destination, process.platform === "win32" ? "junction" : "dir");
62
+ }
54
63
  const tsconfig = (0, import_node_path.join)(root, "tsconfig.json");
55
64
  if (!example.files.some((file) => file.path === "tsconfig.json")) {
56
65
  await (0, import_promises.writeFile)(tsconfig, JSON.stringify({ compilerOptions: {
@@ -68,10 +77,11 @@ async function verifyRuleExamples(rule) {
68
77
  files: ["**/*.{ts,tsx,js,jsx,mts,cts,mjs,cjs}"],
69
78
  languageOptions: { parser, parserOptions: { project: tsconfig, tsconfigRootDir: root } },
70
79
  plugins: { "@sarj": { rules: { [spec.ruleId]: rule } } },
71
- rules: { [ruleId]: ["error", ...rule.defaultOptions ?? []] }
80
+ rules: { [ruleId]: ["error", ...example.ruleOptions ?? rule.defaultOptions ?? []] }
72
81
  };
73
82
  await verifyExample(new import_eslint.Linter({ cwd: root }), config, example, root, ruleId);
74
83
  } finally {
84
+ parser.clearCaches();
75
85
  await (0, import_promises.rm)(root, { recursive: true, force: true });
76
86
  }
77
87
  }
@@ -1,7 +1,9 @@
1
- import { D as DocumentedRule } from './_docs-XCw_6XV9.cjs';
1
+ import { D as DocumentedRule } from './_docs-B9LZ5Out.cjs';
2
2
  import '@typescript-eslint/utils';
3
3
 
4
4
  /** Execute all authored examples, including private regressions, in isolated projects. */
5
- declare function verifyRuleExamples<Options extends readonly unknown[], MessageIds extends string>(rule: DocumentedRule<Options, MessageIds>): Promise<number>;
5
+ declare function verifyRuleExamples<Options extends readonly unknown[], MessageIds extends string>(rule: DocumentedRule<Options, MessageIds>, setup?: {
6
+ readonly installedDependencyRoot?: string;
7
+ }): Promise<number>;
6
8
 
7
9
  export { verifyRuleExamples };
@@ -1,7 +1,9 @@
1
- import { D as DocumentedRule } from './_docs-XCw_6XV9.js';
1
+ import { D as DocumentedRule } from './_docs-B9LZ5Out.js';
2
2
  import '@typescript-eslint/utils';
3
3
 
4
4
  /** Execute all authored examples, including private regressions, in isolated projects. */
5
- declare function verifyRuleExamples<Options extends readonly unknown[], MessageIds extends string>(rule: DocumentedRule<Options, MessageIds>): Promise<number>;
5
+ declare function verifyRuleExamples<Options extends readonly unknown[], MessageIds extends string>(rule: DocumentedRule<Options, MessageIds>, setup?: {
6
+ readonly installedDependencyRoot?: string;
7
+ }): Promise<number>;
6
8
 
7
9
  export { verifyRuleExamples };
@@ -1,10 +1,10 @@
1
1
  // src/verify-rule-examples.ts
2
- import { mkdtemp, mkdir, rm, writeFile } from "fs/promises";
2
+ import { mkdtemp, mkdir, rm, writeFile, readFile, symlink } from "fs/promises";
3
3
  import { tmpdir } from "os";
4
4
  import { dirname, join, resolve, sep } from "path";
5
5
  import * as parser from "@typescript-eslint/parser";
6
6
  import { Linter } from "eslint";
7
- async function verifyRuleExamples(rule) {
7
+ async function verifyRuleExamples(rule, setup = {}) {
8
8
  const spec = rule.documentation;
9
9
  if (spec === void 0 || !spec.publicExamples.some((item) => item.outcome === "match") || !spec.publicExamples.some((item) => item.outcome === "no-match")) {
10
10
  throw new Error("rule requires documented public matching and non-matching examples");
@@ -17,6 +17,15 @@ async function verifyRuleExamples(rule) {
17
17
  await mkdir(dirname(path), { recursive: true });
18
18
  await writeFile(path, file.source);
19
19
  }
20
+ for (const dependency of example.installedDependencies ?? []) {
21
+ if (setup.installedDependencyRoot === void 0) throw new Error(`${example.id}: explicit installed dependency root is required`);
22
+ const packageFile = fixturePath(resolve(setup.installedDependencyRoot), `node_modules/${dependency.module}/package.json`);
23
+ const metadata = JSON.parse(await readFile(packageFile, "utf8"));
24
+ if (typeof metadata !== "object" || metadata === null || !("name" in metadata) || !("version" in metadata) || metadata.name !== dependency.module || metadata.version !== dependency.version) throw new Error(`${example.id}: installed dependency identity/version mismatch for ${dependency.module}`);
25
+ const destination = fixturePath(root, `node_modules/${dependency.module}`);
26
+ await mkdir(dirname(destination), { recursive: true });
27
+ await symlink(dirname(packageFile), destination, process.platform === "win32" ? "junction" : "dir");
28
+ }
20
29
  const tsconfig = join(root, "tsconfig.json");
21
30
  if (!example.files.some((file) => file.path === "tsconfig.json")) {
22
31
  await writeFile(tsconfig, JSON.stringify({ compilerOptions: {
@@ -34,10 +43,11 @@ async function verifyRuleExamples(rule) {
34
43
  files: ["**/*.{ts,tsx,js,jsx,mts,cts,mjs,cjs}"],
35
44
  languageOptions: { parser, parserOptions: { project: tsconfig, tsconfigRootDir: root } },
36
45
  plugins: { "@sarj": { rules: { [spec.ruleId]: rule } } },
37
- rules: { [ruleId]: ["error", ...rule.defaultOptions ?? []] }
46
+ rules: { [ruleId]: ["error", ...example.ruleOptions ?? rule.defaultOptions ?? []] }
38
47
  };
39
48
  await verifyExample(new Linter({ cwd: root }), config, example, root, ruleId);
40
49
  } finally {
50
+ parser.clearCaches();
41
51
  await rm(root, { recursive: true, force: true });
42
52
  }
43
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sarj/eslint-plugin",
3
- "version": "16.4.3",
3
+ "version": "16.4.5",
4
4
  "packageManager": "npm@12.1.0",
5
5
  "description": "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
6
6
  "type": "module",
@@ -35,7 +35,7 @@
35
35
  "scripts": {
36
36
  "build": "tsup",
37
37
  "dogfood": "npm run build && npm run dogfood:built",
38
- "lint": "eslint . ../../.github/scripts --max-warnings 0",
38
+ "lint": "eslint . ../../.github/scripts ../standards/src ../standards/eslint.config.mjs --max-warnings 0",
39
39
  "prepack": "npm run build && npm run verify-package",
40
40
  "test": "vitest run",
41
41
  "typecheck": "tsc --noEmit",