@mkaradeniz/eslint-config 5.12.0 → 5.13.1

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 CHANGED
@@ -1,5 +1,6 @@
1
1
  import { baseConfig } from './base.mjs';
2
2
  import { nextConfig } from './next.mjs';
3
+ import { noUtilInComponentRestrictions } from './noUtilInComponent.mjs';
3
4
  import { reactConfig } from './react.mjs';
4
5
  import { baseRules } from './rules/baseRules.mjs';
5
6
  import { reactRules } from './rules/reactRules.mjs';
@@ -36,6 +37,7 @@ const buildFileOverrideSelectors = merged => merged.slice(1).filter(s => !s.sele
36
37
  *
37
38
  * @param options.base - 'base' | 'react' | 'next'
38
39
  * @param options.noLet - Add restriction on `let`. Optional.
40
+ * @param options.noUtilInComponent - Ban camelCase util functions in `.tsx` files. Optional.
39
41
  * @param options.shadcn - Path to shadcn components for relaxed rules. Optional.
40
42
  * @param options.tanstackQuery - Include TanStack Query config. Optional.
41
43
  * @param options.turbo - Include Turbo config. Optional.
@@ -43,6 +45,7 @@ const buildFileOverrideSelectors = merged => merged.slice(1).filter(s => !s.sele
43
45
  export const createConfig = (options = {}) => {
44
46
  const base = options.base ?? 'next';
45
47
  const noLet = options.noLet ?? false;
48
+ const noUtilInComponent = options.noUtilInComponent ?? false;
46
49
  const shadcn = options.shadcn;
47
50
  const tanstackQuery = options.tanstackQuery ?? false;
48
51
  const turbo = options.turbo ?? false;
@@ -78,6 +81,18 @@ export const createConfig = (options = {}) => {
78
81
  });
79
82
  }
80
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
+
81
96
  if (tanstackQuery) {
82
97
  config.push(...tanstackQueryConfig);
83
98
  }
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@mkaradeniz/eslint-config",
3
- "version": "5.12.0",
3
+ "version": "5.13.1",
4
4
  "private": false,
5
5
  "files": [
6
6
  "base.mjs",
@@ -8,6 +8,7 @@
8
8
  "web.mjs",
9
9
  "next.mjs",
10
10
  "noLet.mjs",
11
+ "noUtilInComponent.mjs",
11
12
  "react.mjs",
12
13
  "shadcn.mjs",
13
14
  "tanstackQuery.mjs",