@ls-stack/extended-lint 0.91.0 → 2.0.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
@@ -6,186 +6,33 @@ To use any of these rules, you need to install the package:
6
6
  pnpm add -D @lucasols/eslint-plugin-extended-lint
7
7
  ```
8
8
 
9
+ There is no `typescript` peer dependency (only an optional `eslint` one), so it works with any TypeScript version (including TypeScript 7) or none at all, and also as an [oxlint JS plugin](https://oxc.rs/docs/guide/usage/linter/js-plugins).
10
+
9
11
  And then configure it in your eslint config:
10
12
 
11
13
  ```json
12
14
  {
13
15
  "plugins": ["@lucasols/extended-lint"],
14
16
  "rules": {
15
- "@lucasols/extended-lint/no-unused-type-props-in-args": "error"
17
+ "@lucasols/extended-lint/<rule-name>": "error"
16
18
  }
17
19
  }
18
20
  ```
19
21
 
20
- ## `no-unused-type-props-in-args`
21
-
22
- Checks if there are unused type props in function arguments.
23
-
24
- Examples
25
-
26
- Bad
27
-
28
- ```ts
29
- function foo({ a }: { a: string; b: string }) {
30
- /* ^ b is declared but not used in the function */
31
- // ...
32
- }
33
- ```
34
-
35
- Good
36
-
37
- ```ts
38
- function foo({ a, b }: { a: string; b: string }) {
39
- // ...
40
- }
41
- ```
42
-
43
- It will also work with the react `FC` type:
44
-
45
- Bad
46
-
47
- ```ts
48
- const Foo: FC<{ a: string; b: string }> = ({ a }) => {
49
- /* ^ b is declared but not used in the component */
50
- // ...
51
- }
52
- ```
53
-
54
- Good
55
-
56
- ```
57
- const Foo: FC<{ a: string; b: string }> = ({ a, b }) => {
58
- // ...
59
- }
60
- ```
61
-
62
- - This rule will not work in all situations, as it does not checks all possible usages of referenced types.
63
-
64
- ## `no-commented-out-code`
65
-
66
- Checks if there are commented code. Block comments are ignored.
67
-
68
- Examples
69
-
70
- Bad:
71
-
72
- ```ts
73
- // function foo() {
74
- // // ...
75
- // }
76
- ```
77
-
78
- Good:
79
-
80
- ```ts
81
- /*
82
- function foo() {
83
- // ...
84
- }
85
- */
86
- ```
87
-
88
- - This rule will not detect all possible commented code, and can give false negatives.
89
-
90
- ## `no-call-with-infered-generics`
91
-
92
- This rule disallows calling functions with inferred generics.
93
-
94
- The rule options types are as follows:
95
-
96
- ````ts
97
- type Options = [
98
- {
99
- functions: Array<{
100
- name: string;
101
- minGenerics?: number;
102
- allowAny?: boolean;
103
- disallowTypes?: string[];
104
- }>;
105
- anyAliases?: string[];
106
- }
107
- ];
108
-
109
- Examples:
110
-
111
- Bad:
112
-
113
- ```ts
114
- // @typescript-eslint/no-call-with-inferred-generics: ["error", { functions: ["foo"] }]
115
-
116
- function foo<T>(arg: T) {
117
- // ...
118
- }
119
-
120
- foo('bar') // Error: Generics must be defined explicitly
121
- foo<any>('bar') // Error: 'any' is not allowed in generics
122
- ````
123
-
124
- Good:
125
-
126
- ```ts
127
- // @typescript-eslint/no-call-with-inferred-generics: ["error", { functions: ["foo"] }]
128
- function foo<T>(arg: T) {
129
- // ...
130
- }
131
-
132
- foo<string>('bar') // OK
133
- ```
134
-
135
- ## `rules-of-hooks`
136
-
137
- A fork of the `eslint-plugin-react-hooks` `rules-of-hooks` rule, but with the following changes:
138
-
139
- - Identifies hooks in camelCase namespaced functions (e.g. `test.useFoo()`)
140
-
141
- ## `strict-casting`
142
-
143
- Enforces safe and necessary `String()`/`Number()` casts. Replaces the deprecated `no-unnecessary-casting` rule.
144
-
145
- Checks performed:
146
-
147
- - **Unnecessary casts** (auto-fixable): casting a value that is already of the target type
148
- - **Nullish casts**: `String(value)` produces the strings `"null"`/`"undefined"`, and `Number(value)` produces `0` for `null` and `NaN` for `undefined`. A suggestion is provided to add a `?? ''`/`?? 0` fallback
149
- - **Invalid `Number()` casts**: casting a `symbol` (throws at runtime) or an object without a numeric `valueOf` (always results in `NaN`)
150
- - **`any`/`unknown` casts**: casting untyped values is unsafe, type or narrow the value before casting
151
-
152
- Bad:
153
-
154
- ```ts
155
- declare const str: string
156
- declare const nullable: string | null
157
- declare const obj: { a: string }
158
-
159
- String(str) // Error: unnecessary cast
160
- String(nullable) // Error: may produce "null"
161
- Number(obj) // Error: results in NaN
162
- ```
163
-
164
- Good:
165
-
166
- ```ts
167
- String(num)
168
- String(nullable ?? '')
169
- Number(date) // Date has a numeric valueOf
170
- ```
171
-
172
- Options:
173
-
174
- ```ts
175
- type Options = [
176
- {
177
- /** Extra functions checked for unnecessary casts */
178
- additionalCastFunctions?: { name: string; expectedType: 'string' | 'number' }[]
179
- /** Allow casting possibly nullish values (default: false) */
180
- allowNullishCasting?: boolean
181
- /** Allow symbol/object Number() casts (default: false) */
182
- allowInvalidCasting?: boolean
183
- /** Allow casting `any` values (default: false) */
184
- allowAnyCasting?: boolean
185
- /** Allow casting `unknown` values, e.g. `String(err)` in catch blocks (default: false) */
186
- allowUnknownCasting?: boolean
187
- },
188
- ]
189
- ```
190
-
191
- For `String(obj)` producing `"[object Object]"`, use `@typescript-eslint/no-base-to-string`, which covers that case well.
22
+ Rules are being migrated to [`@ls-stack/fast-lint`](../fast-lint), where these now live (same names and options, so
23
+ `@ls-stack/<rule>` configs and disable comments keep working there): `improved-no-unnecessary-condition`,
24
+ `strict-casting` (also replaces the removed `no-unnecessary-casting`), `no-unnecessary-void-on-promise`,
25
+ `advanced-no-restricted-syntax` (now `no-restricted-syntax`), `no-default-export`, `no-reexport`, `no-relative-imports`,
26
+ `no-sync-dynamic-import`, `no-leaked-text-in-jsx`, `no-static-style-prop`, `no-non-camel-case-functions`,
27
+ `prefer-named-functions`, `no-call-with-explicit-generics`, `no-call-with-inferred-generics`, `no-unnecessary-typing`,
28
+ `no-type-guards`, `use-state-setter-naming`, `require-lazy-execution`, `no-unnecessary-iife`, `require-description`,
29
+ `no-write-only-ref`, `no-commented-out-code`, `react-single-export`, `no-unused-optional-args`,
30
+ `no-unused-type-props-in-args`, `no-unused-t-state-field`, `no-unused-selected-values`, `no-optional-root-props`,
31
+ `no-redundant-function-params`, `react-no-module-level-single-use-values`, `require-reads-to-var-prop`,
32
+ `prefer-react-hook-alternative`, `sort-react-components-and-styles`, `use-types-directly-above-usage` and
33
+ `react-compiler-extra`. The `rules-of-hooks` and `exhaustive-deps` forks were removed; use `eslint-plugin-react-hooks`
34
+ (or oxlint's built-in rules) instead.
35
+
36
+ Remaining rules: `collapse-simple-objs-in-one-line`, `no-data-attributes-on-components`, `no-restricted-comments`,
37
+ `no-unnecessary-async-on-jsx-props`, `no-unnecessary-describe`, `no-unused-obj-props`, `react-compiler-migration`,
38
+ `require-usage-explanation`, `template-indent` and `use-top-level-regex`.
@@ -1,5 +1,14 @@
1
- import { TSESLint } from '@typescript-eslint/utils';
1
+ type ExtendedLintRuleListener = {
2
+ visit(node: unknown): void;
3
+ }['visit'];
4
+ type ExtendedLintRule = {
5
+ meta?: object;
6
+ create(context: never): Record<string, ExtendedLintRuleListener | undefined>;
7
+ };
2
8
 
3
- declare const extendedLintPlugin: TSESLint.FlatConfig.Plugin;
9
+ type ExtendedLintPlugin = {
10
+ rules: Record<string, ExtendedLintRule>;
11
+ };
12
+ declare const extendedLintPlugin: ExtendedLintPlugin;
4
13
 
5
- export { extendedLintPlugin as default, extendedLintPlugin };
14
+ export { type ExtendedLintPlugin, extendedLintPlugin as default, extendedLintPlugin };
@@ -1,5 +1,14 @@
1
- import { TSESLint } from '@typescript-eslint/utils';
1
+ type ExtendedLintRuleListener = {
2
+ visit(node: unknown): void;
3
+ }['visit'];
4
+ type ExtendedLintRule = {
5
+ meta?: object;
6
+ create(context: never): Record<string, ExtendedLintRuleListener | undefined>;
7
+ };
2
8
 
3
- declare const extendedLintPlugin: TSESLint.FlatConfig.Plugin;
9
+ type ExtendedLintPlugin = {
10
+ rules: Record<string, ExtendedLintRule>;
11
+ };
12
+ declare const extendedLintPlugin: ExtendedLintPlugin;
4
13
 
5
- export { extendedLintPlugin as default, extendedLintPlugin };
14
+ export { type ExtendedLintPlugin, extendedLintPlugin as default, extendedLintPlugin };