-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
eslint.config.js
101 lines (89 loc) · 2.96 KB
/
eslint.config.js
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
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import Module from 'node:module';
import eslintJs from '@eslint/js';
import prettierConfig from 'eslint-config-prettier';
// @ts-expect-error No type definitions available for this package. https://github.com/ota-meshi/eslint-plugin-regexp/issues/723
import * as regexpPlugin from 'eslint-plugin-regexp';
import globals from 'globals';
const require = Module.createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
/** @type {'module' | 'commonjs'} */
const defaultSourceType =
require(join(__dirname, 'package.json')).type ?? 'commonjs';
/** @type {import('eslint').Linter.FlatConfig[]} */
export default [
eslintJs.configs.recommended,
prettierConfig,
regexpPlugin.configs['flat/recommended'],
{
linterOptions: {
reportUnusedDisableDirectives: 'error'
},
languageOptions: {
sourceType: defaultSourceType,
parserOptions: {
ecmaFeatures: {
impliedStrict: true
}
},
globals: {
...globals.nodeBuiltin
}
},
rules: {
'no-var': 'error',
'no-await-in-loop': 'error',
'no-implicit-globals': ['error'],
'no-unused-vars': ['error', { vars: 'local', argsIgnorePattern: '^_' }],
'no-useless-rename': ['error'],
'arrow-body-style': ['error', 'as-needed'],
'no-lonely-if': 'error',
'prefer-object-has-own': 'error',
'prefer-exponentiation-operator': 'error',
'prefer-regex-literals': ['error', { disallowRedundantWrapping: true }],
'array-callback-return': [
'error',
{ checkForEach: true, allowVoid: true }
],
'no-constructor-return': 'error',
'no-unmodified-loop-condition': 'error',
'no-useless-assignment': 'error',
/* eslint-plugin-regexp */
'regexp/prefer-character-class': ['error', { minAlternatives: 2 }],
'regexp/no-empty-alternative': 'error', // Set to warn in recommended config
'regexp/no-lazy-ends': 'error', // Set to warn in recommended config
'regexp/no-potentially-useless-backreference': 'error', // Set to warn in recommended config
'regexp/confusing-quantifier': 'error', // Set to warn in recommended config
'regexp/no-useless-flag': 'error', // Set to warn in recommended config
'regexp/optimal-lookaround-quantifier': 'error' // Set to warn in recommended config
}
},
{
files: ['src/**/*'],
languageOptions: {
globals: {
...globals.browser
}
}
},
{
// Why doesn't ESLint do this by default is beyond me.
files: ['**/*.cjs'],
languageOptions: {
sourceType: 'commonjs'
}
},
{
// Why doesn't ESLint do this by default is beyond me.
files: ['**/*.mjs'],
languageOptions: {
sourceType: 'module'
}
},
{
// `ignores` field must be in the very bottom config.
ignores: ['dist/**/*', '**/*-polyfill.*']
}
];