-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy patheslint.config.js
More file actions
130 lines (121 loc) · 3.41 KB
/
eslint.config.js
File metadata and controls
130 lines (121 loc) · 3.41 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
import js from '@eslint/js';
import tseslintPlugin from '@typescript-eslint/eslint-plugin';
import tseslintParser from '@typescript-eslint/parser';
import prettierPlugin from 'eslint-plugin-prettier';
import prettierConfig from 'eslint-config-prettier';
import { defineConfig } from 'eslint/config';
import globals from 'globals';
// typescript-eslint's flat/recommended preset is an array of configs (base +
// eslint-recommended overrides + recommended rules). Flatten its rules so we
// can apply them via our own `files`-scoped blocks.
const tsRecommendedRules = tseslintPlugin.configs['flat/recommended'].reduce(
(acc, cfg) => ({ ...acc, ...(cfg.rules ?? {}) }),
{},
);
const prettierRules = {
...prettierConfig.rules,
'prettier/prettier': 'error',
};
const unusedVarsOptions = {
args: 'after-used',
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
ignoreRestSiblings: true,
};
const preferConstOptions = {
destructuring: 'all',
ignoreReadBeforeAssign: false,
};
const lintedGlobals = {
...globals.node,
extension: 'readonly',
config: 'readonly',
global_config: 'readonly',
};
const jsFiles = [
'src/backend/**/*.{js,mjs,cjs}',
'extensions/**/*.{js,mjs,cjs}',
];
const tsIgnores = [
'**/*.test.ts',
'**/*.test.mts',
'**/*.spec.ts',
'**/*.spec.mts',
'src/backend/test/**',
'src/backend/tools/**',
'src/backend/vitest.config.ts',
'src/backend/vitest.bench.config.ts',
];
const createTsConfig = ({ files, project }) => ({
files,
ignores: tsIgnores,
languageOptions: {
parser: tseslintParser,
globals: lintedGlobals,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
projectService: { defaultProject: project },
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
'@typescript-eslint': tseslintPlugin,
prettier: prettierPlugin,
},
rules: {
...tsRecommendedRules,
...prettierRules,
'@typescript-eslint/no-unused-vars': ['error', unusedVarsOptions],
'@typescript-eslint/no-explicit-any': 'warn',
'prefer-const': ['error', preferConstOptions],
},
});
export default defineConfig([
{
ignores: [
'**/*.dbmig.js',
'dist/**',
'build/**',
'volatile/**',
'node_modules/**',
'puter.js/**',
'apps/**',
'experiment/**',
'workers/**',
'src/public/**',
'src/gui/**',
'src/docs/**',
'src/puter-js/**',
'src/worker/**',
'submodules/**',
'tests/**',
'tools/**',
],
},
{
files: jsFiles,
ignores: ['**/*.test.js'],
plugins: {
js,
prettier: prettierPlugin,
},
extends: ['js/recommended'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: lintedGlobals,
},
rules: {
...prettierRules,
'no-unused-vars': ['error', unusedVarsOptions],
'prefer-const': ['error', preferConstOptions],
},
},
createTsConfig({
files: ['src/backend/**/*.ts', 'extensions/**/*.ts'],
project: './tsconfig.json',
}),
]);