-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.eslintrc.js
120 lines (111 loc) · 3.37 KB
/
.eslintrc.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* globals module */
const default_rules = {
'no-restricted-syntax': [
'warn',
'ForInStatement'
],
'tampermonkey/no-global-object-access': [ 'warn', { aggressive: true } ],
'indent': [
'warn', 4,
{
'ignoreComments': true,
'SwitchCase': 1,
'MemberExpression': 0,
'offsetTernaryExpressions': false
}
]
};
const content_script_rules = {
'tampermonkey/no-global-object-access': 'off'
};
const unsafe_env_ts = [
'src/tab/**/*.ts'
];
const uniq = (a, b) => {
b.forEach(function(item) {
if (a.indexOf(item) < 0) {
a.push(item);
}
});
return a;
};
const merge_rules = (dest, ...srcs) => {
for (const src of srcs) {
for (const [ k, v ] of Object.entries(src)) {
const t = typeof dest[k];
if (t === 'undefined') {
dest[k] = v;
} else if (t === 'object' || t === 'string') {
if ([ 'off', 0 ].includes(v)) {
dest[k] = v;
} else if (Array.isArray(dest[k])) {
if (Array.isArray(v)) {
const [ level, ...rules ] = dest[k];
dest[k] = [ level, ...uniq(rules, v.slice(1)) ];
}
} else {
dest[k] = v;
}
} else {
console.log(`eslintrc.js: unknown rule type ${t} ${k}`);
}
}
}
return dest;
};
const ts_rules = merge_rules({
'linebreak-style': [ 'warn', 'unix' ],
'no-constant-condition': [ 'warn', { 'checkLoops': false } ],
'no-empty': [ 'warn', { 'allowEmptyCatch': true } ],
'no-debugger': 'warn',
'@typescript-eslint/no-explicit-any': 'off',
// '@typescript-eslint/strict-boolean-expressions': [ 'warn', { 'allowConstantLoopConditions': true } ],
'@typescript-eslint/no-unused-vars': [ 'warn', { 'argsIgnorePattern': '^_' } ],
'@typescript-eslint/semi': [ 'warn', 'always', { 'omitLastInOneLineBlock': true } ],
'@typescript-eslint/quotes': [ 'warn', 'single', { 'allowTemplateLiterals': true, 'avoidEscape': true } ],
'@typescript-eslint/no-empty-interface': [ 'warn', { 'allowSingleExtends': true } ],
'@typescript-eslint/naming-convention': [ 'warn', {
'selector': 'property',
'format': ['strictCamelCase', 'PascalCase']
}]
}, default_rules);
const extends_ts = [
'eslint:recommended',
'plugin:@typescript-eslint/recommended'
// 'plugin:@typescript-eslint/recommended-requiring-type-checking'
];
module.exports = {
plugins: [ 'es' , 'tampermonkey' ],
env: {
browser: true,
es6: true
},
extends: [
],
parser: "@typescript-eslint/parser",
parserOptions: {
// project: './tsconfig.json',
ecmaVersion: 11,
sourceType: 'module',
ecmaFeatures: {
}
},
ignorePatterns: [ 'webpack.config.js' ], // , 'eslint/**/*.js' ],
rules: {
},
overrides: [
{
files: [ '**/*.ts' ],
extends: extends_ts,
parserOptions: {
project: [ './tsconfig.json' ]
},
rules: ts_rules
},
{
files: unsafe_env_ts,
extends: extends_ts,
rules: merge_rules({}, ts_rules, content_script_rules)
}
]
};