-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy patheslint.config.mjs
More file actions
129 lines (127 loc) · 4.54 KB
/
eslint.config.mjs
File metadata and controls
129 lines (127 loc) · 4.54 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
// @ts-check
// cspell: ignore tseslint
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import tsParser from "@typescript-eslint/parser";
import prettierRecommendedConfig from "eslint-plugin-prettier/recommended";
import globals from "globals";
import path from "path";
import { fileURLToPath } from "url";
import { defineConfig } from "eslint/config";
import { createRequire } from "module";
import importPlugin from "eslint-plugin-import";
import { includeIgnoreFile } from "@eslint/compat";
const require = createRequire(import.meta.url);
/** @type {import('eslint').ESLint.Plugin} */
const eslintPluginLocal = require("./test/eslint/eslint-plugin-local.cjs");
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
const gitignorePath = path.resolve(import.meta.dirname, ".gitignore");
export default defineConfig(
includeIgnoreFile(gitignorePath, "Imported .gitignore patterns"),
...[
importPlugin.flatConfigs.recommended,
eslint.configs.recommended,
prettierRecommendedConfig,
tseslint.configs.recommended,
tseslint.configs.strict,
// TODO: enable later
// tseslint.configs.stylistic,
],
{
/** Files that use type-aware linting (TS/JS in src, packages, test). */
files: ["**/*.{js,mjs,ts,tsx,mts,cjs}"],
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.mocha,
...globals.es2022,
},
parser: tsParser,
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
},
},
plugins: {
local: eslintPluginLocal,
},
rules: {
"no-restricted-imports": [
"error",
{
paths: [
{
name: "chai",
message:
"No direct import from chai, use vitest or node:assert alternatives.",
},
],
patterns: [
{
group: ["./*", "../*", "../../*", "../../../*", "../../../../*"],
message:
"Do not use relative imports; use path aliases or absolute imports.",
},
],
},
],
// temporary until we address these
// https://github.com/import-js/eslint-plugin-import/issues/3199
eqeqeq: ["error", "smart"],
// "import/no-relative-parent-imports": "warn",
// Needed for tseslint.configs.strictTypeChecked
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-base-to-string": "error",
"@typescript-eslint/no-require-imports": "off",
"local/node-DEP0190": "error",
"no-case-declarations": "error",
"no-constant-condition": "error",
"no-control-regex": "error",
"no-empty-function": "error",
"no-prototype-builtins": "error",
// "@typescript-eslint/require-await": "error", // electron import
// "@typescript-eslint/await-thenable": "error", // ~58 errors
"@typescript-eslint/unbound-method": "error",
// "@typescript-eslint/no-unsafe-member-access": "error", // ~550 errors
// "@typescript-eslint/no-floating-promises": "error", // ~100 errors
// "@typescript-eslint/restrict-template-expressions": "error",
// "@typescript-eslint/no-unsafe-argument": "error",
"@typescript-eslint/no-unsafe-return": "error",
},
settings: {
// workaround for vscode imports in test files
"import/core-modules": ["vscode"],
"import/resolver": {
typescript: { alwaysTryTypes: true },
},
},
},
{
// Test files rules are more relaxed for convenience
files: ["**/test/**/*.{js,ts,tsx,cjs}"],
rules: {
// unbound-method is noisy (expect(mock.method).toHaveBeenCalledWith etc.
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-base-to-string": "off",
// Mocks and dynamic fixtures routinely return `any`
"@typescript-eslint/no-unsafe-return": "off",
},
},
{
// WDIO tests use their own tsconfig with relative imports; path aliases aren't practical
files: ["test/wdio/**/*.ts", "wdio.conf.ts"],
rules: { "no-restricted-imports": "off" },
},
{
// Standalone scripts have no tsconfig; skip eslint entirely
ignores: ["scripts/**"],
},
{
// Package code uses @src/@test aliases resolved by tsconfig/Vitest per package; ESLint uses root
files: ["packages/**/*.{js,ts,tsx}"],
rules: { "import/no-unresolved": "off" },
},
);