-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.js
103 lines (97 loc) · 2.72 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
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import { ESLintUtils } from '@typescript-eslint/utils';
const createRule = ESLintUtils.RuleCreator(
name => `${name}`,
);
// TODO: Prettier?
const noArrayLengthMinusOne = createRule({
name: 'no-array-length-minus-one',
meta: {
type: 'suggestion',
docs: {
description: 'Suggest using array.at(-1) instead of array[array.length - 1]',
recommended: 'warn',
},
fixable: 'code',
schema: [],
messages: {
useAtMethod: 'Use array.at(-1) instead of array[array.length - 1]',
},
},
defaultOptions: [],
create(context) {
return {
MemberExpression(node) {
if (
node.computed &&
node.property.type === 'BinaryExpression' &&
node.property.operator === '-' &&
node.property.left.type === 'MemberExpression' &&
node.property.left.object.type === 'Identifier' &&
node.property.left.property.type === 'Identifier' &&
node.property.left.property.name === 'length' &&
node.property.left.object.name === node.object.name &&
node.property.right.type === 'Literal' &&
node.property.right.value === 1
) {
context.report({
node,
messageId: 'useAtMethod',
fix(fixer) {
return fixer.replaceText(node, `${node.object.name}.at(-1)`);
},
});
}
},
};
},
});
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
}
},
plugins: {
custom: {
rules: {
noArrayLengthMinusOne,
}
}
},
rules: {
'custom/noArrayLengthMinusOne': 'error',
// Conflicts with prettier.
'no-unexpected-multiline': 'off',
'no-constant-binary-expression': 'error',
'no-constant-condition': [
'error',
{
checkLoops: false,
}
],
'no-inner-declarations': 'off',
// Will still be checked before calls/assignment.
'@typescript-eslint/no-unsafe-member-access': 'off',
// Used in lit event bindings.
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true
}
]
}
}
);