@mkaradeniz/eslint-config 5.11.0 → 5.12.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 +92 -0
- package/package.json +2 -1
package/createConfig.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { baseConfig } from './base.mjs';
|
|
2
|
+
import { nextConfig } from './next.mjs';
|
|
3
|
+
import { reactConfig } from './react.mjs';
|
|
4
|
+
import { baseRules } from './rules/baseRules.mjs';
|
|
5
|
+
import { reactRules } from './rules/reactRules.mjs';
|
|
6
|
+
import { createShadcnConfig } from './shadcn.mjs';
|
|
7
|
+
import { tanstackQueryConfig } from './tanstackQuery.mjs';
|
|
8
|
+
import { turboConfig } from './turbo.mjs';
|
|
9
|
+
|
|
10
|
+
const noLetRestriction = {
|
|
11
|
+
message:
|
|
12
|
+
'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).',
|
|
13
|
+
selector: 'VariableDeclaration[kind="let"]',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const envPrismaFiles = ['**/env.ts', '**/env.client.ts', '**/env.server.ts', '**/prisma/**/seed.ts', '**/prisma.config.ts'];
|
|
17
|
+
|
|
18
|
+
const instrumentationFiles = ['**/instrumentation.ts', '**/instrumentation-client.ts'];
|
|
19
|
+
|
|
20
|
+
const stripNoRestrictedSyntaxOverrides = configArray =>
|
|
21
|
+
configArray.filter(block => !(block.files && block.rules && Array.isArray(block.rules['no-restricted-syntax'])));
|
|
22
|
+
|
|
23
|
+
const buildMergedNoRestrictedSyntax = options => {
|
|
24
|
+
const sourceRules = options.base === 'next' || options.base === 'react' ? reactRules : baseRules;
|
|
25
|
+
const selectors = [...sourceRules.rules['no-restricted-syntax'].slice(1)];
|
|
26
|
+
if (options.noLet) {
|
|
27
|
+
selectors.push(noLetRestriction);
|
|
28
|
+
}
|
|
29
|
+
return ['warn', ...selectors];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const buildFileOverrideSelectors = merged => merged.slice(1).filter(s => !s.selector?.includes('process'));
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Composes ESLint flat config with merged `no-restricted-syntax` so file-scoped overrides (env, prisma, instrumentation) are not clobbered.
|
|
36
|
+
*
|
|
37
|
+
* @param options.base - 'base' | 'react' | 'next'
|
|
38
|
+
* @param options.noLet - Add restriction on `let`. Optional.
|
|
39
|
+
* @param options.shadcn - Path to shadcn components for relaxed rules. Optional.
|
|
40
|
+
* @param options.tanstackQuery - Include TanStack Query config. Optional.
|
|
41
|
+
* @param options.turbo - Include Turbo config. Optional.
|
|
42
|
+
*/
|
|
43
|
+
export const createConfig = (options = {}) => {
|
|
44
|
+
const base = options.base ?? 'next';
|
|
45
|
+
const noLet = options.noLet ?? false;
|
|
46
|
+
const shadcn = options.shadcn;
|
|
47
|
+
const tanstackQuery = options.tanstackQuery ?? false;
|
|
48
|
+
const turbo = options.turbo ?? false;
|
|
49
|
+
|
|
50
|
+
const configByBase = { base: baseConfig, next: nextConfig, react: reactConfig };
|
|
51
|
+
const baseConfigArray = configByBase[base];
|
|
52
|
+
const stripped = stripNoRestrictedSyntaxOverrides(baseConfigArray);
|
|
53
|
+
const mergedNoRestrictedSyntax = buildMergedNoRestrictedSyntax({ base, noLet });
|
|
54
|
+
const overrideSelectors = buildFileOverrideSelectors(mergedNoRestrictedSyntax);
|
|
55
|
+
const fileOverrideNoRestrictedSyntax = ['warn', ...overrideSelectors];
|
|
56
|
+
|
|
57
|
+
const config = [
|
|
58
|
+
...stripped,
|
|
59
|
+
{
|
|
60
|
+
rules: {
|
|
61
|
+
'no-restricted-syntax': mergedNoRestrictedSyntax,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
files: envPrismaFiles,
|
|
66
|
+
rules: {
|
|
67
|
+
'no-restricted-syntax': fileOverrideNoRestrictedSyntax,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
if (base === 'next') {
|
|
73
|
+
config.push({
|
|
74
|
+
files: instrumentationFiles,
|
|
75
|
+
rules: {
|
|
76
|
+
'no-restricted-syntax': fileOverrideNoRestrictedSyntax,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (tanstackQuery) {
|
|
82
|
+
config.push(...tanstackQueryConfig);
|
|
83
|
+
}
|
|
84
|
+
if (turbo) {
|
|
85
|
+
config.push(...turboConfig);
|
|
86
|
+
}
|
|
87
|
+
if (typeof shadcn === 'string') {
|
|
88
|
+
config.push(...createShadcnConfig(shadcn));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return config;
|
|
92
|
+
};
|