@leancodepl/resolve-eslint-flat-config 9.5.2
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/README.md +37 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +44 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -0
- package/index.esm.js +42 -0
- package/package.json +51 -0
- package/src/index.d.ts +1 -0
- package/src/lib/resolveFlatConfig.d.ts +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @leancodepl/resolve-eslint-flat-config
|
|
2
|
+
|
|
3
|
+
A TypeScript library for resolving ESLint flat config plugin collisions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @leancodepl/resolve-eslint-flat-config
|
|
9
|
+
# or
|
|
10
|
+
yarn add --dev @leancodepl/resolve-eslint-flat-config
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
### `resolveFlatConfig(allModules)`
|
|
16
|
+
|
|
17
|
+
Resolves ESLint flat config by merging plugins and separating configurations.
|
|
18
|
+
|
|
19
|
+
**Parameters:**
|
|
20
|
+
|
|
21
|
+
- `allModules` (`Linter.Config[]`, **required**) - Array of ESLint flat config objects to merge
|
|
22
|
+
|
|
23
|
+
**Returns:** Array containing merged plugins object followed by individual configs
|
|
24
|
+
|
|
25
|
+
## Usage Examples
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
// eslint.config.js
|
|
29
|
+
const { resolveFlatConfig } = require("@leancodepl/resolve-eslint-flat-config")
|
|
30
|
+
|
|
31
|
+
const customConfigs = [
|
|
32
|
+
{ plugins: { custom: customPlugin }, rules: { "custom/rule": "error" } },
|
|
33
|
+
{ plugins: { another: anotherPlugin }, rules: { "another/rule": "warn" } },
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
export default resolveFlatConfig(customConfigs)
|
|
37
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./index.cjs.js').default;
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _object_without_properties_loose(source, excluded) {
|
|
4
|
+
if (source == null) return {};
|
|
5
|
+
var target = {};
|
|
6
|
+
var sourceKeys = Object.keys(source);
|
|
7
|
+
var key, i;
|
|
8
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
9
|
+
key = sourceKeys[i];
|
|
10
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
11
|
+
target[key] = source[key];
|
|
12
|
+
}
|
|
13
|
+
return target;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Resolves flat config issue: https://github.com/eslint/eslintrc/issues/135
|
|
17
|
+
function resolveFlatConfig(allModules) {
|
|
18
|
+
const plugins = {};
|
|
19
|
+
const configsWithoutPlugins = [];
|
|
20
|
+
allModules.forEach((config)=>{
|
|
21
|
+
if (config.plugins) {
|
|
22
|
+
Object.assign(plugins, config.plugins);
|
|
23
|
+
const { plugins: _ignoredPlugins } = config, configWithoutPlugins = _object_without_properties_loose(config, [
|
|
24
|
+
"plugins"
|
|
25
|
+
]);
|
|
26
|
+
if (Object.keys(configWithoutPlugins).length) {
|
|
27
|
+
configsWithoutPlugins.push(configWithoutPlugins);
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
configsWithoutPlugins.push(config);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (Object.keys(plugins).length) {
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
plugins
|
|
37
|
+
},
|
|
38
|
+
...configsWithoutPlugins
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
return configsWithoutPlugins;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
exports.resolveFlatConfig = resolveFlatConfig;
|
package/index.cjs.mjs
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.esm.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function _object_without_properties_loose(source, excluded) {
|
|
2
|
+
if (source == null) return {};
|
|
3
|
+
var target = {};
|
|
4
|
+
var sourceKeys = Object.keys(source);
|
|
5
|
+
var key, i;
|
|
6
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
7
|
+
key = sourceKeys[i];
|
|
8
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
9
|
+
target[key] = source[key];
|
|
10
|
+
}
|
|
11
|
+
return target;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Resolves flat config issue: https://github.com/eslint/eslintrc/issues/135
|
|
15
|
+
function resolveFlatConfig(allModules) {
|
|
16
|
+
const plugins = {};
|
|
17
|
+
const configsWithoutPlugins = [];
|
|
18
|
+
allModules.forEach((config)=>{
|
|
19
|
+
if (config.plugins) {
|
|
20
|
+
Object.assign(plugins, config.plugins);
|
|
21
|
+
const { plugins: _ignoredPlugins } = config, configWithoutPlugins = _object_without_properties_loose(config, [
|
|
22
|
+
"plugins"
|
|
23
|
+
]);
|
|
24
|
+
if (Object.keys(configWithoutPlugins).length) {
|
|
25
|
+
configsWithoutPlugins.push(configWithoutPlugins);
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
configsWithoutPlugins.push(config);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
if (Object.keys(plugins).length) {
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
plugins
|
|
35
|
+
},
|
|
36
|
+
...configsWithoutPlugins
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
return configsWithoutPlugins;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { resolveFlatConfig };
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leancodepl/resolve-eslint-flat-config",
|
|
3
|
+
"version": "9.5.2",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"eslint": ">=8.9.0"
|
|
7
|
+
},
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"registry": "https://registry.npmjs.org/"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=18.0.0"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/leancodepl/js_corelibrary.git",
|
|
18
|
+
"directory": "packages/linters/resolve-eslint-flat-config"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/leancodepl/js_corelibrary",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/leancodepl/js_corelibrary/issues"
|
|
23
|
+
},
|
|
24
|
+
"description": "Resolve ESlint flat config plugin collisions",
|
|
25
|
+
"keywords": [
|
|
26
|
+
"eslint",
|
|
27
|
+
"flat",
|
|
28
|
+
"config",
|
|
29
|
+
"linting",
|
|
30
|
+
"javascript",
|
|
31
|
+
"typescript",
|
|
32
|
+
"leancode"
|
|
33
|
+
],
|
|
34
|
+
"author": {
|
|
35
|
+
"name": "LeanCode",
|
|
36
|
+
"url": "https://leancode.co"
|
|
37
|
+
},
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"exports": {
|
|
40
|
+
"./package.json": "./package.json",
|
|
41
|
+
".": {
|
|
42
|
+
"module": "./index.esm.js",
|
|
43
|
+
"types": "./index.d.ts",
|
|
44
|
+
"import": "./index.cjs.mjs",
|
|
45
|
+
"default": "./index.cjs.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"module": "./index.esm.js",
|
|
49
|
+
"main": "./index.cjs.js",
|
|
50
|
+
"types": "./index.d.ts"
|
|
51
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveFlatConfig } from "./lib/resolveFlatConfig";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves ESLint flat config by merging plugins and separating configurations.
|
|
3
|
+
*
|
|
4
|
+
* Combines plugins from multiple ESLint configurations into a single plugins object,
|
|
5
|
+
* then returns an array with the merged plugins followed by the individual configs
|
|
6
|
+
* without their plugins.
|
|
7
|
+
*
|
|
8
|
+
* @param allModules - Array of ESLint flat config objects to merge
|
|
9
|
+
* @returns Array containing merged plugins object followed by individual configs
|
|
10
|
+
* @example
|
|
11
|
+
* ```javascript
|
|
12
|
+
* const configs = [
|
|
13
|
+
* { plugins: { react: reactPlugin }, rules: { "react/jsx-uses-react": "error" } },
|
|
14
|
+
* { plugins: { typescript: tsPlugin }, rules: { "@typescript-eslint/no-unused-vars": "error" } }
|
|
15
|
+
* ]
|
|
16
|
+
*
|
|
17
|
+
* const resolved = resolveFlatConfig(configs)
|
|
18
|
+
* // Returns: [
|
|
19
|
+
* // { plugins: { react: reactPlugin, typescript: tsPlugin } },
|
|
20
|
+
* // { rules: { "react/jsx-uses-react": "error" } },
|
|
21
|
+
* // { rules: { "@typescript-eslint/no-unused-vars": "error" } }
|
|
22
|
+
* // ]
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { Linter } from "eslint";
|
|
26
|
+
export declare function resolveFlatConfig(allModules: Linter.Config[]): Linter.Config[];
|