Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
141 lines (131 loc) · 4.19 KB
/
Copy patheslint.config.js
File metadata and controls
141 lines (131 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// eslint.config.js (ESM / ESLint v9 flat config)
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import pluginImport from 'eslint-plugin-import';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import eslintConfigPrettier from 'eslint-config-prettier';
import globals from 'globals';
import unusedImports from 'eslint-plugin-unused-imports';
export default [
// Replaces .eslintignore
{ ignores: ['dist/**', 'node_modules/**', '**/*.d.ts'] },
// Base JS + TS recommended
js.configs.recommended,
...tseslint.configs.recommended,
// React/TS app files (browser), plus .mts/.cts (Node ESM/CJS TS scripts -
// these get Node globals from the scripts override block below)
{
files: ['**/*.{ts,tsx,mts,cts}'],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: { jsx: true },
},
globals: globals.browser,
},
settings: {
react: { version: 'detect' },
'import/resolver': { typescript: true },
},
plugins: {
react,
'react-hooks': reactHooks,
import: pluginImport,
'simple-import-sort': simpleImportSort,
'unused-imports': unusedImports,
},
rules: {
// Project conventions
'import/no-default-export': 'error',
'react/react-in-jsx-scope': 'off',
'react/jsx-uses-react': 'off',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
// Remove unused imports/vars on --fix
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
// Deterministic import ordering
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
// Layering: rules/ is the sole rule-logic layer and must stay UI-free;
// data/ is the sole static-content layer and must stay rules/UI-free.
// See claude.md's architecture section.
'import/no-restricted-paths': [
'error',
{
zones: [
{
target: './src/rules/**/*',
from: ['./src/components/**/*', './src/hooks/**/*'],
message:
'src/rules/ has no UI dependencies; it may only import from src/data and src/types.',
},
{
target: './src/data/**/*',
from: ['./src/rules/**/*', './src/components/**/*'],
message:
'src/data/ is the static-content layer; it may not import from src/rules or src/components.',
},
],
},
],
// Optional tighten-ups you can enable later:
// '@typescript-eslint/no-explicit-any': 'warn',
// '@typescript-eslint/explicit-function-return-type': 'off',
},
},
// src/rules/ additionally has no React/DOM dependencies (see claude.md)
{
files: ['src/rules/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{ name: 'react', message: 'src/rules/ has no React/DOM dependencies.' },
{ name: 'react-dom', message: 'src/rules/ has no React/DOM dependencies.' },
],
},
],
},
},
// Node CLI / scripts (e.g., scripts/*.mjs, tool configs)
{
files: [
'scripts/**/*.{js,mjs,ts,mts}',
'vite.config.*',
'vitest.config.*',
'eslint.config.*',
'postcss.config.*',
'tailwind.config.*',
'*.config.{js,ts,mjs,cjs}',
],
languageOptions: {
sourceType: 'module',
globals: {
...globals.node, // process, console, __dirname (CJS note), etc.
structuredClone: 'readonly',
},
},
rules: {
// Allow default export in tool configs; allow console in CLI
'import/no-default-export': 'off',
'no-console': 'off',
},
},
// Keep last to disable rules that conflict with Prettier
eslintConfigPrettier,
];