-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.mjs
155 lines (146 loc) · 4.92 KB
/
eslint.config.mjs
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
import globals from 'globals';
import pluginJs from '@eslint/js';
import pluginTs from '@typescript-eslint/eslint-plugin';
import tseslint from 'typescript-eslint';
import tsParser from '@typescript-eslint/parser';
// --------------------------------------------------------------------------------------------------------------------
const globalLanguageOptions = {
globals: {
...globals.node,
...globals.mocha,
},
ecmaVersion: 'latest',
sourceType: 'module',
parser: tsParser,
};
// --------------------------------------------------------------------------------------------------------------------
/** @type {import('eslint').Linter.Config[]} */
export default [
{ ignores: ['coverage', 'dist', 'node_modules'] },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
// Entire project
files: ['**/*.{js,mjs,cjs,ts}'],
plugins: { '@typescript-eslint': pluginTs },
languageOptions: globalLanguageOptions,
rules: {
// ----- Code Style -----
'keyword-spacing': 'error',
'brace-style': ['error', 'stroustrup', { 'allowSingleLine': true }],
'indent': ['error', 4],
'quotes': ['error', 'single'],
'semi': ['error', 'always'],
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'never',
},
],
'eol-last': ['error', 'always'],
'max-len': [
'warn',
{
'code': 120,
'ignoreComments': true,
'ignoreUrls': true,
'ignoreTemplateLiterals': true,
'ignoreRegExpLiterals': true,
},
],
'no-trailing-spaces': ['error'],
// ----- Import/Export Rules -----
// `sort-imports` is native to ESLint, so it doesn't need a plugin.
// But `import/order` is from `eslint-plugin-import`, so it needs to be installed as a plugin.
'sort-imports': [
// The modules are organized into distinct groups, each separated by an empty line for clarity and order.
// The sequence of groups is as follows:
// Node.js built-in modules
// Third party modules
// project modules
'error',
{
'ignoreCase': true,
'ignoreDeclarationSort': false,
'ignoreMemberSort': false,
'memberSyntaxSortOrder': ['none', 'all', 'multiple', 'single'],
'allowSeparatedGroups': true,
},
],
// Need `eslint-plugin-import` as a plugin to use import/export rules.
// $ npm install eslint-plugin-import --save-dev
// Reference:
// - Installation:
// - https://github.com/import-js/eslint-plugin-import/tree/main?tab=readme-ov-file#installation
// - Configuration:
// - https://github.com/import-js/eslint-plugin-import/tree/main?tab=readme-ov-file#config---flat-eslintconfigjs
// - https://github.com/import-js/eslint-plugin-import/tree/main?tab=readme-ov-file#config---flat-with-config-in-typescript-eslint
// - Rules:
// - https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md
//
// 'import/order': [
// 'error',
// {
// groups: [
// ['builtin', 'external'],
// 'internal',
// ['parent', 'sibling'],
// 'index'
// ],
// 'newlines-between': 'always',
// 'alphabetize': { order: 'asc', caseInsensitive: true },
// },
// ],
// ----- TypeScript Rules -----
'@typescript-eslint/member-ordering': [
// In order from the largest to the smallest scope, member variables should come first, followed by the
// constructor, and then member methods.
'warn',
{
'default': [
// Abstract Fields
'public-abstract-field',
'protected-abstract-field',
// Abstract Methods
'public-abstract-method',
'protected-abstract-method',
// Static Fields
'public-static-field',
'protected-static-field',
'private-static-field',
// Static Methods
'public-static-method',
'protected-static-method',
'private-static-method',
// Instance Fields
'public-instance-field',
'protected-instance-field',
'private-instance-field',
// Constructor
'constructor',
// Instance Methods
'public-instance-method',
'protected-instance-method',
'private-instance-method',
],
},
],
},
},
{
files: ['eslint.config.mjs'],
rules: {
'indent': ['error', 2],
},
},
{
files: ['**/*.spec.ts'],
rules: {
'@typescript-eslint/no-unused-expressions': 'off',
},
},
];