-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheslint.config.mjs
More file actions
97 lines (96 loc) · 3.06 KB
/
eslint.config.mjs
File metadata and controls
97 lines (96 loc) · 3.06 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
import js from '@eslint/js';
import globals from 'globals';
import tseslint from 'typescript-eslint';
import tsparser from '@typescript-eslint/parser';
import typescriptEslintPlugin from '@typescript-eslint/eslint-plugin';
import vitest from '@vitest/eslint-plugin';
import testingLibrary from 'eslint-plugin-testing-library';
import { defineConfig } from 'eslint/config';
export default defineConfig(
{ ignores: ['dist'] },
// Disallow .js and .cjs files (project uses ESM with .mjs and TypeScript)
{
files: ['**/*.js', '**/*.cjs'],
rules: {
'no-restricted-syntax': [
'error',
{
selector: 'Program',
message: 'JavaScript (.js) and CommonJS (.cjs) files are not allowed. Use TypeScript (.ts) or ES modules (.mjs) instead.',
},
],
},
},
// JavaScript configuration files (jest.config.mjs, etc.)
{
files: ['*.mjs'],
...js.configs.recommended,
languageOptions: {
ecmaVersion: 2020,
sourceType: 'module',
globals: {
...globals.node,
},
},
},
{
files: ['src/**/*.{ts,tsx}'],
plugins: {
'@typescript-eslint': typescriptEslintPlugin,
},
rules: {
...tseslint.configs.recommended.rules,
...tseslint.configs.recommendedTypeChecked.rules,
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'@typescript-eslint/explicit-function-return-type': 'error',
// Disabled to allow type inference at module boundaries
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-non-null-assertion': 'warn',
// Disallow `unknown` in type assertions (`x as unknown`) and in variable-type
// annotations (`const x: unknown`). Both are escape hatches that bypass type
// safety. Function-parameter and interface-field annotations are not targeted
// by these selectors. If genuinely unavoidable, add eslint-disable-next-line
// with a justification.
'no-restricted-syntax': [
'error',
{
selector: 'TSAsExpression[typeAnnotation.type="TSUnknownKeyword"], VariableDeclarator[id.typeAnnotation.typeAnnotation.type="TSUnknownKeyword"]',
message: 'Avoid `unknown` in type assertions and variable-type annotations. If unavoidable, add eslint-disable-next-line with a justification.',
},
],
// Disabled to allow console logging in VS Code extension
'no-console': 'off',
},
languageOptions: {
parser: tsparser,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: './tsconfig.json',
},
globals: globals.browser,
},
},
{
files: ['src/**/*.{test,spec}.{ts,tsx}'],
plugins: {
vitest,
'testing-library': testingLibrary,
},
rules: {
...vitest.configs.recommended.rules,
},
languageOptions: {
globals: {
...vitest.environments.env.globals,
},
},
},
);