@tsrx/eslint-plugin 0.6.3 → 0.7.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 CHANGED
@@ -8,18 +8,27 @@ ESLint rules and flat configurations for target-neutral TSRX syntax.
8
8
  ## Installation
9
9
 
10
10
  ```bash
11
- pnpm add --save-dev eslint @tsrx/eslint-parser @tsrx/eslint-plugin
11
+ pnpm add --save-dev eslint @eslint/js @tsrx/eslint-parser @tsrx/eslint-plugin
12
12
  ```
13
13
 
14
14
  ## Usage
15
15
 
16
16
  ```js
17
17
  // eslint.config.js
18
+ import js from '@eslint/js';
18
19
  import tsrx from '@tsrx/eslint-plugin';
19
20
 
20
- export default [...tsrx.configs.recommended];
21
+ export default [
22
+ js.configs.recommended,
23
+ ...tsrx.configs.recommended,
24
+ ...tsrx.configs.js,
25
+ ];
21
26
  ```
22
27
 
28
+ List `tsrx.configs.js` after any configuration that turns on core `no-unused-vars`
29
+ or `no-unreachable`, such as `js.configs.recommended`. See
30
+ [With `js.configs.recommended`](#with-jsconfigsrecommended).
31
+
23
32
  The recommended configuration:
24
33
 
25
34
  - uses `@tsrx/eslint-parser` for `.tsrx` files when installed;
@@ -35,13 +44,111 @@ import tsrx from '@tsrx/eslint-plugin';
35
44
  export default [...tsrx.configs.strict];
36
45
  ```
37
46
 
47
+ ### With eslint-plugin-react
48
+
49
+ `react/jsx-curly-brace-presence` unwraps strings that TSRX text reads as syntax,
50
+ so its `--fix` can break a `.tsrx` file. The `react` configuration turns it off
51
+ for `.tsrx` files and turns on `tsrx/jsx-curly-brace-presence`, which keeps those
52
+ braces. List it after eslint-plugin-react's configurations, or a later one turns
53
+ the react rule back on:
54
+
55
+ ```js
56
+ // eslint.config.js
57
+ import react from 'eslint-plugin-react';
58
+ import tsrx from '@tsrx/eslint-plugin';
59
+
60
+ export default [
61
+ react.configs.flat.recommended,
62
+ ...tsrx.configs.recommended,
63
+ ...tsrx.configs.react,
64
+ ];
65
+ ```
66
+
67
+ `react.configs.flat.recommended` doesn't turn on `react/jsx-curly-brace-presence`,
68
+ so with it, `tsrx.configs.react` adds `tsrx/jsx-curly-brace-presence` as a new
69
+ rule at `error` rather than swapping one in. Leave `tsrx.configs.react` out if you
70
+ don't want the rule. To pass options, set them on `tsrx/jsx-curly-brace-presence`,
71
+ after `tsrx.configs.react`.
72
+
38
73
  ## Rules
39
74
 
40
75
  - `tsrx/control-flow-jsx` requires template output in returned `@for` blocks.
41
76
  - `tsrx/require-statement-container-body` detects component bodies that need the
42
77
  `@{ ... }` statement-container marker.
43
78
  - `tsrx/valid-for-of-key` validates identifiers used in TSRX loop keys.
79
+ - `tsrx/jsx-curly-brace-presence` is `react/jsx-curly-brace-presence`, with the
80
+ same options and messages, for TSRX text. It doesn't unwrap a child that TSRX
81
+ would read differently: a directive such as `{'@for (item of items)'}`, a
82
+ comment such as `{'// note'}`, text that would join a comment or a directive
83
+ clause beside it, or the first child of a `<style>`. To tell, it parses the
84
+ element around a child whose text could be TSRX syntax, before and after the
85
+ unwrap, with the file's parser. Inside an expression container it parses the
86
+ top-level statement, for at most 50 children per file, and keeps the braces past
87
+ that. Each fix spans the text beside the child, so fixes that would touch the
88
+ same text go in separate passes of one `--fix` run. See
89
+ [With eslint-plugin-react](#with-eslint-plugin-react).
44
90
  - `tsrx/no-return-in-component` is a deprecated no-op retained for compatibility.
91
+ - `tsrx/no-unused-vars` is ESLint's `no-unused-vars`, except that its suggestion
92
+ for an unused `@for` index removes the whole `; index i` clause. The core rule's
93
+ suggestion deletes only the name and leaves `index )`, which doesn't parse.
94
+ - `tsrx/no-await-in-loop` is ESLint's `no-await-in-loop`, and also reports an
95
+ `await` in a `@for` key, which runs once per item, as the body does.
96
+ - `tsrx/no-unreachable` is ESLint's `no-unreachable`, with the arms of a `@switch`
97
+ as alternatives. After an arm that throws, it doesn't report the other arms or
98
+ the code after the `@switch`. It still reports unreachable code inside an arm:
99
+ there it follows `throw`, `return`, `break`, `continue`, `try` and endless loops
100
+ itself, since code path analysis has already given up on the arm. It can miss
101
+ unreachable code there when a `break`, `continue` or `return` passes through a
102
+ `finally` block. In generated arms with heavy `try`/`finally`, label and loop
103
+ nesting, it missed some unreachable code in about 1 in 120 (0.8%), and reported
104
+ nothing the core rule doesn't report on the same code in a plain function. Like
105
+ the core rule, it reports the `@pending` and `@catch` of a `@try` whose body
106
+ throws, and the code after the `@try`, in an arm or not, as the
107
+ [`@tsrx/eslint-parser` README](https://github.com/tsrx-org/tsrx/tree/main/packages/eslint-parser#known-limitations)
108
+ explains.
109
+
110
+ ### With `js.configs.recommended`
111
+
112
+ `js.configs.recommended` turns on `no-unused-vars` and `no-unreachable`. The `js`
113
+ configuration turns those two off for `.tsrx` files and turns on
114
+ `tsrx/no-unused-vars` and `tsrx/no-unreachable` at `error`. Every other report and
115
+ suggestion is the core rule's, except in the code `tsrx/no-unreachable` revives
116
+ after a `@switch` arm that throws, the other arms and the code after the
117
+ `@switch`, where it follows exits itself. A configuration can't read the severity
118
+ or options another one gives the core rule, so:
119
+
120
+ - list `tsrx.configs.js` after `js.configs.recommended`, and after any other
121
+ configuration that turns these core rules on. Listed before them, it leaves both
122
+ versions on for `.tsrx` files, and each problem is reported twice;
123
+ - on its own, without `js.configs.recommended`, it turns the two TSRX rules on;
124
+ - give `tsrx/no-unused-vars` the options you give `no-unused-vars`, and set a
125
+ `tsrx/` rule to `warn` or `off` to change its severity;
126
+ - name the TSRX rule in `eslint-disable` comments in `.tsrx` files:
127
+ `// eslint-disable-next-line tsrx/no-unused-vars`.
128
+
129
+ `js.configs.recommended` leaves `no-await-in-loop` off, so no configuration turns
130
+ on `tsrx/no-await-in-loop`. If you turn on `no-await-in-loop`, use
131
+ `tsrx/no-await-in-loop` for `.tsrx` files instead:
132
+
133
+ ```js
134
+ import js from '@eslint/js';
135
+ import tsrx from '@tsrx/eslint-plugin';
136
+
137
+ export default [
138
+ js.configs.recommended,
139
+ ...tsrx.configs.recommended,
140
+ ...tsrx.configs.js,
141
+ { rules: { 'no-await-in-loop': 'error' } },
142
+ {
143
+ files: ['**/*.tsrx'],
144
+ rules: {
145
+ 'tsrx/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
146
+ 'no-await-in-loop': 'off',
147
+ 'tsrx/no-await-in-loop': 'error',
148
+ },
149
+ },
150
+ ];
151
+ ```
45
152
 
46
153
  Target runtime rules do not belong in the shared recommended configuration. For
47
154
  example, Ripple-specific `track()` placement and DOM event guidance should be
package/dist/index.d.ts CHANGED
@@ -9,6 +9,10 @@ declare const plugin: {
9
9
  'control-flow-jsx': import("eslint").Rule.RuleModule;
10
10
  'valid-for-of-key': import("eslint").Rule.RuleModule;
11
11
  'require-statement-container-body': import("eslint").Rule.RuleModule;
12
+ 'jsx-curly-brace-presence': import("eslint").Rule.RuleModule;
13
+ 'no-unused-vars': import("eslint").Rule.RuleModule;
14
+ 'no-await-in-loop': import("eslint").Rule.RuleModule;
15
+ 'no-unreachable': import("eslint").Rule.RuleModule;
12
16
  };
13
17
  configs: any;
14
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";cAMM;;;;;;;;;;;EAWU"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";cAUM;;;;;;;;;;;;;;;EAeU"}