@origin-1/eslint-config 0.14.0 → 0.16.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/index.js +0 -5
- package/lib/create-config.d.ts +7 -3
- package/lib/create-config.js +115 -58
- package/lib/rules.js +3 -4
- package/package.json +6 -7
- package/patch-tslib.js +0 -23
package/index.js
CHANGED
|
@@ -13,11 +13,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
const patch_tslib_js_1 = __importDefault(require("./patch-tslib.js"));
|
|
21
|
-
(0, patch_tslib_js_1.default)(require);
|
|
22
17
|
__exportStar(require("./lib/create-config.js"), exports);
|
|
23
18
|
__exportStar(require("./lib/normalize-version.js"), exports);
|
package/lib/create-config.d.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { type JSVersion, type TSVersion } from './normalize-version.js';
|
|
2
2
|
import type { Linter } from 'eslint';
|
|
3
|
-
export interface ConfigData extends Linter.HasRules {
|
|
3
|
+
export interface ConfigData extends Linter.HasRules, LanguageConfigData {
|
|
4
4
|
env?: Linter.BaseConfig['env'];
|
|
5
5
|
extends?: string | string[] | undefined;
|
|
6
6
|
globals?: Linter.BaseConfig['globals'];
|
|
7
|
-
jsVersion?: JSVersion | undefined;
|
|
8
7
|
parser?: string | undefined;
|
|
9
8
|
parserOptions?: Linter.ParserOptions | undefined;
|
|
10
9
|
plugins?: string[] | undefined;
|
|
11
10
|
processor?: string | undefined;
|
|
12
|
-
tsVersion?: TSVersion | undefined;
|
|
13
11
|
}
|
|
14
12
|
export interface ConfigDataWithFiles extends ConfigData {
|
|
15
13
|
excludedFiles?: string | string[] | undefined;
|
|
16
14
|
files: string | string[];
|
|
17
15
|
}
|
|
16
|
+
export type FlatConfigData = Linter.FlatConfig & LanguageConfigData;
|
|
17
|
+
export interface LanguageConfigData {
|
|
18
|
+
jsVersion?: JSVersion | undefined;
|
|
19
|
+
tsVersion?: TSVersion | undefined;
|
|
20
|
+
}
|
|
18
21
|
export declare function createBaseConfig(configData: ConfigData): Linter.BaseConfig;
|
|
19
22
|
export declare function createConfig(...configDataList: ConfigDataWithFiles[]): Linter.Config;
|
|
23
|
+
export declare function createFlatConfig(...configDataList: FlatConfigData[]): Promise<Linter.FlatConfig[]>;
|
package/lib/create-config.js
CHANGED
|
@@ -3,10 +3,65 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createConfig = exports.createBaseConfig = void 0;
|
|
6
|
+
exports.createFlatConfig = exports.createConfig = exports.createBaseConfig = void 0;
|
|
7
7
|
const normalize_version_js_1 = require("./normalize-version.js");
|
|
8
8
|
const rules_js_1 = require("./rules.js");
|
|
9
9
|
const semver_1 = __importDefault(require("semver"));
|
|
10
|
+
function addLanguageRules(lang, jsVersion, tsVersion, rules, rulePrefixes) {
|
|
11
|
+
const setOverrideRule = (ruleKey, ruleLangSettings) => {
|
|
12
|
+
const ruleEntry = isVersionedList(ruleLangSettings) ?
|
|
13
|
+
findRuleEntry(ruleLangSettings, jsVersion, tsVersion) : ruleLangSettings;
|
|
14
|
+
rules[ruleKey] = cloneRuleEntry(ruleEntry);
|
|
15
|
+
};
|
|
16
|
+
for (const [ruleName, ruleSettings] of ruleSettingsFor(rules_js_1.RULES[rules_js_1.UNIQUE])) {
|
|
17
|
+
if (isJSTSEntry(ruleSettings)) {
|
|
18
|
+
const ruleLangSettings = ruleSettings[lang];
|
|
19
|
+
setOverrideRule(ruleName, ruleLangSettings);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
for (const [ruleName, ruleSettings] of ruleSettingsFor(rules_js_1.RULES[rules_js_1.HYBRID])) {
|
|
23
|
+
if (isRuleEntry(ruleSettings)) {
|
|
24
|
+
if (lang === 'ts') {
|
|
25
|
+
rules[ruleName] = 'off';
|
|
26
|
+
const typescriptESLintRuleKey = (0, rules_js_1.getRuleKey)('@typescript-eslint', ruleName);
|
|
27
|
+
rules[typescriptESLintRuleKey] = cloneRuleEntry(ruleSettings);
|
|
28
|
+
}
|
|
29
|
+
else
|
|
30
|
+
rules[ruleName] = cloneRuleEntry(ruleSettings);
|
|
31
|
+
}
|
|
32
|
+
if (isJSTSEntry(ruleSettings)) {
|
|
33
|
+
if (lang === 'ts') {
|
|
34
|
+
rules[ruleName] = 'off';
|
|
35
|
+
const typescriptESLintRuleKey = (0, rules_js_1.getRuleKey)('@typescript-eslint', ruleName);
|
|
36
|
+
setOverrideRule(typescriptESLintRuleKey, ruleSettings.ts);
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
setOverrideRule(ruleName, ruleSettings.js);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
for (const [pluginName, pluginSettings] of Object.entries(rules_js_1.RULES)) {
|
|
43
|
+
if (isPluginSettingsForLang(pluginSettings)) {
|
|
44
|
+
if (lang !== pluginSettings[rules_js_1.FOR_LANG])
|
|
45
|
+
continue;
|
|
46
|
+
const rulePrefix = (0, rules_js_1.getRulePrefix)(pluginName);
|
|
47
|
+
rulePrefixes.push(rulePrefix);
|
|
48
|
+
for (const [ruleName, ruleSettings] of ruleSettingsFor(pluginSettings)) {
|
|
49
|
+
const ruleKey = (0, rules_js_1.getRuleKey)(rulePrefix, ruleName);
|
|
50
|
+
setOverrideRule(ruleKey, ruleSettings);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const rulePrefix = (0, rules_js_1.getRulePrefix)(pluginName);
|
|
55
|
+
for (const [ruleName, ruleSettings] of ruleSettingsFor(pluginSettings)) {
|
|
56
|
+
if (isJSTSEntry(ruleSettings)) {
|
|
57
|
+
const ruleKey = (0, rules_js_1.getRuleKey)(rulePrefix, ruleName);
|
|
58
|
+
const ruleLangSettings = ruleSettings[lang];
|
|
59
|
+
setOverrideRule(ruleKey, ruleLangSettings);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
10
65
|
function cloneRuleEntry(ruleEntry) {
|
|
11
66
|
return structuredClone(ruleEntry);
|
|
12
67
|
}
|
|
@@ -68,64 +123,11 @@ function createBaseOverride(configData) {
|
|
|
68
123
|
Object.assign(env, configData.env);
|
|
69
124
|
const parserOptions = { ecmaVersion, ...configData.parserOptions };
|
|
70
125
|
const rules = {};
|
|
126
|
+
if (lang != null)
|
|
127
|
+
addLanguageRules(lang, jsVersion, tsVersion, rules, plugins);
|
|
71
128
|
const baseOverride = { env, parserOptions, plugins, rules };
|
|
72
129
|
if (parser != null)
|
|
73
130
|
baseOverride.parser = parser;
|
|
74
|
-
if (lang != null) {
|
|
75
|
-
const setOverrideRule = (ruleKey, ruleLangSettings) => {
|
|
76
|
-
const ruleEntry = isVersionedList(ruleLangSettings) ?
|
|
77
|
-
findRuleEntry(ruleLangSettings, jsVersion, tsVersion) : ruleLangSettings;
|
|
78
|
-
rules[ruleKey] = cloneRuleEntry(ruleEntry);
|
|
79
|
-
};
|
|
80
|
-
for (const [ruleName, ruleSettings] of ruleSettingsFor(rules_js_1.RULES[rules_js_1.UNIQUE])) {
|
|
81
|
-
if (isJSTSEntry(ruleSettings)) {
|
|
82
|
-
const ruleLangSettings = ruleSettings[lang];
|
|
83
|
-
setOverrideRule(ruleName, ruleLangSettings);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
for (const [ruleName, ruleSettings] of ruleSettingsFor(rules_js_1.RULES[rules_js_1.HYBRID])) {
|
|
87
|
-
if (isRuleEntry(ruleSettings)) {
|
|
88
|
-
if (lang === 'ts') {
|
|
89
|
-
rules[ruleName] = 'off';
|
|
90
|
-
const typescriptESLintRuleKey = (0, rules_js_1.getRuleKey)('@typescript-eslint', ruleName);
|
|
91
|
-
rules[typescriptESLintRuleKey] = cloneRuleEntry(ruleSettings);
|
|
92
|
-
}
|
|
93
|
-
else
|
|
94
|
-
rules[ruleName] = cloneRuleEntry(ruleSettings);
|
|
95
|
-
}
|
|
96
|
-
if (isJSTSEntry(ruleSettings)) {
|
|
97
|
-
if (lang === 'ts') {
|
|
98
|
-
rules[ruleName] = 'off';
|
|
99
|
-
const typescriptESLintRuleKey = (0, rules_js_1.getRuleKey)('@typescript-eslint', ruleName);
|
|
100
|
-
setOverrideRule(typescriptESLintRuleKey, ruleSettings.ts);
|
|
101
|
-
}
|
|
102
|
-
else
|
|
103
|
-
setOverrideRule(ruleName, ruleSettings.js);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
for (const [pluginName, pluginSettings] of Object.entries(rules_js_1.RULES)) {
|
|
107
|
-
if (isPluginSettingsForLang(pluginSettings)) {
|
|
108
|
-
if (lang !== pluginSettings[rules_js_1.FOR_LANG])
|
|
109
|
-
continue;
|
|
110
|
-
const rulePrefix = (0, rules_js_1.getRulePrefix)(pluginName);
|
|
111
|
-
plugins.push(rulePrefix);
|
|
112
|
-
for (const [ruleName, ruleSettings] of ruleSettingsFor(pluginSettings)) {
|
|
113
|
-
const ruleKey = (0, rules_js_1.getRuleKey)(rulePrefix, ruleName);
|
|
114
|
-
setOverrideRule(ruleKey, ruleSettings);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
const rulePrefix = (0, rules_js_1.getRulePrefix)(pluginName);
|
|
119
|
-
for (const [ruleName, ruleSettings] of ruleSettingsFor(pluginSettings)) {
|
|
120
|
-
if (isJSTSEntry(ruleSettings)) {
|
|
121
|
-
const ruleKey = (0, rules_js_1.getRuleKey)(rulePrefix, ruleName);
|
|
122
|
-
const ruleLangSettings = ruleSettings[lang];
|
|
123
|
-
setOverrideRule(ruleKey, ruleLangSettings);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
131
|
Object.assign(rules, configData.rules);
|
|
130
132
|
return baseOverride;
|
|
131
133
|
}
|
|
@@ -166,23 +168,69 @@ function createConfig(...configDataList) {
|
|
|
166
168
|
return config;
|
|
167
169
|
}
|
|
168
170
|
exports.createConfig = createConfig;
|
|
171
|
+
async function createFlatConfig(...configDataList) {
|
|
172
|
+
const promises = configDataList.map(createSingleFlatConfig);
|
|
173
|
+
return Promise.all(promises);
|
|
174
|
+
}
|
|
175
|
+
exports.createFlatConfig = createFlatConfig;
|
|
169
176
|
function createOverride(configData) {
|
|
170
177
|
const baseOverride = createBaseOverride(configData);
|
|
171
178
|
const { excludedFiles, extends: extends_, files, globals, processor } = configData;
|
|
172
179
|
const override = { ...baseOverride, excludedFiles, extends: extends_, files, globals, processor };
|
|
173
180
|
return override;
|
|
174
181
|
}
|
|
182
|
+
async function createSingleFlatConfig(configData) {
|
|
183
|
+
const { jsVersion: rawJSVersion, tsVersion: rawTSVersion, ...config } = configData;
|
|
184
|
+
if (rawJSVersion != null && rawTSVersion != null)
|
|
185
|
+
throw TypeError('`jsVersion` and `tsVersion` cannot be specified at the same time');
|
|
186
|
+
const lang = getLanguage(configData);
|
|
187
|
+
if (lang != null) {
|
|
188
|
+
const languageOptions = { ...config.languageOptions };
|
|
189
|
+
let { ecmaVersion, parser } = languageOptions;
|
|
190
|
+
let jsVersion;
|
|
191
|
+
let tsVersion;
|
|
192
|
+
switch (lang) {
|
|
193
|
+
case 'js':
|
|
194
|
+
jsVersion = (0, normalize_version_js_1.normalizeJSVersion)(rawJSVersion);
|
|
195
|
+
ecmaVersion ??= jsVersion;
|
|
196
|
+
parser ??= await importParser('espree');
|
|
197
|
+
break;
|
|
198
|
+
case 'ts':
|
|
199
|
+
tsVersion = (0, normalize_version_js_1.normalizeTSVersion)(rawTSVersion);
|
|
200
|
+
ecmaVersion ??= 'latest';
|
|
201
|
+
parser ??= await importParser('@typescript-eslint/parser');
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
languageOptions.ecmaVersion = ecmaVersion;
|
|
205
|
+
languageOptions.parser = parser;
|
|
206
|
+
const linterOptions = { ...config.linterOptions };
|
|
207
|
+
linterOptions.reportUnusedDisableDirectives ??= true;
|
|
208
|
+
const plugins = {};
|
|
209
|
+
const { plugins: rulePrefixes, rules } = createCommonEntries();
|
|
210
|
+
addLanguageRules(lang, jsVersion, tsVersion, rules, rulePrefixes);
|
|
211
|
+
const pluginPromises = rulePrefixes.map(importPlugin);
|
|
212
|
+
const pluginList = await Promise.all(pluginPromises);
|
|
213
|
+
rulePrefixes.forEach((rulePrefix, index) => {
|
|
214
|
+
plugins[rulePrefix] = pluginList[index];
|
|
215
|
+
});
|
|
216
|
+
config.languageOptions = languageOptions;
|
|
217
|
+
config.linterOptions = linterOptions;
|
|
218
|
+
config.plugins = Object.assign(plugins, config.plugins);
|
|
219
|
+
config.rules = Object.assign(rules, config.rules);
|
|
220
|
+
}
|
|
221
|
+
return config;
|
|
222
|
+
}
|
|
175
223
|
function findRuleEntry(versionedList, jsVersion, tsVersion) {
|
|
176
224
|
let index = versionedList.length;
|
|
177
225
|
while (index--) {
|
|
178
226
|
const { minVersion, ruleEntry } = versionedList[index];
|
|
179
227
|
switch (typeof minVersion) {
|
|
180
228
|
case 'number':
|
|
181
|
-
if (jsVersion >= minVersion)
|
|
229
|
+
if (jsVersion != null && jsVersion >= minVersion)
|
|
182
230
|
return ruleEntry;
|
|
183
231
|
break;
|
|
184
232
|
case 'string':
|
|
185
|
-
if (tsVersion === 'latest' || semver_1.default.gte(tsVersion, minVersion))
|
|
233
|
+
if (tsVersion != null && (tsVersion === 'latest' || semver_1.default.gte(tsVersion, minVersion)))
|
|
186
234
|
return ruleEntry;
|
|
187
235
|
break;
|
|
188
236
|
default:
|
|
@@ -196,6 +244,15 @@ function getLanguage(configData) {
|
|
|
196
244
|
if (configData.jsVersion != null)
|
|
197
245
|
return 'js';
|
|
198
246
|
}
|
|
247
|
+
async function importParser(parserName) {
|
|
248
|
+
const parser = await import(parserName);
|
|
249
|
+
return parser;
|
|
250
|
+
}
|
|
251
|
+
async function importPlugin(pluginName) {
|
|
252
|
+
const pkgName = pluginName.startsWith('@') ? `${pluginName}/eslint-plugin` : `eslint-plugin-${pluginName}`;
|
|
253
|
+
const { default: plugin } = await import(pkgName);
|
|
254
|
+
return plugin;
|
|
255
|
+
}
|
|
199
256
|
function isJSTSEntry(ruleSettings) {
|
|
200
257
|
return typeof ruleSettings === 'object' && 'js' in ruleSettings && 'ts' in ruleSettings;
|
|
201
258
|
}
|
package/lib/rules.js
CHANGED
|
@@ -87,7 +87,6 @@ exports.RULES = {
|
|
|
87
87
|
'block-scoped-var': 'off',
|
|
88
88
|
'camelcase': 'off',
|
|
89
89
|
'capitalized-comments': 'off',
|
|
90
|
-
'class-methods-use-this': 'off',
|
|
91
90
|
'complexity': 'off',
|
|
92
91
|
'consistent-return': 'off',
|
|
93
92
|
'consistent-this': 'off',
|
|
@@ -162,7 +161,7 @@ exports.RULES = {
|
|
|
162
161
|
'no-restricted-properties': 'off',
|
|
163
162
|
'no-restricted-syntax': ['error'],
|
|
164
163
|
'no-return-assign': ['error', 'always'],
|
|
165
|
-
'no-return-await':
|
|
164
|
+
'no-return-await': 'off',
|
|
166
165
|
'no-script-url': ['error'],
|
|
167
166
|
'no-sequences': ['error'],
|
|
168
167
|
'no-shadow-restricted-names': ['error'],
|
|
@@ -266,6 +265,7 @@ exports.RULES = {
|
|
|
266
265
|
'no-loss-of-precision': ['error'],
|
|
267
266
|
'no-unused-vars': beforeJSOrElse(2019, ['error', { ignoreRestSiblings: true, vars: 'local' }], ['error', { caughtErrors: 'all', ignoreRestSiblings: true, vars: 'local' }]),
|
|
268
267
|
'no-use-before-define': 'off',
|
|
268
|
+
'class-methods-use-this': 'off',
|
|
269
269
|
'default-param-last': 'off',
|
|
270
270
|
'dot-notation': ['error'],
|
|
271
271
|
'init-declarations': 'off',
|
|
@@ -351,7 +351,7 @@ exports.RULES = {
|
|
|
351
351
|
'no-import-type-side-effects': 'off',
|
|
352
352
|
'no-invalid-void-type': 'off',
|
|
353
353
|
'no-misused-new': ['error'],
|
|
354
|
-
'no-misused-promises': ['error'],
|
|
354
|
+
'no-misused-promises': ['error', { checksVoidReturn: false }],
|
|
355
355
|
'no-mixed-enums': ['error'],
|
|
356
356
|
'no-non-null-asserted-nullish-coalescing': ['error'],
|
|
357
357
|
'no-non-null-asserted-optional-chain': ['error'],
|
|
@@ -396,7 +396,6 @@ exports.RULES = {
|
|
|
396
396
|
'no-namespace': 'off',
|
|
397
397
|
'no-redundant-type-constituents': ['error'],
|
|
398
398
|
'no-this-alias': 'off',
|
|
399
|
-
'no-type-alias': 'off',
|
|
400
399
|
'no-unnecessary-boolean-literal-compare': ['error'],
|
|
401
400
|
'no-unnecessary-condition': ['error'],
|
|
402
401
|
'no-unnecessary-qualifier': ['error'],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@origin-1/eslint-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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",
|
|
@@ -12,18 +12,17 @@
|
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"@origin-1/eslint-plugin": ">=0.13",
|
|
15
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
16
|
-
"@typescript-eslint/parser": "^
|
|
15
|
+
"@typescript-eslint/eslint-plugin": "^6.2.0",
|
|
16
|
+
"@typescript-eslint/parser": "^6.2.0",
|
|
17
17
|
"eslint": "^8.37",
|
|
18
|
-
"eslint-plugin-n": "
|
|
18
|
+
"eslint-plugin-n": "16"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=18
|
|
21
|
+
"node": ">=18"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
".": "./index.js",
|
|
25
25
|
"./no-parser": "./no-parser.js",
|
|
26
|
-
"./package.json": "./package.json"
|
|
27
|
-
"./patch-tslib": "./patch-tslib.js"
|
|
26
|
+
"./package.json": "./package.json"
|
|
28
27
|
}
|
|
29
28
|
}
|
package/patch-tslib.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_module_1 = require("node:module");
|
|
4
|
-
function patchTslib(require) {
|
|
5
|
-
let tsutilsPath;
|
|
6
|
-
const { resolve } = require;
|
|
7
|
-
try {
|
|
8
|
-
tsutilsPath = resolve('tsutils');
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const tsutilsRequire = (0, node_module_1.createRequire)(tsutilsPath);
|
|
14
|
-
const originalGlobal = globalThis.global;
|
|
15
|
-
globalThis.global = {};
|
|
16
|
-
try {
|
|
17
|
-
tsutilsRequire('tslib');
|
|
18
|
-
}
|
|
19
|
-
finally {
|
|
20
|
-
globalThis.global = originalGlobal;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.default = patchTslib;
|