@siim-m/config 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +57 -2
- package/dist/anti-slop/LICENSE +21 -0
- package/dist/anti-slop/effect/baseline.d.ts +18 -0
- package/dist/anti-slop/effect/baseline.js +41 -0
- package/dist/anti-slop/effect/index.d.ts +3 -0
- package/dist/anti-slop/effect/index.js +16 -0
- package/dist/anti-slop/effect/rules/no-manual-effect-error-tag.d.ts +1 -0
- package/dist/anti-slop/effect/rules/no-manual-effect-error-tag.js +39 -0
- package/dist/anti-slop/effect/rules/no-service-constructor-imports.d.ts +2 -0
- package/dist/anti-slop/effect/rules/no-service-constructor-imports.js +44 -0
- package/dist/anti-slop/effect/rules/no-service-parameters.d.ts +2 -0
- package/dist/anti-slop/effect/rules/no-service-parameters.js +181 -0
- package/dist/anti-slop/effect/rules/prefer-effect-match.d.ts +1 -0
- package/dist/anti-slop/effect/rules/prefer-effect-match.js +48 -0
- package/dist/anti-slop/effect/shared/tagged-values.d.ts +8 -0
- package/dist/anti-slop/effect/shared/tagged-values.js +68 -0
- package/dist/anti-slop/index.d.ts +3 -0
- package/dist/anti-slop/index.js +42 -0
- package/dist/anti-slop/rules/no-chained-type-assertions.d.ts +2 -0
- package/dist/anti-slop/rules/no-chained-type-assertions.js +60 -0
- package/dist/anti-slop/rules/no-conditional-empty-object-spread.d.ts +2 -0
- package/dist/anti-slop/rules/no-conditional-empty-object-spread.js +40 -0
- package/dist/anti-slop/rules/no-known-value-widening.d.ts +2 -0
- package/dist/anti-slop/rules/no-known-value-widening.js +300 -0
- package/dist/anti-slop/rules/no-module-mocking.d.ts +2 -0
- package/dist/anti-slop/rules/no-module-mocking.js +69 -0
- package/dist/anti-slop/rules/no-object-parameters.d.ts +2 -0
- package/dist/anti-slop/rules/no-object-parameters.js +56 -0
- package/dist/anti-slop/rules/no-reduce-accumulator-copy.d.ts +2 -0
- package/dist/anti-slop/rules/no-reduce-accumulator-copy.js +99 -0
- package/dist/anti-slop/rules/no-reflect-apply.d.ts +2 -0
- package/dist/anti-slop/rules/no-reflect-apply.js +25 -0
- package/dist/anti-slop/rules/no-reflect-get.d.ts +2 -0
- package/dist/anti-slop/rules/no-reflect-get.js +25 -0
- package/dist/anti-slop/rules/no-runtime-typeof.d.ts +2 -0
- package/dist/anti-slop/rules/no-runtime-typeof.js +64 -0
- package/dist/anti-slop/rules/no-unknown-parameters.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-parameters.js +51 -0
- package/dist/anti-slop/rules/no-unknown-returns.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-returns.js +58 -0
- package/dist/anti-slop/rules/no-unknown-type-aliases.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-type-aliases.js +40 -0
- package/dist/anti-slop/rules/no-unsafe-dictionary-type.d.ts +2 -0
- package/dist/anti-slop/rules/no-unsafe-dictionary-type.js +134 -0
- package/dist/anti-slop/rules/no-widen-then-assert.d.ts +2 -0
- package/dist/anti-slop/rules/no-widen-then-assert.js +270 -0
- package/dist/anti-slop/rules/require-pascal-case-namespace-imports.d.ts +8 -0
- package/dist/anti-slop/rules/require-pascal-case-namespace-imports.js +36 -0
- package/dist/anti-slop/rules/require-readable-spacing.d.ts +3 -0
- package/dist/anti-slop/rules/require-readable-spacing.js +65 -0
- package/dist/anti-slop/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
- package/dist/anti-slop/rules/require-safety-comment-for-type-assertion.js +100 -0
- package/dist/anti-slop/shared/array-method.d.ts +12 -0
- package/dist/anti-slop/shared/array-method.js +84 -0
- package/dist/anti-slop/shared/dictionary-types.d.ts +20 -0
- package/dist/anti-slop/shared/dictionary-types.js +377 -0
- package/dist/anti-slop/shared/function-parameters.d.ts +8 -0
- package/dist/anti-slop/shared/function-parameters.js +40 -0
- package/dist/anti-slop/shared/lexical-type-parameters.d.ts +5 -0
- package/dist/anti-slop/shared/lexical-type-parameters.js +47 -0
- package/dist/anti-slop/shared/reflect-method.d.ts +3 -0
- package/dist/anti-slop/shared/reflect-method.js +20 -0
- package/dist/anti-slop/shared/scope.d.ts +3 -0
- package/dist/anti-slop/shared/scope.js +11 -0
- package/dist/anti-slop/shared/type-alias-resolution.d.ts +23 -0
- package/dist/anti-slop/shared/type-alias-resolution.js +162 -0
- package/dist/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-ast.d.ts +27 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-ast.js +28 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.d.ts +37 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.js +703 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-options.d.ts +87 -0
- package/dist/anti-slop-react/LICENSE +21 -0
- package/dist/anti-slop-react/index.d.ts +3 -0
- package/dist/anti-slop-react/index.js +14 -0
- package/dist/anti-slop-react/rules/no-hookless-use-function.d.ts +8 -0
- package/dist/anti-slop-react/rules/no-hookless-use-function.js +67 -0
- package/dist/anti-slop-react/rules/no-manual-memo.d.ts +7 -0
- package/dist/anti-slop-react/rules/no-manual-memo.js +58 -0
- package/dist/anti-slop-react/rules/require-sync-comment-for-effect.d.ts +8 -0
- package/dist/anti-slop-react/rules/require-sync-comment-for-effect.js +64 -0
- package/dist/oxfmt.d.ts +27 -0
- package/dist/oxfmt.js +19 -0
- package/dist/oxlint-react.d.ts +62 -0
- package/dist/oxlint-react.js +62 -0
- package/dist/oxlint.d.ts +44 -0
- package/dist/oxlint.js +44 -0
- package/package.json +63 -4
- package/reset.d.ts +4 -0
- package/tsconfig.base.json +148 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* GENERATED, DO NOT EDIT DIRECTLY */
|
|
2
|
+
|
|
3
|
+
/* @checksum: 3QCTtOH6rJM5_AGJ58rGpeEaBEfaJz17MSCxWB4X_PU */
|
|
4
|
+
|
|
5
|
+
export type PaddingType = 'any' | 'never' | 'always'
|
|
6
|
+
export type StatementOption =
|
|
7
|
+
| StatementMatcher
|
|
8
|
+
| [StatementMatcher, ...StatementMatcher[]]
|
|
9
|
+
export type StatementMatcher =
|
|
10
|
+
| StatementType
|
|
11
|
+
| SelectorOption
|
|
12
|
+
export type StatementType =
|
|
13
|
+
| '*'
|
|
14
|
+
| 'exports'
|
|
15
|
+
| 'require'
|
|
16
|
+
| 'directive'
|
|
17
|
+
| 'iife'
|
|
18
|
+
| 'block'
|
|
19
|
+
| 'empty'
|
|
20
|
+
| 'function'
|
|
21
|
+
| 'ts-method'
|
|
22
|
+
| 'break'
|
|
23
|
+
| 'case'
|
|
24
|
+
| 'class'
|
|
25
|
+
| 'continue'
|
|
26
|
+
| 'debugger'
|
|
27
|
+
| 'default'
|
|
28
|
+
| 'do'
|
|
29
|
+
| 'for'
|
|
30
|
+
| 'if'
|
|
31
|
+
| 'import'
|
|
32
|
+
| 'switch'
|
|
33
|
+
| 'throw'
|
|
34
|
+
| 'try'
|
|
35
|
+
| 'while'
|
|
36
|
+
| 'with'
|
|
37
|
+
| 'cjs-export'
|
|
38
|
+
| 'cjs-import'
|
|
39
|
+
| 'enum'
|
|
40
|
+
| 'interface'
|
|
41
|
+
| 'function-overload'
|
|
42
|
+
| 'block-like'
|
|
43
|
+
| 'singleline-block-like'
|
|
44
|
+
| 'multiline-block-like'
|
|
45
|
+
| 'expression'
|
|
46
|
+
| 'singleline-expression'
|
|
47
|
+
| 'multiline-expression'
|
|
48
|
+
| 'return'
|
|
49
|
+
| 'singleline-return'
|
|
50
|
+
| 'multiline-return'
|
|
51
|
+
| 'export'
|
|
52
|
+
| 'singleline-export'
|
|
53
|
+
| 'multiline-export'
|
|
54
|
+
| 'var'
|
|
55
|
+
| 'singleline-var'
|
|
56
|
+
| 'multiline-var'
|
|
57
|
+
| 'let'
|
|
58
|
+
| 'singleline-let'
|
|
59
|
+
| 'multiline-let'
|
|
60
|
+
| 'const'
|
|
61
|
+
| 'singleline-const'
|
|
62
|
+
| 'multiline-const'
|
|
63
|
+
| 'using'
|
|
64
|
+
| 'singleline-using'
|
|
65
|
+
| 'multiline-using'
|
|
66
|
+
| 'type'
|
|
67
|
+
| 'singleline-type'
|
|
68
|
+
| 'multiline-type'
|
|
69
|
+
export type PaddingLineBetweenStatementsSchema0 = {
|
|
70
|
+
blankLine: PaddingType
|
|
71
|
+
prev: StatementOption
|
|
72
|
+
next: StatementOption
|
|
73
|
+
}[]
|
|
74
|
+
|
|
75
|
+
export interface SelectorOption {
|
|
76
|
+
selector: string
|
|
77
|
+
lineMode?: 'any' | 'singleline' | 'multiline'
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type PaddingLineBetweenStatementsRuleOptions
|
|
81
|
+
= PaddingLineBetweenStatementsSchema0
|
|
82
|
+
|
|
83
|
+
export type RuleOptions
|
|
84
|
+
= PaddingLineBetweenStatementsRuleOptions
|
|
85
|
+
export type MessageIds =
|
|
86
|
+
| 'unexpectedBlankLine'
|
|
87
|
+
| 'expectedBlankLine'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 T3 Tools Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { eslintCompatPlugin } from '@oxlint/plugins';
|
|
2
|
+
import { noHooklessUseFunctionRule } from './rules/no-hookless-use-function.js';
|
|
3
|
+
import { noManualMemoRule } from './rules/no-manual-memo.js';
|
|
4
|
+
import { requireSyncCommentForEffectRule } from './rules/require-sync-comment-for-effect.js';
|
|
5
|
+
/** Oxlint rules for React code that the React Compiler compiles. */
|
|
6
|
+
const antiSlopReactPlugin = eslintCompatPlugin({
|
|
7
|
+
meta: { name: 'anti-slop-react' },
|
|
8
|
+
rules: {
|
|
9
|
+
'no-hookless-use-function': noHooklessUseFunctionRule,
|
|
10
|
+
'no-manual-memo': noManualMemoRule,
|
|
11
|
+
'require-sync-comment-for-effect': requireSyncCommentForEffectRule,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
export default antiSlopReactPlugin;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disallow `use*` functions that call no hook during their own body. React treats the name as
|
|
3
|
+
* a hook, and the React Compiler only memoizes functions that call one, so whatever a hook-less
|
|
4
|
+
* `use*` function returns is rebuilt on every render. From T3 Code's rule of the same name,
|
|
5
|
+
* which mirrors eslint-react's `no-unnecessary-use-prefix`; this one tracks hook calls through
|
|
6
|
+
* oxlint's traversal instead of walking each function's body.
|
|
7
|
+
*/
|
|
8
|
+
export declare const noHooklessUseFunctionRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { defineRule } from '@oxlint/plugins';
|
|
2
|
+
const HOOK_NAME = /^use[A-Z]/;
|
|
3
|
+
// Bare `use` is React 19's `use(promise | context)`, which is a hook call too.
|
|
4
|
+
const HOOK_CALLEE = /^use([A-Z]|$)/;
|
|
5
|
+
function isHookCall(callee) {
|
|
6
|
+
if (callee.type === 'Identifier')
|
|
7
|
+
return HOOK_CALLEE.test(callee.name);
|
|
8
|
+
return (callee.type === 'MemberExpression' && !callee.computed && HOOK_CALLEE.test(callee.property.name));
|
|
9
|
+
}
|
|
10
|
+
/** The name a function is declared or assigned under, as `function useX` or `const useX = () =>`. */
|
|
11
|
+
function functionName(node) {
|
|
12
|
+
if (node.type === 'FunctionDeclaration')
|
|
13
|
+
return node.id ?? undefined;
|
|
14
|
+
const parent = node.parent;
|
|
15
|
+
if (parent.type === 'VariableDeclarator' &&
|
|
16
|
+
parent.init === node &&
|
|
17
|
+
parent.id.type === 'Identifier') {
|
|
18
|
+
return parent.id;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Disallow `use*` functions that call no hook during their own body. React treats the name as
|
|
24
|
+
* a hook, and the React Compiler only memoizes functions that call one, so whatever a hook-less
|
|
25
|
+
* `use*` function returns is rebuilt on every render. From T3 Code's rule of the same name,
|
|
26
|
+
* which mirrors eslint-react's `no-unnecessary-use-prefix`; this one tracks hook calls through
|
|
27
|
+
* oxlint's traversal instead of walking each function's body.
|
|
28
|
+
*/
|
|
29
|
+
export const noHooklessUseFunctionRule = defineRule({
|
|
30
|
+
meta: {
|
|
31
|
+
type: 'problem',
|
|
32
|
+
docs: {
|
|
33
|
+
description: 'Disallow use* functions that call no hooks.',
|
|
34
|
+
},
|
|
35
|
+
messages: {
|
|
36
|
+
noHook: '"{{name}}" calls no hooks, so the React Compiler skips it and whatever it returns is rebuilt on every render. Rename it to a plain function, or read the hook it depends on inside it.',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
createOnce(context) {
|
|
40
|
+
// One entry per function being visited: whether its own body, outside nested functions,
|
|
41
|
+
// calls a hook.
|
|
42
|
+
const callsHook = [];
|
|
43
|
+
const enter = () => {
|
|
44
|
+
callsHook.push(false);
|
|
45
|
+
};
|
|
46
|
+
const exit = (node) => {
|
|
47
|
+
const called = callsHook.pop();
|
|
48
|
+
const name = functionName(node);
|
|
49
|
+
if (called === true || name === undefined || !HOOK_NAME.test(name.name))
|
|
50
|
+
return;
|
|
51
|
+
context.report({ node: name, messageId: 'noHook', data: { name: name.name } });
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
FunctionDeclaration: enter,
|
|
55
|
+
FunctionExpression: enter,
|
|
56
|
+
ArrowFunctionExpression: enter,
|
|
57
|
+
'FunctionDeclaration:exit': exit,
|
|
58
|
+
'FunctionExpression:exit': exit,
|
|
59
|
+
'ArrowFunctionExpression:exit': exit,
|
|
60
|
+
CallExpression(node) {
|
|
61
|
+
if (callsHook.length > 0 && isHookCall(node.callee)) {
|
|
62
|
+
callsHook[callsHook.length - 1] = true;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disallow `useMemo`, `useCallback` and the compiler's memo directives. The React Compiler
|
|
3
|
+
* memoizes components and hooks itself, so manual memoization is noise, and a directive
|
|
4
|
+
* hides the code the compiler withheld a cache scope from. From T3 Code's rule of the same name,
|
|
5
|
+
* without its `allowMemoHooks` option.
|
|
6
|
+
*/
|
|
7
|
+
export declare const noManualMemoRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { defineRule } from '@oxlint/plugins';
|
|
2
|
+
const MEMO_HOOKS = new Set(['useCallback', 'useMemo']);
|
|
3
|
+
// "use no memo" and "use no forget" skip a function the compiler would bail on, which hides
|
|
4
|
+
// the bailout as much as "use memo" does.
|
|
5
|
+
const OPT_OUT_DIRECTIVES = new Set(['use no memo', 'use no forget']);
|
|
6
|
+
function memoHookName(callee) {
|
|
7
|
+
if (callee.type === 'Identifier')
|
|
8
|
+
return MEMO_HOOKS.has(callee.name) ? callee.name : undefined;
|
|
9
|
+
if (callee.type === 'MemberExpression' &&
|
|
10
|
+
!callee.computed &&
|
|
11
|
+
callee.object.type === 'Identifier' &&
|
|
12
|
+
callee.object.name === 'React' &&
|
|
13
|
+
MEMO_HOOKS.has(callee.property.name)) {
|
|
14
|
+
return callee.property.name;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Disallow `useMemo`, `useCallback` and the compiler's memo directives. The React Compiler
|
|
20
|
+
* memoizes components and hooks itself, so manual memoization is noise, and a directive
|
|
21
|
+
* hides the code the compiler withheld a cache scope from. From T3 Code's rule of the same name,
|
|
22
|
+
* without its `allowMemoHooks` option.
|
|
23
|
+
*/
|
|
24
|
+
export const noManualMemoRule = defineRule({
|
|
25
|
+
meta: {
|
|
26
|
+
type: 'suggestion',
|
|
27
|
+
docs: {
|
|
28
|
+
description: 'Disallow useMemo, useCallback and memo directives; the React Compiler memoizes components and hooks.',
|
|
29
|
+
},
|
|
30
|
+
messages: {
|
|
31
|
+
memoHook: 'Drop {{name}}: the React Compiler memoizes this. Write the plain value or function.',
|
|
32
|
+
useMemoDirective: 'Drop "use memo": restructure so the compiler caches this on its own, for example by moving plain uses of a value before the hook call that splits its scope, or by inlining the helper.',
|
|
33
|
+
optOutDirective: 'Drop "{{directive}}": fix the code the compiler cannot prove safe instead of skipping it.',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
createOnce(context) {
|
|
37
|
+
return {
|
|
38
|
+
ExpressionStatement(node) {
|
|
39
|
+
if (node.directive === 'use memo') {
|
|
40
|
+
context.report({ node, messageId: 'useMemoDirective' });
|
|
41
|
+
}
|
|
42
|
+
else if (typeof node.directive === 'string' && OPT_OUT_DIRECTIVES.has(node.directive)) {
|
|
43
|
+
context.report({
|
|
44
|
+
node,
|
|
45
|
+
messageId: 'optOutDirective',
|
|
46
|
+
data: { directive: node.directive },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
CallExpression(node) {
|
|
51
|
+
const name = memoHookName(node.callee);
|
|
52
|
+
if (name === undefined)
|
|
53
|
+
return;
|
|
54
|
+
context.report({ node: node.callee, messageId: 'memoHook', data: { name } });
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Require a `SYNC:` comment above every `useEffect`, `useLayoutEffect` and
|
|
3
|
+
* `useInsertionEffect`, naming what outside React the effect keeps in step. Most effects
|
|
4
|
+
* should be a derivation during render or an event handler instead, and the message walks
|
|
5
|
+
* through those first. Adapted from T3 Code's `no-unreasoned-state-sync`, which asks for a
|
|
6
|
+
* disable comment with a reason instead, and skips test files.
|
|
7
|
+
*/
|
|
8
|
+
export declare const requireSyncCommentForEffectRule: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { defineRule } from '@oxlint/plugins';
|
|
2
|
+
const EFFECT_HOOKS = new Set(['useEffect', 'useLayoutEffect', 'useInsertionEffect']);
|
|
3
|
+
const SYNC_COMMENT = /(?:^|[^\p{L}\p{N}_])SYNC\s*:\s*\S/u;
|
|
4
|
+
const statementKinds = new Set(['ExpressionStatement', 'ReturnStatement', 'VariableDeclaration']);
|
|
5
|
+
function isEffectHookCall(callee) {
|
|
6
|
+
if (callee.type === 'Identifier')
|
|
7
|
+
return EFFECT_HOOKS.has(callee.name);
|
|
8
|
+
return (callee.type === 'MemberExpression' && !callee.computed && EFFECT_HOOKS.has(callee.property.name));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Require a `SYNC:` comment above every `useEffect`, `useLayoutEffect` and
|
|
12
|
+
* `useInsertionEffect`, naming what outside React the effect keeps in step. Most effects
|
|
13
|
+
* should be a derivation during render or an event handler instead, and the message walks
|
|
14
|
+
* through those first. Adapted from T3 Code's `no-unreasoned-state-sync`, which asks for a
|
|
15
|
+
* disable comment with a reason instead, and skips test files.
|
|
16
|
+
*/
|
|
17
|
+
export const requireSyncCommentForEffectRule = defineRule({
|
|
18
|
+
meta: {
|
|
19
|
+
type: 'suggestion',
|
|
20
|
+
docs: {
|
|
21
|
+
description: 'Require a SYNC comment naming what outside React each effect hook keeps in step.',
|
|
22
|
+
},
|
|
23
|
+
messages: {
|
|
24
|
+
missingSyncComment: 'Stop and reconsider before keeping this effect. ' +
|
|
25
|
+
'Is it computable from props or state? Compute it during render; the compiler memoizes it. ' +
|
|
26
|
+
'Does it respond to a user action? Do it in that handler. ' +
|
|
27
|
+
'Does it reset state when a prop changes? Key the component on that prop. ' +
|
|
28
|
+
'Does it tell a parent or store that a value changed? Do it where the change happens. ' +
|
|
29
|
+
'Does it read a value from outside React? Use useSyncExternalStore or the data library. ' +
|
|
30
|
+
'An effect that sets state another effect reads is one handler or one derivation. ' +
|
|
31
|
+
'An effect is right only when it keeps something outside React in step with this component while mounted: ' +
|
|
32
|
+
'a DOM node, listener, timer, connection, third-party widget, or a resource held until unmount. ' +
|
|
33
|
+
'Moving the same logic into a ref or store to avoid this rule is not a fix. ' +
|
|
34
|
+
'If the effect does that, name what it keeps in step in a comment above it: `// SYNC: <what and why>`.',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
createOnce(context) {
|
|
38
|
+
const hasSyncCommentBefore = (node) => context.sourceCode.getCommentsBefore(node).some((c) => SYNC_COMMENT.test(c.value));
|
|
39
|
+
/**
|
|
40
|
+
* A SYNC comment before the call, before any node between it and its statement, or before
|
|
41
|
+
* the `export` that declares that statement.
|
|
42
|
+
*/
|
|
43
|
+
const hasSyncComment = (node) => {
|
|
44
|
+
let current = node;
|
|
45
|
+
while (true) {
|
|
46
|
+
if (hasSyncCommentBefore(current))
|
|
47
|
+
return true;
|
|
48
|
+
if (statementKinds.has(current.type)) {
|
|
49
|
+
return (current.parent.type === 'ExportNamedDeclaration' && hasSyncCommentBefore(current.parent));
|
|
50
|
+
}
|
|
51
|
+
if (current.parent.type === 'Program')
|
|
52
|
+
return false;
|
|
53
|
+
current = current.parent;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
CallExpression(node) {
|
|
58
|
+
if (!isEffectHookCall(node.callee) || hasSyncComment(node))
|
|
59
|
+
return;
|
|
60
|
+
context.report({ node, messageId: 'missingSyncComment' });
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
});
|
package/dist/oxfmt.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared oxfmt settings. oxfmt has no `extends`, so spread them in `oxfmt.config.mts` and
|
|
3
|
+
* set the repo's own values after the spread:
|
|
4
|
+
*
|
|
5
|
+
* export default { ...base, singleQuote: false, ignorePatterns: [...] }
|
|
6
|
+
*
|
|
7
|
+
* `overrides` is an array, so a repo that sets it replaces the Svelte entry below.
|
|
8
|
+
*/
|
|
9
|
+
declare const base: {
|
|
10
|
+
useTabs: false;
|
|
11
|
+
singleQuote: true;
|
|
12
|
+
trailingComma: "es5";
|
|
13
|
+
printWidth: number;
|
|
14
|
+
proseWrap: "always";
|
|
15
|
+
singleAttributePerLine: true;
|
|
16
|
+
sortImports: {
|
|
17
|
+
newlinesBetween: false;
|
|
18
|
+
};
|
|
19
|
+
overrides: {
|
|
20
|
+
files: string[];
|
|
21
|
+
options: {
|
|
22
|
+
svelte: true;
|
|
23
|
+
sortTailwindcss: true;
|
|
24
|
+
};
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
export default base;
|
package/dist/oxfmt.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared oxfmt settings. oxfmt has no `extends`, so spread them in `oxfmt.config.mts` and
|
|
3
|
+
* set the repo's own values after the spread:
|
|
4
|
+
*
|
|
5
|
+
* export default { ...base, singleQuote: false, ignorePatterns: [...] }
|
|
6
|
+
*
|
|
7
|
+
* `overrides` is an array, so a repo that sets it replaces the Svelte entry below.
|
|
8
|
+
*/
|
|
9
|
+
const base = {
|
|
10
|
+
useTabs: false,
|
|
11
|
+
singleQuote: true,
|
|
12
|
+
trailingComma: 'es5',
|
|
13
|
+
printWidth: 100,
|
|
14
|
+
proseWrap: 'always',
|
|
15
|
+
singleAttributePerLine: true,
|
|
16
|
+
sortImports: { newlinesBetween: false },
|
|
17
|
+
overrides: [{ files: ['**/*.svelte'], options: { svelte: true, sortTailwindcss: true } }],
|
|
18
|
+
};
|
|
19
|
+
export default base;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React preset, for code the React Compiler compiles. Extend it after the base preset:
|
|
3
|
+
*
|
|
4
|
+
* export default defineConfig({ extends: [base, react] })
|
|
5
|
+
*
|
|
6
|
+
* The base preset's `correctness` category also turns on the react and jsx-a11y plugins'
|
|
7
|
+
* correctness rules, which include the React Compiler's checks (`react/purity`, `react/refs`,
|
|
8
|
+
* `react/set-state-in-effect` and others). The rules below come from other categories.
|
|
9
|
+
*/
|
|
10
|
+
declare const preset: {
|
|
11
|
+
plugins: ("jsx-a11y" | "react")[];
|
|
12
|
+
jsPlugins: {
|
|
13
|
+
name: string;
|
|
14
|
+
specifier: string;
|
|
15
|
+
}[];
|
|
16
|
+
rules: {
|
|
17
|
+
'anti-slop-react/no-hookless-use-function': "error";
|
|
18
|
+
'anti-slop-react/no-manual-memo': "error";
|
|
19
|
+
'anti-slop-react/require-sync-comment-for-effect': "error";
|
|
20
|
+
'react/rules-of-hooks': "error";
|
|
21
|
+
'react/rule-suppression': "error";
|
|
22
|
+
'react/capitalized-calls': "error";
|
|
23
|
+
'react/unsupported-syntax': "error";
|
|
24
|
+
'react/only-export-components': ["error", {
|
|
25
|
+
allowConstantExport: true;
|
|
26
|
+
}];
|
|
27
|
+
'react/prefer-function-component': "error";
|
|
28
|
+
'react/no-array-index-key': "error";
|
|
29
|
+
'react/hook-use-state': "error";
|
|
30
|
+
'react/display-name': "error";
|
|
31
|
+
'react/no-react-children': "error";
|
|
32
|
+
'react/no-clone-element': "error";
|
|
33
|
+
'react/button-has-type': "error";
|
|
34
|
+
'react/jsx-no-target-blank': ["error", {
|
|
35
|
+
forms: true;
|
|
36
|
+
}];
|
|
37
|
+
'react/jsx-no-script-url': "error";
|
|
38
|
+
'react/iframe-missing-sandbox': "error";
|
|
39
|
+
'react/no-danger': "error";
|
|
40
|
+
'react/checked-requires-onchange-or-readonly': "error";
|
|
41
|
+
'react/jsx-no-comment-textnodes': "error";
|
|
42
|
+
'react/no-unescaped-entities': "error";
|
|
43
|
+
'react/style-prop-object': "error";
|
|
44
|
+
'react/no-namespace': "error";
|
|
45
|
+
'react/self-closing-comp': "error";
|
|
46
|
+
'react/jsx-curly-brace-presence': "error";
|
|
47
|
+
'react/jsx-fragments': "error";
|
|
48
|
+
'react/jsx-no-useless-fragment': "error";
|
|
49
|
+
'react/jsx-pascal-case': "error";
|
|
50
|
+
};
|
|
51
|
+
overrides: {
|
|
52
|
+
files: string[];
|
|
53
|
+
rules: {
|
|
54
|
+
'typescript/strict-boolean-expressions': ["error", {
|
|
55
|
+
allowNumber: false;
|
|
56
|
+
allowNullableBoolean: true;
|
|
57
|
+
allowNullableString: true;
|
|
58
|
+
}];
|
|
59
|
+
};
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
62
|
+
export default preset;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React preset, for code the React Compiler compiles. Extend it after the base preset:
|
|
3
|
+
*
|
|
4
|
+
* export default defineConfig({ extends: [base, react] })
|
|
5
|
+
*
|
|
6
|
+
* The base preset's `correctness` category also turns on the react and jsx-a11y plugins'
|
|
7
|
+
* correctness rules, which include the React Compiler's checks (`react/purity`, `react/refs`,
|
|
8
|
+
* `react/set-state-in-effect` and others). The rules below come from other categories.
|
|
9
|
+
*/
|
|
10
|
+
const preset = {
|
|
11
|
+
plugins: ['react', 'jsx-a11y'],
|
|
12
|
+
jsPlugins: [{ name: 'anti-slop-react', specifier: '@siim-m/config/anti-slop-react' }],
|
|
13
|
+
rules: {
|
|
14
|
+
'anti-slop-react/no-hookless-use-function': 'error',
|
|
15
|
+
'anti-slop-react/no-manual-memo': 'error',
|
|
16
|
+
'anti-slop-react/require-sync-comment-for-effect': 'error',
|
|
17
|
+
// oxlint files rules-of-hooks under pedantic, so the correctness category misses it.
|
|
18
|
+
'react/rules-of-hooks': 'error',
|
|
19
|
+
// A disable comment for exhaustive-deps or rules-of-hooks makes the compiler skip the function.
|
|
20
|
+
'react/rule-suppression': 'error',
|
|
21
|
+
'react/capitalized-calls': 'error',
|
|
22
|
+
'react/unsupported-syntax': 'error',
|
|
23
|
+
// Vite's Fast Refresh keeps state only in modules that export just components.
|
|
24
|
+
'react/only-export-components': ['error', { allowConstantExport: true }],
|
|
25
|
+
'react/prefer-function-component': 'error',
|
|
26
|
+
'react/no-array-index-key': 'error',
|
|
27
|
+
'react/hook-use-state': 'error',
|
|
28
|
+
'react/display-name': 'error',
|
|
29
|
+
'react/no-react-children': 'error',
|
|
30
|
+
'react/no-clone-element': 'error',
|
|
31
|
+
'react/button-has-type': 'error',
|
|
32
|
+
'react/jsx-no-target-blank': ['error', { forms: true }],
|
|
33
|
+
'react/jsx-no-script-url': 'error',
|
|
34
|
+
'react/iframe-missing-sandbox': 'error',
|
|
35
|
+
'react/no-danger': 'error',
|
|
36
|
+
'react/checked-requires-onchange-or-readonly': 'error',
|
|
37
|
+
'react/jsx-no-comment-textnodes': 'error',
|
|
38
|
+
'react/no-unescaped-entities': 'error',
|
|
39
|
+
'react/style-prop-object': 'error',
|
|
40
|
+
'react/no-namespace': 'error',
|
|
41
|
+
'react/self-closing-comp': 'error',
|
|
42
|
+
'react/jsx-curly-brace-presence': 'error',
|
|
43
|
+
'react/jsx-fragments': 'error',
|
|
44
|
+
'react/jsx-no-useless-fragment': 'error',
|
|
45
|
+
'react/jsx-pascal-case': 'error',
|
|
46
|
+
},
|
|
47
|
+
overrides: [
|
|
48
|
+
{
|
|
49
|
+
// `{count && <p />}` renders "0". Optional booleans and strings render nothing when
|
|
50
|
+
// falsy, so they may be conditions; numbers, nullable numbers and `any` may not, in any
|
|
51
|
+
// condition in a .tsx file. Type-aware.
|
|
52
|
+
files: ['**/*.tsx'],
|
|
53
|
+
rules: {
|
|
54
|
+
'typescript/strict-boolean-expressions': [
|
|
55
|
+
'error',
|
|
56
|
+
{ allowNumber: false, allowNullableBoolean: true, allowNullableString: true },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
export default preset;
|
package/dist/oxlint.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared oxlint preset. Extend it from `oxlint.config.mts`:
|
|
3
|
+
*
|
|
4
|
+
* export default defineConfig({ extends: [base], ignorePatterns: [...], rules: { ... } })
|
|
5
|
+
*
|
|
6
|
+
* Every rule here is on. A repo that can't pass one yet turns it off in its own config, so
|
|
7
|
+
* its list of `'off'` rules is its to-do list. `ignorePatterns` are not inherited.
|
|
8
|
+
*/
|
|
9
|
+
declare const preset: {
|
|
10
|
+
jsPlugins: {
|
|
11
|
+
name: string;
|
|
12
|
+
specifier: string;
|
|
13
|
+
}[];
|
|
14
|
+
categories: {
|
|
15
|
+
correctness: "error";
|
|
16
|
+
};
|
|
17
|
+
rules: {
|
|
18
|
+
'anti-slop/no-chained-type-assertions': "error";
|
|
19
|
+
'anti-slop/no-conditional-empty-object-spread': "error";
|
|
20
|
+
'anti-slop/no-known-value-widening': "error";
|
|
21
|
+
'anti-slop/no-module-mocking': "error";
|
|
22
|
+
'anti-slop/no-object-parameters': "error";
|
|
23
|
+
'anti-slop/no-reduce-accumulator-copy': "error";
|
|
24
|
+
'anti-slop/no-reflect-apply': "error";
|
|
25
|
+
'anti-slop/no-reflect-get': "error";
|
|
26
|
+
'anti-slop/no-runtime-typeof': "error";
|
|
27
|
+
'anti-slop/no-unknown-parameters': "error";
|
|
28
|
+
'anti-slop/no-unknown-returns': "error";
|
|
29
|
+
'anti-slop/no-unknown-type-aliases': "error";
|
|
30
|
+
'anti-slop/no-unsafe-dictionary-type': "error";
|
|
31
|
+
'anti-slop/no-widen-then-assert': "error";
|
|
32
|
+
'anti-slop/require-pascal-case-namespace-imports': "error";
|
|
33
|
+
'anti-slop/require-readable-spacing': "error";
|
|
34
|
+
'anti-slop/require-safety-comment-for-type-assertion': "error";
|
|
35
|
+
'anti-slop-effect/no-manual-effect-error-tag': "error";
|
|
36
|
+
'anti-slop-effect/no-service-constructor-imports': "error";
|
|
37
|
+
'anti-slop-effect/no-service-parameters': "error";
|
|
38
|
+
'anti-slop-effect/prefer-effect-match': "error";
|
|
39
|
+
'oxc/no-accumulating-spread': "error";
|
|
40
|
+
'typescript/no-floating-promises': "error";
|
|
41
|
+
'typescript/no-misused-promises': "error";
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export default preset;
|
package/dist/oxlint.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared oxlint preset. Extend it from `oxlint.config.mts`:
|
|
3
|
+
*
|
|
4
|
+
* export default defineConfig({ extends: [base], ignorePatterns: [...], rules: { ... } })
|
|
5
|
+
*
|
|
6
|
+
* Every rule here is on. A repo that can't pass one yet turns it off in its own config, so
|
|
7
|
+
* its list of `'off'` rules is its to-do list. `ignorePatterns` are not inherited.
|
|
8
|
+
*/
|
|
9
|
+
const preset = {
|
|
10
|
+
jsPlugins: [
|
|
11
|
+
{ name: 'anti-slop', specifier: '@siim-m/config/anti-slop' },
|
|
12
|
+
{ name: 'anti-slop-effect', specifier: '@siim-m/config/anti-slop-effect' },
|
|
13
|
+
],
|
|
14
|
+
categories: { correctness: 'error' },
|
|
15
|
+
rules: {
|
|
16
|
+
'anti-slop/no-chained-type-assertions': 'error',
|
|
17
|
+
'anti-slop/no-conditional-empty-object-spread': 'error',
|
|
18
|
+
'anti-slop/no-known-value-widening': 'error',
|
|
19
|
+
'anti-slop/no-module-mocking': 'error',
|
|
20
|
+
'anti-slop/no-object-parameters': 'error',
|
|
21
|
+
'anti-slop/no-reduce-accumulator-copy': 'error',
|
|
22
|
+
'anti-slop/no-reflect-apply': 'error',
|
|
23
|
+
'anti-slop/no-reflect-get': 'error',
|
|
24
|
+
'anti-slop/no-runtime-typeof': 'error',
|
|
25
|
+
'anti-slop/no-unknown-parameters': 'error',
|
|
26
|
+
'anti-slop/no-unknown-returns': 'error',
|
|
27
|
+
'anti-slop/no-unknown-type-aliases': 'error',
|
|
28
|
+
'anti-slop/no-unsafe-dictionary-type': 'error',
|
|
29
|
+
'anti-slop/no-widen-then-assert': 'error',
|
|
30
|
+
'anti-slop/require-pascal-case-namespace-imports': 'error',
|
|
31
|
+
'anti-slop/require-readable-spacing': 'error',
|
|
32
|
+
'anti-slop/require-safety-comment-for-type-assertion': 'error',
|
|
33
|
+
'anti-slop-effect/no-manual-effect-error-tag': 'error',
|
|
34
|
+
'anti-slop-effect/no-service-constructor-imports': 'error',
|
|
35
|
+
'anti-slop-effect/no-service-parameters': 'error',
|
|
36
|
+
'anti-slop-effect/prefer-effect-match': 'error',
|
|
37
|
+
// Spreads in reducers; anti-slop/no-reduce-accumulator-copy covers the other copies.
|
|
38
|
+
'oxc/no-accumulating-spread': 'error',
|
|
39
|
+
// Type-aware: these run only with `oxlint --type-aware` and oxlint-tsgolint installed.
|
|
40
|
+
'typescript/no-floating-promises': 'error',
|
|
41
|
+
'typescript/no-misused-promises': 'error',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
export default preset;
|