@pragmatiks/lint 0.11.0 → 0.13.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## js-v0.13.0 (2026-11-29)
4
+
5
+ ### Features
6
+
7
+ - **rules**: add pra-no-underscore-members for principle 13
8
+
9
+ ## js-v0.12.0 (2026-11-20)
10
+
11
+ ### Bug Fixes
12
+
13
+ - **js**: compose the unit-test bans with the consumer's base config and ban require() and import() of I/O modules (PRA-1002)
14
+ - **js**: keep the Next bans in the unit-test config and close its I/O gaps (PRA-1002)
15
+
16
+ ### Features
17
+
18
+ - **js**: export the unit-test bans as pragmatiksUnitTestConfig (PRA-1002)
19
+
3
20
  ## js-v0.11.0 (2026-11-20)
4
21
 
5
22
  ### Features
package/README.md CHANGED
@@ -63,6 +63,23 @@ export default [...pragmatiksConfig(), pragmatiksCssConfig()];
63
63
 
64
64
  `pragmatiksNextConfig` already includes it.
65
65
 
66
+ ## `@pragmatiks/lint/eslint-config/unit-test`
67
+
68
+ The unit-test config, one object for `tests/unit/**` that bans the vi mock, stub and fake-timer helpers (`vi.mock`, `vi.doMock`, `vi.spyOn`, `vi.fn`, `vi.stubGlobal`, `vi.stubEnv`, `vi.useFakeTimers`, `vi.setSystemTime`), `msw`, the Node I/O modules (`fs`, `fs/promises`, `child_process`, `net`, `http`, `https`, `http2`, `dgram`, `dns`, `tls`, `process`, `worker_threads`, bare and `node:`) and the globals `fetch`, `XMLHttpRequest`, `WebSocket`, `EventSource` and `process`, bare or through `globalThis`, `window` or `self`. Unit tests cover pure decisions with real inputs. It sets `no-restricted-properties`, `no-restricted-imports` and `no-restricted-globals` for those files, and bans `require()` and `import()` of those modules through `no-restricted-syntax`, so place it last. A later flat config replaces a rule's options, so a Next app uses `pragmatiksNextUnitTestConfig` from `@pragmatiks/lint/eslint-config/next` instead, which keeps the Next config's restricted imports, properties and syntax:
69
+
70
+ ```ts
71
+ import { pragmatiksConfig } from "@pragmatiks/lint";
72
+ import { pragmatiksUnitTestConfig } from "@pragmatiks/lint/eslint-config/unit-test";
73
+
74
+ export default [...pragmatiksConfig(), pragmatiksUnitTestConfig()];
75
+ ```
76
+
77
+ ```ts
78
+ import { pragmatiksNextConfig, pragmatiksNextUnitTestConfig } from "@pragmatiks/lint/eslint-config/next";
79
+
80
+ export default [...(await pragmatiksNextConfig(options)), pragmatiksNextUnitTestConfig()];
81
+ ```
82
+
66
83
  ## `@pragmatiks/lint/eslint-config/next`
67
84
 
68
85
  In the app's `eslint.config.mjs`:
@@ -40,6 +40,13 @@ interface PragmatiksNextOptions extends DesignSystemSource {
40
40
  * recommended preset, when a peer or Tailwind package is missing or their versions differ, when
41
41
  * the stylesheet cannot be read, or when the Tailwind API or canary check fails.
42
42
  */
43
+ /**
44
+ * Builds the unit-test bans for a Next app, keeping this config's restricted imports,
45
+ * properties and syntax, which a later flat config would otherwise replace.
46
+ *
47
+ * @returns The `pragmatiksUnitTestConfig` object carrying the Next bans.
48
+ */
49
+ declare function pragmatiksNextUnitTestConfig(): Linter.Config;
43
50
  declare function pragmatiksNextConfig(nextConfigs: readonly Linter.Config[], options: PragmatiksNextOptions): Promise<Linter.Config[]>;
44
51
 
45
- export { type PragmatiksNextOptions, pragmatiksNextConfig };
52
+ export { type PragmatiksNextOptions, pragmatiksNextConfig, pragmatiksNextUnitTestConfig };
@@ -250,6 +250,79 @@ function pragmatiksConfig() {
250
250
  globalIgnores(["dist/**", "node_modules/**", ".next/**", ".turbo/**"])
251
251
  ]);
252
252
  }
253
+
254
+ // src/eslint-config/unit-test/index.ts
255
+ var PRAGMATIKS_UNIT_TEST_FILES = ["tests/unit/**"];
256
+ var MOCK_MESSAGE = "Unit tests use no mocks, stubs or fakes; test a pure decision with real inputs.";
257
+ var IO_MESSAGE = "Unit tests perform no I/O; test a pure decision with real inputs.";
258
+ var BANNED_VI_PROPERTIES = [
259
+ "mock",
260
+ "doMock",
261
+ "spyOn",
262
+ "fn",
263
+ "stubGlobal",
264
+ "stubEnv",
265
+ "useFakeTimers",
266
+ "setSystemTime"
267
+ ];
268
+ var BANNED_NODE_MODULES = [
269
+ "fs",
270
+ "fs/promises",
271
+ "child_process",
272
+ "net",
273
+ "http",
274
+ "https",
275
+ "dgram",
276
+ "dns",
277
+ "dns/promises",
278
+ "http2",
279
+ "tls",
280
+ "process",
281
+ "worker_threads"
282
+ ];
283
+ var BANNED_GLOBALS = ["fetch", "XMLHttpRequest", "WebSocket", "EventSource", "process"];
284
+ var GLOBAL_OBJECTS = ["globalThis", "window", "self"];
285
+ var SLASH = String.raw`\u002F`;
286
+ var MODULE_PATTERN = `/^((node:)?(${BANNED_NODE_MODULES.map((module) => module.replace("/", SLASH)).join("|")})|msw(${SLASH}.*)?)$/`;
287
+ var DYNAMIC_LOAD_SYNTAX = [
288
+ {
289
+ selector: `CallExpression[callee.name="require"] > Literal.arguments[value=${MODULE_PATTERN}]`,
290
+ message: IO_MESSAGE
291
+ },
292
+ { selector: `ImportExpression > Literal.source[value=${MODULE_PATTERN}]`, message: IO_MESSAGE }
293
+ ];
294
+ function pragmatiksUnitTestConfig(inherited = {}) {
295
+ return {
296
+ name: "pragmatiks/unit-test",
297
+ files: PRAGMATIKS_UNIT_TEST_FILES,
298
+ rules: {
299
+ "no-restricted-properties": [
300
+ "error",
301
+ ...inherited.properties ?? [],
302
+ ...BANNED_VI_PROPERTIES.map((property) => ({ object: "vi", property, message: MOCK_MESSAGE })),
303
+ ...GLOBAL_OBJECTS.flatMap(
304
+ (object) => BANNED_GLOBALS.map((property) => ({ object, property, message: IO_MESSAGE }))
305
+ )
306
+ ],
307
+ "no-restricted-imports": [
308
+ "error",
309
+ {
310
+ paths: [
311
+ ...inherited.imports?.paths ?? [],
312
+ { name: "msw", message: MOCK_MESSAGE },
313
+ ...BANNED_NODE_MODULES.flatMap((module) => [
314
+ { name: module, message: IO_MESSAGE },
315
+ { name: `node:${module}`, message: IO_MESSAGE }
316
+ ])
317
+ ],
318
+ patterns: [...inherited.imports?.patterns ?? [], { group: ["msw/*"], message: MOCK_MESSAGE }]
319
+ }
320
+ ],
321
+ "no-restricted-syntax": ["error", ...inherited.syntax ?? [], ...DYNAMIC_LOAD_SYNTAX],
322
+ "no-restricted-globals": ["error", ...BANNED_GLOBALS.map((name) => ({ name, message: IO_MESSAGE }))]
323
+ }
324
+ };
325
+ }
253
326
  var CSS_WIDE_KEYWORDS = new Set(
254
327
  lexer.cssWideKeywords
255
328
  );
@@ -2545,7 +2618,6 @@ var TYPED_FILES = ["**/*.{ts,tsx,mts}"];
2545
2618
  var THREE_DOTS_PATTERN = String.raw`/[A-Za-z]\.\.\./`;
2546
2619
  var ELLIPSIS_MESSAGE = "Write the ellipsis glyph \u2026 instead of three dots.";
2547
2620
  var ZOOM_MESSAGE = "Never disable zoom in the viewport export.";
2548
- var FORWARD_REF_MESSAGE = "Pass ref as a prop; React 19 does not need forwardRef.";
2549
2621
  var URL_ATTRIBUTE = String.raw`JSXAttribute[name.name=/^(href|src|action)$/]`;
2550
2622
  var ELLIPSIS_EXEMPT_LITERAL = [
2551
2623
  `${URL_ATTRIBUTE} Literal`,
@@ -2555,6 +2627,7 @@ var ELLIPSIS_EXEMPT_LITERAL = [
2555
2627
  "ImportExpression > Literal"
2556
2628
  ].join(", ");
2557
2629
  var PRESET_RECOVERY = "To fix it, pass [...nextVitals, ...nextTs] from eslint-config-next";
2630
+ var FORWARD_REF_MESSAGE = "Pass ref as a prop; React 19 does not need forwardRef.";
2558
2631
  var ICON_FAMILY = "@phosphor-icons/react";
2559
2632
  var ICON_PACKAGES = [
2560
2633
  "lucide-react",
@@ -2568,6 +2641,26 @@ var ICON_PACKAGES = [
2568
2641
  "@mui/icons-material",
2569
2642
  "@mui/icons-material/*"
2570
2643
  ];
2644
+ var NEXT_RESTRICTED_IMPORTS = {
2645
+ paths: [
2646
+ {
2647
+ name: "react",
2648
+ importNames: ["forwardRef"],
2649
+ message: FORWARD_REF_MESSAGE
2650
+ }
2651
+ ],
2652
+ patterns: [
2653
+ {
2654
+ group: ICON_PACKAGES,
2655
+ message: `Use ${ICON_FAMILY}, the project's one icon family.`
2656
+ }
2657
+ ]
2658
+ };
2659
+ var NEXT_RESTRICTED_PROPERTIES = {
2660
+ object: "React",
2661
+ property: "forwardRef",
2662
+ message: FORWARD_REF_MESSAGE
2663
+ };
2571
2664
  var RESTRICTED_SYNTAX = [
2572
2665
  {
2573
2666
  selector: `JSXText[value=${THREE_DOTS_PATTERN}]`,
@@ -2602,26 +2695,6 @@ var RESTRICTED_SYNTAX = [
2602
2695
  message: "Replace placeholder content with real copy."
2603
2696
  }
2604
2697
  ];
2605
- var RESTRICTED_IMPORTS = {
2606
- paths: [
2607
- {
2608
- name: "react",
2609
- importNames: ["forwardRef"],
2610
- message: FORWARD_REF_MESSAGE
2611
- }
2612
- ],
2613
- patterns: [
2614
- {
2615
- group: ICON_PACKAGES,
2616
- message: `Use ${ICON_FAMILY}, the project's one icon family.`
2617
- }
2618
- ]
2619
- };
2620
- var RESTRICTED_PROPERTIES = {
2621
- object: "React",
2622
- property: "forwardRef",
2623
- message: FORWARD_REF_MESSAGE
2624
- };
2625
2698
  function isIgnoreOnly(config) {
2626
2699
  return Object.keys(config).every(
2627
2700
  (key) => key === "ignores" || key === "name"
@@ -2685,8 +2758,8 @@ function buildFrontendConfig(accessibilityConfig, plugin, rules) {
2685
2758
  ...buildAccessibilityRules(accessibilityConfig),
2686
2759
  ...buildRuleEntries(Object.keys(rules.javascript)),
2687
2760
  "no-restricted-syntax": ["error", ...RESTRICTED_SYNTAX],
2688
- "no-restricted-imports": ["error", RESTRICTED_IMPORTS],
2689
- "no-restricted-properties": ["error", RESTRICTED_PROPERTIES],
2761
+ "no-restricted-imports": ["error", NEXT_RESTRICTED_IMPORTS],
2762
+ "no-restricted-properties": ["error", NEXT_RESTRICTED_PROPERTIES],
2690
2763
  "no-alert": "error",
2691
2764
  "unicorn/filename-case": ["error", FILENAME_CASE_OPTIONS],
2692
2765
  "unicorn/no-useless-undefined": ["error", NO_USELESS_UNDEFINED_OPTIONS]
@@ -2714,6 +2787,13 @@ function buildCssConfig(plugin, rules) {
2714
2787
  rules: buildRuleEntries(Object.keys(rules.css))
2715
2788
  };
2716
2789
  }
2790
+ function pragmatiksNextUnitTestConfig() {
2791
+ return pragmatiksUnitTestConfig({
2792
+ imports: NEXT_RESTRICTED_IMPORTS,
2793
+ properties: [NEXT_RESTRICTED_PROPERTIES],
2794
+ syntax: RESTRICTED_SYNTAX
2795
+ });
2796
+ }
2717
2797
  async function pragmatiksNextConfig(nextConfigs, options) {
2718
2798
  const accessibilityConfig = findAccessibilityConfig(nextConfigs);
2719
2799
  const view = await loadDesignSystem(options);
@@ -2729,6 +2809,6 @@ async function pragmatiksNextConfig(nextConfigs, options) {
2729
2809
  ];
2730
2810
  }
2731
2811
 
2732
- export { pragmatiksNextConfig };
2812
+ export { pragmatiksNextConfig, pragmatiksNextUnitTestConfig };
2733
2813
  //# sourceMappingURL=index.js.map
2734
2814
  //# sourceMappingURL=index.js.map