-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheslint.config.base.mjs
More file actions
173 lines (163 loc) · 6.04 KB
/
eslint.config.base.mjs
File metadata and controls
173 lines (163 loc) · 6.04 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
/**
* Shareable ESLint config for Playwright TypeScript projects.
* Single source of truth: used by this repo (via eslint.config.mjs) and by consumers (vasu-playwright-utils/eslint).
*
* @example
* // eslint.config.mjs (in your project)
* import playwrightLibConfig from 'vasu-playwright-utils/eslint';
* export default [
* ...playwrightLibConfig,
* { rules: { 'playwright/no-focused-test': 'warn' } },
* ];
*/
import typescript from '@typescript-eslint/eslint-plugin';
import typescriptParser from '@typescript-eslint/parser';
import prettier from 'eslint-plugin-prettier';
import importPlugin from 'eslint-plugin-import';
import jsdoc from 'eslint-plugin-jsdoc';
import playwright from 'eslint-plugin-playwright';
import js from '@eslint/js';
import process from 'node:process';
// Works in this repo and when imported from other projects (consumer's cwd)
const projectRoot = process.cwd();
export default [
{
ignores: [
'node_modules/**',
'dist/**',
'build/**',
'coverage/**',
'.husky/**',
'**/*.js',
'package-lock.json',
],
},
js.configs.recommended,
{
files: ['**/*.ts'],
languageOptions: {
parser: typescriptParser,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: projectRoot,
},
globals: {
console: 'readonly',
process: 'readonly',
Buffer: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
global: 'readonly',
module: 'readonly',
require: 'readonly',
exports: 'readonly',
},
},
plugins: {
'@typescript-eslint': typescript,
prettier,
import: importPlugin,
jsdoc,
playwright,
},
settings: { 'import/resolver': { typescript: { alwaysTryTypes: true } } },
rules: {
// Prettier Rules
'prettier/prettier': 'error',
'no-trailing-spaces': 'error',
'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 0 }],
'eol-last': ['error', 'always'],
// TypeScript Rules - Base
...typescript.configs['eslint-recommended'].overrides[0].rules,
...typescript.configs.recommended.rules,
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/explicit-module-boundary-types': 'off',
// TypeScript Rules - Additional Strict Rules
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-empty-function': 'warn',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-duplicate-enum-values': 'error',
'@typescript-eslint/no-inferrable-types': [
'error',
{ ignoreParameters: false, ignoreProperties: false },
],
// Import Rules
'import/no-unresolved': 'error',
'import/named': 'error',
'import/default': 'error',
'import/no-absolute-path': 'error',
'import/no-self-import': 'error',
'import/first': 'error',
'import/no-mutable-exports': 'error',
// Declaration order: builtin → external → internal → parent → sibling → index (auto-fix via import/order)
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'type'],
'newlines-between': 'never',
alphabetize: { order: 'asc', caseInsensitive: true },
pathGroups: [
{ pattern: '@/**', group: 'internal', position: 'before' },
],
pathGroupsExcludedImportTypes: ['builtin'],
},
],
// Member order within named imports only (e.g. { b, a } → { a, b }); declaration order handled by import/order
'sort-imports': ['error', { ignoreDeclarationSort: true }],
// General Rules - Best Practices
'require-await': 'off',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-misused-promises': 'error',
complexity: ['warn', { max: 11 }],
'no-console': ['warn', { allow: ['warn', 'error', 'info'] }],
'no-debugger': 'error',
'no-var': 'error',
'prefer-const': 'error',
'prefer-template': 'error',
'object-shorthand': 'error',
'no-lonely-if': 'error',
'no-useless-return': 'error',
'no-nested-ternary': 'warn',
eqeqeq: ['error', 'always', { null: 'ignore' }],
'no-throw-literal': 'error',
// JSDoc Rules
'jsdoc/check-alignment': 'off',
'jsdoc/check-indentation': 'off',
// Playwright recommended rules
...playwright.configs['playwright-test'].rules,
// Playwright Rules
'playwright/missing-playwright-await': 'error',
'playwright/no-focused-test': 'error',
'playwright/valid-expect': 'error',
'playwright/prefer-web-first-assertions': 'error',
'playwright/no-useless-await': 'error',
'playwright/no-page-pause': 'error',
'playwright/no-element-handle': 'error',
'playwright/no-eval': 'error',
'playwright/prefer-to-be': 'error',
'playwright/prefer-to-contain': 'error',
'playwright/prefer-to-have-length': 'error',
'playwright/no-wait-for-timeout': 'warn',
'playwright/no-useless-not': 'warn',
'playwright/require-top-level-describe': 'off',
'playwright/expect-expect': 'off',
'playwright/no-conditional-in-test': 'off',
'playwright/no-skipped-test': 'off',
'playwright/consistent-spacing-between-blocks': 'off',
},
},
];