eslint-plugin-what 0.12.3 → 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/index.d.ts ADDED
@@ -0,0 +1,90 @@
1
+ // eslint-plugin-what — TypeScript definitions.
2
+ //
3
+ // Declared by hand and held to the runtime by `npm run hygiene:types`. The
4
+ // plugin is a default export, so the parity checker sees one name; the shapes
5
+ // below are what a flat config actually consumes.
6
+ //
7
+ // ESLint's own types are not imported: `eslint` is a peer dependency, and
8
+ // pulling @types/eslint in here would make a type-only package a hard
9
+ // requirement for anyone who just wants to spread a preset into their config.
10
+
11
+ /** One rule module. Structural, so a stock ESLint `Rule.RuleModule` assigns to it. */
12
+ export interface WhatRuleModule {
13
+ meta: {
14
+ type?: 'problem' | 'suggestion' | 'layout';
15
+ docs?: { description?: string; recommended?: boolean; url?: string };
16
+ fixable?: 'code' | 'whitespace';
17
+ schema?: unknown[];
18
+ messages?: Record<string, string>;
19
+ [key: string]: unknown;
20
+ };
21
+ create(context: unknown): Record<string, (...args: never[]) => void>;
22
+ }
23
+
24
+ /** The rules this plugin ships, keyed exactly as they are referenced in config. */
25
+ export interface WhatRules {
26
+ /** Signals are read by calling them; listing one in a deps array compares functions, not values. */
27
+ 'no-signal-in-effect-deps': WhatRuleModule;
28
+ /** A signal passed as a JSX child renders once unless it stays reactive. */
29
+ 'reactive-jsx-children': WhatRuleModule;
30
+ /** Writing a signal during render re-enters render. */
31
+ 'no-signal-write-in-render': WhatRuleModule;
32
+ /** DOM events are lowercase; `onClick` on an intrinsic element never fires. */
33
+ 'no-camelcase-events': WhatRuleModule;
34
+ /** `set(next)` over read-modify-write, which races concurrent updates. */
35
+ 'prefer-set': WhatRuleModule;
36
+ /** A signal referenced without calling it yields the function, not its value. */
37
+ 'no-uncalled-signals': WhatRuleModule;
38
+ /** `h()` is the compiler's output, not an authoring API. */
39
+ 'no-h-in-user-code': WhatRuleModule;
40
+ /** A signal in JSX must be called to be read. */
41
+ 'signal-call-in-jsx': WhatRuleModule;
42
+ /** A computed that writes a signal is a side effect pretending to be a value. */
43
+ 'no-set-in-computed': WhatRuleModule;
44
+ }
45
+
46
+ /**
47
+ * A complete flat-config entry. Each preset carries its own `files` glob and
48
+ * JSX-enabled language options, so spreading one into a config array works
49
+ * against stock ESLint with no extra parser setup for .js/.jsx.
50
+ */
51
+ export interface WhatFlatConfig {
52
+ name: string;
53
+ files: string[];
54
+ languageOptions: {
55
+ ecmaVersion: 'latest' | number;
56
+ sourceType: 'module' | 'script';
57
+ parserOptions?: { ecmaFeatures?: { jsx?: boolean }; [key: string]: unknown };
58
+ /**
59
+ * Only the `compiler` preset sets this, declaring the control-flow tags
60
+ * the What compiler lowers itself (`For`, `Show`, `Switch`, `Match`).
61
+ * Under the compiler they need no import; without it they must be
62
+ * imported, so the other presets leave `no-undef` free to say so.
63
+ */
64
+ globals?: Record<string, 'readonly' | 'writable' | 'off'>;
65
+ [key: string]: unknown;
66
+ };
67
+ plugins: Record<string, WhatPlugin>;
68
+ rules: Record<string, 'off' | 'warn' | 'error'>;
69
+ }
70
+
71
+ export interface WhatConfigs {
72
+ /** Everything on as warnings, except no-set-in-computed, which is always an error. */
73
+ recommended: WhatFlatConfig;
74
+ /** Everything on as errors, plus prefer-set as a warning. */
75
+ strict: WhatFlatConfig;
76
+ /**
77
+ * For compiler users: the rules the compiler already handles are off, and
78
+ * the compiler-lowered control-flow tags are declared as globals.
79
+ */
80
+ compiler: WhatFlatConfig;
81
+ }
82
+
83
+ export interface WhatPlugin {
84
+ meta: { name: string; version: string };
85
+ rules: WhatRules;
86
+ configs: WhatConfigs;
87
+ }
88
+
89
+ declare const plugin: WhatPlugin;
90
+ export default plugin;
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "eslint-plugin-what",
3
- "version": "0.12.3",
3
+ "version": "0.13.0",
4
4
  "description": "ESLint rules for What Framework — catch signal bugs, enforce patterns",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
+ "types": "index.d.ts",
7
8
  "exports": {
8
- ".": "./src/index.js"
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "default": "./src/index.js"
12
+ }
9
13
  },
10
14
  "files": [
11
- "src"
15
+ "src",
16
+ "index.d.ts"
12
17
  ],
13
18
  "keywords": [
14
19
  "eslint",
package/src/index.js CHANGED
@@ -65,6 +65,20 @@ const baseLanguageOptions = {
65
65
 
66
66
  const FILES = ['**/*.{js,jsx,ts,tsx}'];
67
67
 
68
+ // Control-flow tags the What compiler lowers itself rather than resolving as
69
+ // components (LOWERED_TAGS in what-compiler's babel plugin). Under the
70
+ // compiler they need no import, so `no-undef` would otherwise report every
71
+ // <For>, <Show>, <Switch> and <Match> in a compiled file as undefined.
72
+ //
73
+ // Only the `compiler` preset declares them. Without the compiler these really
74
+ // must be imported from what-framework, and reporting that is correct.
75
+ const COMPILER_LOWERED_TAGS = {
76
+ For: 'readonly',
77
+ Show: 'readonly',
78
+ Switch: 'readonly',
79
+ Match: 'readonly',
80
+ };
81
+
68
82
  plugin.configs.recommended = {
69
83
  name: 'what/recommended',
70
84
  files: FILES,
@@ -106,7 +120,7 @@ plugin.configs.strict = {
106
120
  plugin.configs.compiler = {
107
121
  name: 'what/compiler',
108
122
  files: FILES,
109
- languageOptions: baseLanguageOptions,
123
+ languageOptions: { ...baseLanguageOptions, globals: COMPILER_LOWERED_TAGS },
110
124
  plugins: { what: plugin },
111
125
  rules: {
112
126
  'what/no-signal-in-effect-deps': 'warn',
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * Warn when user code imports `h` from what-framework.
5
5
  * Users should use JSX syntax instead of calling h() directly.
6
- * The compiler handles JSX-to-h() transformation automatically.
6
+ * The compiler lowers JSX to _$template() + _$insert() + _$createComponent(),
7
+ * not to h(). h() is the uncompiled fallback and the framework's own internal
8
+ * element constructor.
7
9
  *
8
10
  * Bad: import { h } from 'what-framework';
9
11
  * h('div', { class: 'foo' }, 'Hello');