@mkaradeniz/eslint-config 5.11.0 → 5.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/createConfig.mjs +107 -0
- package/noUtilInComponent.mjs +19 -0
- package/package.json +3 -1
package/createConfig.mjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { baseConfig } from './base.mjs';
|
|
2
|
+
import { nextConfig } from './next.mjs';
|
|
3
|
+
import { noUtilInComponentRestrictions } from './noUtilInComponent.mjs';
|
|
4
|
+
import { reactConfig } from './react.mjs';
|
|
5
|
+
import { baseRules } from './rules/baseRules.mjs';
|
|
6
|
+
import { reactRules } from './rules/reactRules.mjs';
|
|
7
|
+
import { createShadcnConfig } from './shadcn.mjs';
|
|
8
|
+
import { tanstackQueryConfig } from './tanstackQuery.mjs';
|
|
9
|
+
import { turboConfig } from './turbo.mjs';
|
|
10
|
+
|
|
11
|
+
const noLetRestriction = {
|
|
12
|
+
message:
|
|
13
|
+
'Prefer const + functional patterns (map/filter/reduce/ternary). Extract to a util function if needed. Only disable for: try/catch assignment, iterators/generators, for-await-of accumulation, or closures requiring mutable state (debounce, event handlers).',
|
|
14
|
+
selector: 'VariableDeclaration[kind="let"]',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const envPrismaFiles = ['**/env.ts', '**/env.client.ts', '**/env.server.ts', '**/prisma/**/seed.ts', '**/prisma.config.ts'];
|
|
18
|
+
|
|
19
|
+
const instrumentationFiles = ['**/instrumentation.ts', '**/instrumentation-client.ts'];
|
|
20
|
+
|
|
21
|
+
const stripNoRestrictedSyntaxOverrides = configArray =>
|
|
22
|
+
configArray.filter(block => !(block.files && block.rules && Array.isArray(block.rules['no-restricted-syntax'])));
|
|
23
|
+
|
|
24
|
+
const buildMergedNoRestrictedSyntax = options => {
|
|
25
|
+
const sourceRules = options.base === 'next' || options.base === 'react' ? reactRules : baseRules;
|
|
26
|
+
const selectors = [...sourceRules.rules['no-restricted-syntax'].slice(1)];
|
|
27
|
+
if (options.noLet) {
|
|
28
|
+
selectors.push(noLetRestriction);
|
|
29
|
+
}
|
|
30
|
+
return ['warn', ...selectors];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const buildFileOverrideSelectors = merged => merged.slice(1).filter(s => !s.selector?.includes('process'));
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Composes ESLint flat config with merged `no-restricted-syntax` so file-scoped overrides (env, prisma, instrumentation) are not clobbered.
|
|
37
|
+
*
|
|
38
|
+
* @param options.base - 'base' | 'react' | 'next'
|
|
39
|
+
* @param options.noLet - Add restriction on `let`. Optional.
|
|
40
|
+
* @param options.noUtilInComponent - Ban camelCase util functions in `.tsx` files. Optional.
|
|
41
|
+
* @param options.shadcn - Path to shadcn components for relaxed rules. Optional.
|
|
42
|
+
* @param options.tanstackQuery - Include TanStack Query config. Optional.
|
|
43
|
+
* @param options.turbo - Include Turbo config. Optional.
|
|
44
|
+
*/
|
|
45
|
+
export const createConfig = (options = {}) => {
|
|
46
|
+
const base = options.base ?? 'next';
|
|
47
|
+
const noLet = options.noLet ?? false;
|
|
48
|
+
const noUtilInComponent = options.noUtilInComponent ?? false;
|
|
49
|
+
const shadcn = options.shadcn;
|
|
50
|
+
const tanstackQuery = options.tanstackQuery ?? false;
|
|
51
|
+
const turbo = options.turbo ?? false;
|
|
52
|
+
|
|
53
|
+
const configByBase = { base: baseConfig, next: nextConfig, react: reactConfig };
|
|
54
|
+
const baseConfigArray = configByBase[base];
|
|
55
|
+
const stripped = stripNoRestrictedSyntaxOverrides(baseConfigArray);
|
|
56
|
+
const mergedNoRestrictedSyntax = buildMergedNoRestrictedSyntax({ base, noLet });
|
|
57
|
+
const overrideSelectors = buildFileOverrideSelectors(mergedNoRestrictedSyntax);
|
|
58
|
+
const fileOverrideNoRestrictedSyntax = ['warn', ...overrideSelectors];
|
|
59
|
+
|
|
60
|
+
const config = [
|
|
61
|
+
...stripped,
|
|
62
|
+
{
|
|
63
|
+
rules: {
|
|
64
|
+
'no-restricted-syntax': mergedNoRestrictedSyntax,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
files: envPrismaFiles,
|
|
69
|
+
rules: {
|
|
70
|
+
'no-restricted-syntax': fileOverrideNoRestrictedSyntax,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
if (base === 'next') {
|
|
76
|
+
config.push({
|
|
77
|
+
files: instrumentationFiles,
|
|
78
|
+
rules: {
|
|
79
|
+
'no-restricted-syntax': fileOverrideNoRestrictedSyntax,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (noUtilInComponent && (base === 'next' || base === 'react')) {
|
|
85
|
+
const ignorePatterns = typeof shadcn === 'string' ? [`!${shadcn}/**`] : [];
|
|
86
|
+
|
|
87
|
+
config.push({
|
|
88
|
+
files: ['**/*.tsx'],
|
|
89
|
+
ignores: ignorePatterns,
|
|
90
|
+
rules: {
|
|
91
|
+
'no-restricted-syntax': [...mergedNoRestrictedSyntax, ...noUtilInComponentRestrictions],
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (tanstackQuery) {
|
|
97
|
+
config.push(...tanstackQueryConfig);
|
|
98
|
+
}
|
|
99
|
+
if (turbo) {
|
|
100
|
+
config.push(...turboConfig);
|
|
101
|
+
}
|
|
102
|
+
if (typeof shadcn === 'string') {
|
|
103
|
+
config.push(...createShadcnConfig(shadcn));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return config;
|
|
107
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const noUtilInComponentMessage =
|
|
2
|
+
"Don't define util functions in component files — move to a utils module. Use PascalCase for components and useX for hooks.";
|
|
3
|
+
|
|
4
|
+
export const noUtilInComponentRestrictions = [
|
|
5
|
+
{
|
|
6
|
+
message: noUtilInComponentMessage,
|
|
7
|
+
selector: 'Program > FunctionDeclaration[id.name=/^[a-z]/]:not([id.name=/^use[A-Z]/])',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
message: noUtilInComponentMessage,
|
|
11
|
+
selector:
|
|
12
|
+
'Program > VariableDeclaration > VariableDeclarator[init.type="ArrowFunctionExpression"][id.name=/^[a-z]/]:not([id.name=/^use[A-Z]/])',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
message: noUtilInComponentMessage,
|
|
16
|
+
selector:
|
|
17
|
+
'Program > VariableDeclaration > VariableDeclarator[init.type="FunctionExpression"][id.name=/^[a-z]/]:not([id.name=/^use[A-Z]/])',
|
|
18
|
+
},
|
|
19
|
+
];
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mkaradeniz/eslint-config",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.13.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"files": [
|
|
6
6
|
"base.mjs",
|
|
7
|
+
"createConfig.mjs",
|
|
7
8
|
"web.mjs",
|
|
8
9
|
"next.mjs",
|
|
9
10
|
"noLet.mjs",
|
|
11
|
+
"noUtilInComponent.mjs",
|
|
10
12
|
"react.mjs",
|
|
11
13
|
"shadcn.mjs",
|
|
12
14
|
"tanstackQuery.mjs",
|