-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.ts
More file actions
176 lines (162 loc) · 4.73 KB
/
eslint.config.ts
File metadata and controls
176 lines (162 loc) · 4.73 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import js from "@eslint/js";
import prettier from "eslint-config-prettier";
import importPlugin from "eslint-plugin-import";
import { readFileSync } from "fs";
import globals from "globals";
import * as JSONC from "jsonc-parser";
import tseslint from "typescript-eslint";
// Import custom rules
import customRules from "./eslint-rules";
/**
* Read TypeScript exclusions to maintain perfect scope alignment
*/
function getTypeScriptExclusions(configFile: string): string[] {
try {
const configContent = readFileSync(configFile, "utf-8");
const config = JSONC.parse(configContent);
return config.exclude || [];
} catch {
console.warn(`Could not read TypeScript config ${configFile}, using default exclusions`);
return [];
}
}
// Determine TypeScript config file based on mode
// Use ESLINT_PRODUCTION_ONLY=1 to lint only production files
const isBuildOnly = process.env.ESLINT_PRODUCTION_ONLY === "1";
const typescriptConfigFile = isBuildOnly ? "./tsconfig.production.json" : "./tsconfig.json";
// Always read TypeScript exclusions - tsconfig.json is the single source of truth
const tsExclusions = getTypeScriptExclusions(typescriptConfigFile);
const config = [
// Ignore patterns - tsconfig.json exclusions + ESLint-specific patterns
{
ignores: [
// Add ESLint-specific ignore rules below only if they cannot be
// handled in tsconfig.json
// From tsconfig.json (single source of truth)
...tsExclusions.map((p) => (p.includes("*") ? p : `${p}/**/*`)),
],
},
// Base configuration for all files
{
plugins: {
import: importPlugin,
},
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
parser: tseslint.parser,
globals: {
...globals.node,
...globals.es2021,
},
},
settings: {
"import/resolver": {
typescript: {
alwaysTryTypes: true,
project: typescriptConfigFile,
},
},
},
},
// JavaScript recommended rules
js.configs.recommended,
// TypeScript configuration
{
files: ["**/*.ts", "**/*.tsx"],
plugins: {
"@typescript-eslint": tseslint.plugin,
},
languageOptions: {
parser: tseslint.parser,
},
rules: {
...tseslint.configs.recommended[2].rules,
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
// Disable rules that conflict with TypeScript compiler
"no-unreachable": "off",
"no-redeclare": "off",
"no-undef": "off", // TypeScript handles this better
"no-dupe-class-members": "off",
// Enable TypeScript-specific versions
"@typescript-eslint/no-redeclare": "error",
},
},
// ESLint config files and other script files
{
files: [".eslintrc.{js,cjs}", "eslint.config.js", "tailwind.config.ts"],
languageOptions: {
sourceType: "script",
globals: {
node: true,
},
},
rules: {
"@typescript-eslint/no-require-imports": "off",
},
},
// TypeScript declaration files
{
files: ["**/*.d.ts"],
rules: {
"@typescript-eslint/no-unused-vars": "off",
},
},
// Test files overrides
{
files: ["**/*.test.ts", "**/*.test.tsx"],
languageOptions: {
globals: {
// Test environment globals
describe: "readonly",
it: "readonly",
expect: "readonly",
beforeEach: "readonly",
afterEach: "readonly",
beforeAll: "readonly",
afterAll: "readonly",
vi: "readonly",
vitest: "readonly",
test: "readonly",
},
},
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unnecessary-condition": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
// Allow unimported test utilities and transformers
"no-undef": "off",
"@typescript-eslint/no-redeclare": "off",
},
},
// Custom rules
{
plugins: {
spx: customRules,
},
rules: {},
},
// Custom CraftFinal rules for test files
{
files: ["**/*.test.ts", "**/*.spec.ts", "**/tests/**/*.ts", "**/__tests__/**/*.ts"],
plugins: {
spx: customRules,
},
rules: {
"spx/no-bdd-try-catch-anti-pattern": "error",
// Rules set to "warn" until existing violations are fixed (463 violations detected)
// See feature-25_eslint-rules-enforcement for tracking
"spx/no-hardcoded-work-item-kinds": "warn",
"spx/no-hardcoded-statuses": "warn",
},
},
// Prettier integration (must be last)
prettier,
];
export default config;