@origin-1/eslint-config 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/create-config.js +75 -55
- package/lib/rules.js +3 -1
- package/package.json +2 -2
package/lib/create-config.js
CHANGED
|
@@ -11,7 +11,15 @@ function cloneRuleEntry(ruleEntry) {
|
|
|
11
11
|
return structuredClone(ruleEntry);
|
|
12
12
|
}
|
|
13
13
|
function createBaseConfig(configData) {
|
|
14
|
-
|
|
14
|
+
let plugins;
|
|
15
|
+
let rules;
|
|
16
|
+
const lang = getLanguage(configData);
|
|
17
|
+
if (lang != null)
|
|
18
|
+
({ plugins, rules } = createCommonEntries());
|
|
19
|
+
else {
|
|
20
|
+
plugins = [];
|
|
21
|
+
rules = {};
|
|
22
|
+
}
|
|
15
23
|
const { env, parser, parserOptions, plugins: overridePlugins, rules: overrideRules } = createBaseOverride(configData);
|
|
16
24
|
plugins.push(...overridePlugins);
|
|
17
25
|
Object.assign(rules, overrideRules);
|
|
@@ -20,17 +28,19 @@ function createBaseConfig(configData) {
|
|
|
20
28
|
env,
|
|
21
29
|
extends: extends_,
|
|
22
30
|
globals,
|
|
23
|
-
parser,
|
|
24
31
|
parserOptions,
|
|
25
32
|
plugins,
|
|
26
33
|
reportUnusedDisableDirectives: true,
|
|
27
34
|
rules,
|
|
28
35
|
};
|
|
36
|
+
if (lang != null)
|
|
37
|
+
baseConfig.parser = parser;
|
|
29
38
|
return baseConfig;
|
|
30
39
|
}
|
|
31
40
|
exports.createBaseConfig = createBaseConfig;
|
|
32
41
|
function createBaseOverride(configData) {
|
|
33
|
-
const
|
|
42
|
+
const configPlugins = configData.plugins;
|
|
43
|
+
const plugins = configPlugins == null ? [] : [...configPlugins];
|
|
34
44
|
const lang = getLanguage(configData);
|
|
35
45
|
let ecmaVersion;
|
|
36
46
|
let envKey;
|
|
@@ -41,73 +51,80 @@ function createBaseOverride(configData) {
|
|
|
41
51
|
else if (jsVersion > 2015)
|
|
42
52
|
envKey = `es${jsVersion}`;
|
|
43
53
|
const tsVersion = (0, normalize_version_js_1.normalizeTSVersion)(configData.tsVersion);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
switch (lang) {
|
|
55
|
+
case 'js':
|
|
56
|
+
ecmaVersion = jsVersion;
|
|
57
|
+
parser = 'espree';
|
|
58
|
+
break;
|
|
59
|
+
case 'ts':
|
|
60
|
+
ecmaVersion = 'latest';
|
|
61
|
+
parser = '@typescript-eslint/parser';
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
break;
|
|
51
65
|
}
|
|
52
66
|
const env = envKey ? { [envKey]: true } : {};
|
|
53
67
|
Object.assign(env, configData.env);
|
|
54
68
|
const parserOptions = { ecmaVersion, ...configData.parserOptions };
|
|
55
69
|
const rules = {};
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (isRuleEntry(ruleSettings)) {
|
|
69
|
-
if (lang === 'ts') {
|
|
70
|
-
rules[ruleName] = 'off';
|
|
71
|
-
const typescriptESLintRuleKey = (0, rules_js_1.getRuleKey)('@typescript-eslint', ruleName);
|
|
72
|
-
rules[typescriptESLintRuleKey] = cloneRuleEntry(ruleSettings);
|
|
70
|
+
const baseOverride = { env, parserOptions, plugins, rules };
|
|
71
|
+
if (lang != null) {
|
|
72
|
+
baseOverride.parser = parser;
|
|
73
|
+
const setOverrideRule = (ruleKey, ruleLangSettings) => {
|
|
74
|
+
const ruleEntry = isVersionedList(ruleLangSettings) ?
|
|
75
|
+
findRuleEntry(ruleLangSettings, jsVersion, tsVersion) : ruleLangSettings;
|
|
76
|
+
rules[ruleKey] = cloneRuleEntry(ruleEntry);
|
|
77
|
+
};
|
|
78
|
+
for (const [ruleName, ruleSettings] of ruleSettingsFor(rules_js_1.RULES[rules_js_1.UNIQUE])) {
|
|
79
|
+
if (isJSTSEntry(ruleSettings)) {
|
|
80
|
+
const ruleLangSettings = ruleSettings[lang];
|
|
81
|
+
setOverrideRule(ruleName, ruleLangSettings);
|
|
73
82
|
}
|
|
74
|
-
else
|
|
75
|
-
rules[ruleName] = cloneRuleEntry(ruleSettings);
|
|
76
83
|
}
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
for (const [ruleName, ruleSettings] of ruleSettingsFor(rules_js_1.RULES[rules_js_1.HYBRID])) {
|
|
85
|
+
if (isRuleEntry(ruleSettings)) {
|
|
86
|
+
if (lang === 'ts') {
|
|
87
|
+
rules[ruleName] = 'off';
|
|
88
|
+
const typescriptESLintRuleKey = (0, rules_js_1.getRuleKey)('@typescript-eslint', ruleName);
|
|
89
|
+
rules[typescriptESLintRuleKey] = cloneRuleEntry(ruleSettings);
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
rules[ruleName] = cloneRuleEntry(ruleSettings);
|
|
82
93
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const rulePrefix = (0, rules_js_1.getRulePrefix)(pluginName);
|
|
92
|
-
plugins.push(rulePrefix);
|
|
93
|
-
for (const [ruleName, ruleSettings] of ruleSettingsFor(pluginSettings)) {
|
|
94
|
-
const ruleKey = (0, rules_js_1.getRuleKey)(rulePrefix, ruleName);
|
|
95
|
-
setOverrideRule(ruleKey, ruleSettings);
|
|
94
|
+
if (isJSTSEntry(ruleSettings)) {
|
|
95
|
+
if (lang === 'ts') {
|
|
96
|
+
rules[ruleName] = 'off';
|
|
97
|
+
const typescriptESLintRuleKey = (0, rules_js_1.getRuleKey)('@typescript-eslint', ruleName);
|
|
98
|
+
setOverrideRule(typescriptESLintRuleKey, ruleSettings.ts);
|
|
99
|
+
}
|
|
100
|
+
else
|
|
101
|
+
setOverrideRule(ruleName, ruleSettings.js);
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
for (const [pluginName, pluginSettings] of Object.entries(rules_js_1.RULES)) {
|
|
105
|
+
if (isPluginSettingsForLang(pluginSettings)) {
|
|
106
|
+
if (lang !== pluginSettings[rules_js_1.FOR_LANG])
|
|
107
|
+
continue;
|
|
108
|
+
const rulePrefix = (0, rules_js_1.getRulePrefix)(pluginName);
|
|
109
|
+
plugins.push(rulePrefix);
|
|
110
|
+
for (const [ruleName, ruleSettings] of ruleSettingsFor(pluginSettings)) {
|
|
102
111
|
const ruleKey = (0, rules_js_1.getRuleKey)(rulePrefix, ruleName);
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
setOverrideRule(ruleKey, ruleSettings);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const rulePrefix = (0, rules_js_1.getRulePrefix)(pluginName);
|
|
117
|
+
for (const [ruleName, ruleSettings] of ruleSettingsFor(pluginSettings)) {
|
|
118
|
+
if (isJSTSEntry(ruleSettings)) {
|
|
119
|
+
const ruleKey = (0, rules_js_1.getRuleKey)(rulePrefix, ruleName);
|
|
120
|
+
const ruleLangSettings = ruleSettings[lang];
|
|
121
|
+
setOverrideRule(ruleKey, ruleLangSettings);
|
|
122
|
+
}
|
|
105
123
|
}
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
126
|
}
|
|
109
127
|
Object.assign(rules, configData.rules);
|
|
110
|
-
const baseOverride = { env, parser, parserOptions, plugins, rules };
|
|
111
128
|
return baseOverride;
|
|
112
129
|
}
|
|
113
130
|
function createCommonEntries() {
|
|
@@ -172,7 +189,10 @@ function findRuleEntry(versionedList, jsVersion, tsVersion) {
|
|
|
172
189
|
}
|
|
173
190
|
}
|
|
174
191
|
function getLanguage(configData) {
|
|
175
|
-
|
|
192
|
+
if (configData.tsVersion != null)
|
|
193
|
+
return 'ts';
|
|
194
|
+
if (configData.jsVersion != null)
|
|
195
|
+
return 'js';
|
|
176
196
|
}
|
|
177
197
|
function isJSTSEntry(ruleSettings) {
|
|
178
198
|
return typeof ruleSettings === 'object' && 'js' in ruleSettings && 'ts' in ruleSettings;
|
package/lib/rules.js
CHANGED
|
@@ -58,7 +58,8 @@ exports.RULES = {
|
|
|
58
58
|
'no-invalid-regexp': 'error',
|
|
59
59
|
'no-irregular-whitespace': 'error',
|
|
60
60
|
'no-misleading-character-class': 'error',
|
|
61
|
-
'no-new-
|
|
61
|
+
'no-new-native-nonconstructor': 'error',
|
|
62
|
+
'no-new-symbol': 'off',
|
|
62
63
|
'no-obj-calls': 'error',
|
|
63
64
|
'no-promise-executor-return': 'error',
|
|
64
65
|
'no-prototype-builtins': 'off',
|
|
@@ -123,6 +124,7 @@ exports.RULES = {
|
|
|
123
124
|
'no-div-regex': 'error',
|
|
124
125
|
'no-else-return': 'error',
|
|
125
126
|
'no-empty': ['error', { allowEmptyCatch: true }],
|
|
127
|
+
'no-empty-static-block': 'error',
|
|
126
128
|
'no-eq-null': 'off',
|
|
127
129
|
'no-eval': 'off',
|
|
128
130
|
'no-extend-native': 'error',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@origin-1/eslint-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "ESLint configuration generator with Origin₁ presets",
|
|
5
5
|
"homepage": "https://github.com/origin-1/eslint-config#readme",
|
|
6
6
|
"license": "ISC",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@origin-1/eslint-plugin": "0.7",
|
|
15
15
|
"@typescript-eslint/eslint-plugin": "^5.42",
|
|
16
16
|
"@typescript-eslint/parser": "^5.42",
|
|
17
|
-
"eslint": "^8.
|
|
17
|
+
"eslint": "^8.27.0",
|
|
18
18
|
"eslint-plugin-n": "15"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|