@mkaradeniz/eslint-config 5.10.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.
@@ -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
+ };
package/noLet.mjs ADDED
@@ -0,0 +1,26 @@
1
+ import { baseRules } from './rules/baseRules.mjs';
2
+
3
+ const noLetRestriction = {
4
+ message:
5
+ '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).',
6
+ selector: 'VariableDeclaration[kind="let"]',
7
+ };
8
+
9
+ /**
10
+ * Bans `let` declarations via `no-restricted-syntax`.
11
+ *
12
+ * Accepts an optional source rules object to merge with. Defaults to `baseRules`.
13
+ * Pass `reactRules` when composing with `reactConfig` or `nextConfig` to preserve their extra selectors.
14
+ *
15
+ * @example
16
+ * import { createNoLetConfig } from '@mkaradeniz/eslint-config/noLet.mjs';
17
+ * import { reactRules } from '@mkaradeniz/eslint-config/rules/reactRules.mjs';
18
+ * export default [...nextConfig, ...createNoLetConfig(reactRules)];
19
+ */
20
+ export const createNoLetConfig = (sourceRules = baseRules) => [
21
+ {
22
+ rules: {
23
+ 'no-restricted-syntax': ['warn', ...sourceRules.rules['no-restricted-syntax'].slice(1), noLetRestriction],
24
+ },
25
+ },
26
+ ];
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@mkaradeniz/eslint-config",
3
- "version": "5.10.0",
3
+ "version": "5.12.0",
4
4
  "private": false,
5
5
  "files": [
6
6
  "base.mjs",
7
+ "createConfig.mjs",
7
8
  "web.mjs",
8
9
  "next.mjs",
10
+ "noLet.mjs",
9
11
  "react.mjs",
10
12
  "shadcn.mjs",
11
13
  "tanstackQuery.mjs",
@@ -134,11 +134,6 @@ export const baseRules = {
134
134
  message: 'Use envConfigClient or envConfigServer instead of process.env.',
135
135
  selector: 'MemberExpression[object.name="process"][property.name="env"]',
136
136
  },
137
- // {
138
- // message:
139
- // '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).',
140
- // selector: 'VariableDeclaration[kind="let"]',
141
- // },
142
137
  ],
143
138
  'no-return-assign': ['warn'],
144
139
  'no-script-url': ['warn'],