@ncontiero/eslint-config 7.3.0-beta.0 → 7.3.0-beta.1
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/dist/index.d.mts +47 -2
- package/dist/index.mjs +58 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -16695,6 +16695,9 @@ declare const hasTailwind: boolean;
|
|
|
16695
16695
|
declare const hasTanStackReactQuery: boolean;
|
|
16696
16696
|
//#endregion
|
|
16697
16697
|
//#region src/factory.d.ts
|
|
16698
|
+
declare const defaultPluginRenaming: {
|
|
16699
|
+
"@eslint-react": string;
|
|
16700
|
+
};
|
|
16698
16701
|
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
16699
16702
|
declare function resolveSubOptions<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): ResolvedOptions<OptionsConfig[K]>;
|
|
16700
16703
|
declare function getOverrides<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): Partial<Linter.RulesRecord & Rules>;
|
|
@@ -16769,7 +16772,49 @@ declare function interopDefault<T>(m: Awaitable<T>): Promise<T extends {
|
|
|
16769
16772
|
default: infer U;
|
|
16770
16773
|
} ? U : T>;
|
|
16771
16774
|
declare function ensurePackages(packages: (string | undefined)[]): void;
|
|
16772
|
-
|
|
16775
|
+
interface ComposerOptions {
|
|
16776
|
+
items: Awaitable<FlatConfigItem[]>[];
|
|
16777
|
+
pluginsNameMap?: Record<string, string>;
|
|
16778
|
+
}
|
|
16779
|
+
declare function composer({
|
|
16780
|
+
items,
|
|
16781
|
+
pluginsNameMap
|
|
16782
|
+
}: ComposerOptions): Promise<FlatConfigItem[]>;
|
|
16783
|
+
/**
|
|
16784
|
+
* Rename plugin prefixes in a rule object.
|
|
16785
|
+
* Accepts a map of prefixes to rename.
|
|
16786
|
+
*
|
|
16787
|
+
* @example
|
|
16788
|
+
* ```ts
|
|
16789
|
+
* import { renameRules } from "@ncontiero/eslint-config";
|
|
16790
|
+
*
|
|
16791
|
+
* export default [
|
|
16792
|
+
* {
|
|
16793
|
+
* rules: renameRules(
|
|
16794
|
+
* {
|
|
16795
|
+
* "@typescript-eslint/indent": "error",
|
|
16796
|
+
* },
|
|
16797
|
+
* { "@typescript-eslint": "ts" },
|
|
16798
|
+
* ),
|
|
16799
|
+
* },
|
|
16800
|
+
* ];
|
|
16801
|
+
* ```
|
|
16802
|
+
*/
|
|
16803
|
+
declare function renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any>;
|
|
16804
|
+
/**
|
|
16805
|
+
* Rename plugin names a flat configs array
|
|
16806
|
+
*
|
|
16807
|
+
* @example
|
|
16808
|
+
* ```ts
|
|
16809
|
+
* import { renamePluginInConfigs } from "@ncontiero/eslint-config";
|
|
16810
|
+
* import someConfigs from "./some-configs";
|
|
16811
|
+
*
|
|
16812
|
+
* export default renamePluginInConfigs(someConfigs, {
|
|
16813
|
+
* "@typescript-eslint": "ts",
|
|
16814
|
+
* });
|
|
16815
|
+
* ```
|
|
16816
|
+
*/
|
|
16817
|
+
declare function renamePluginInConfigs(configs: FlatConfigItem[], map: Record<string, string>): FlatConfigItem[];
|
|
16773
16818
|
declare function toArray<T>(value: T | T[]): T[];
|
|
16774
16819
|
//#endregion
|
|
16775
|
-
export { Awaitable, FlatConfigItem, GLOB_ALL_SRC, GLOB_CSS, GLOB_DIST, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_LOCKFILE, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_NODE_MODULES, GLOB_POSTCSS, GLOB_REACT, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_YAML, HTMLOptions, OptionsConfig, OptionsFiles, OptionsHasNextJs, OptionsHasRegexp, OptionsHasTanStackReactQuery, OptionsHasTypeScript, OptionsOverrides, OptionsTailwindCSS, OptionsTypeScriptParserOptions, OptionsTypescript, OptionsUnicorn, PrettierOptions, ResolvedOptions, Rules, StyleConfig, StyleOptions, combine, command, comments, composer, deMorgan, ensurePackages, getOverrides, hasNextJs, hasReact, hasTailwind, hasTanStackReactQuery, hasTypeScript, html, ignores, imports, interopDefault, javascript, jsdoc, jsonc, markdown, ncontiero, nextJs, node, parserPlain, perfectionist, prettier, promise, react, regexp, resolveSubOptions, restrictedSyntaxJs, sortPackageJson, sortPnpmWorkspace, sortTsconfig, tailwindcss, toArray, toml, typescript, unicorn, yml };
|
|
16820
|
+
export { Awaitable, ComposerOptions, FlatConfigItem, GLOB_ALL_SRC, GLOB_CSS, GLOB_DIST, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_LOCKFILE, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_NODE_MODULES, GLOB_POSTCSS, GLOB_REACT, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_YAML, HTMLOptions, OptionsConfig, OptionsFiles, OptionsHasNextJs, OptionsHasRegexp, OptionsHasTanStackReactQuery, OptionsHasTypeScript, OptionsOverrides, OptionsTailwindCSS, OptionsTypeScriptParserOptions, OptionsTypescript, OptionsUnicorn, PrettierOptions, ResolvedOptions, Rules, StyleConfig, StyleOptions, combine, command, comments, composer, deMorgan, defaultPluginRenaming, ensurePackages, getOverrides, hasNextJs, hasReact, hasTailwind, hasTanStackReactQuery, hasTypeScript, html, ignores, imports, interopDefault, javascript, jsdoc, jsonc, markdown, ncontiero, nextJs, node, parserPlain, perfectionist, prettier, promise, react, regexp, renamePluginInConfigs, renameRules, resolveSubOptions, restrictedSyntaxJs, sortPackageJson, sortPnpmWorkspace, sortTsconfig, tailwindcss, toArray, toml, typescript, unicorn, yml };
|
package/dist/index.mjs
CHANGED
|
@@ -153,12 +153,63 @@ function ensurePackages(packages) {
|
|
|
153
153
|
if (nonExistingPackages.length === 0) return;
|
|
154
154
|
throw new Error(`This package(s) are required for this config: ${nonExistingPackages.join(", ")}. Please install them.`);
|
|
155
155
|
}
|
|
156
|
-
async function composer(
|
|
156
|
+
async function composer({ items, pluginsNameMap }) {
|
|
157
157
|
let configs = [];
|
|
158
158
|
const flatResolved = (await Promise.all(items)).flat();
|
|
159
159
|
configs = [...configs, ...flatResolved];
|
|
160
|
+
if (pluginsNameMap) configs = renamePluginInConfigs(configs, pluginsNameMap);
|
|
160
161
|
return configs;
|
|
161
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Rename plugin prefixes in a rule object.
|
|
165
|
+
* Accepts a map of prefixes to rename.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* import { renameRules } from "@ncontiero/eslint-config";
|
|
170
|
+
*
|
|
171
|
+
* export default [
|
|
172
|
+
* {
|
|
173
|
+
* rules: renameRules(
|
|
174
|
+
* {
|
|
175
|
+
* "@typescript-eslint/indent": "error",
|
|
176
|
+
* },
|
|
177
|
+
* { "@typescript-eslint": "ts" },
|
|
178
|
+
* ),
|
|
179
|
+
* },
|
|
180
|
+
* ];
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
function renameRules(rules, map) {
|
|
184
|
+
return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
|
|
185
|
+
for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
|
|
186
|
+
return [key, value];
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Rename plugin names a flat configs array
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* import { renamePluginInConfigs } from "@ncontiero/eslint-config";
|
|
195
|
+
* import someConfigs from "./some-configs";
|
|
196
|
+
*
|
|
197
|
+
* export default renamePluginInConfigs(someConfigs, {
|
|
198
|
+
* "@typescript-eslint": "ts",
|
|
199
|
+
* });
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
function renamePluginInConfigs(configs, map) {
|
|
203
|
+
return configs.map((i) => {
|
|
204
|
+
const clone = { ...i };
|
|
205
|
+
if (clone.rules) clone.rules = renameRules(clone.rules, map);
|
|
206
|
+
if (clone.plugins) clone.plugins = Object.fromEntries(Object.entries(clone.plugins).map(([key, value]) => {
|
|
207
|
+
if (key in map) return [map[key], value];
|
|
208
|
+
return [key, value];
|
|
209
|
+
}));
|
|
210
|
+
return clone;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
162
213
|
function toArray(value) {
|
|
163
214
|
return Array.isArray(value) ? value : [value];
|
|
164
215
|
}
|
|
@@ -1557,6 +1608,7 @@ const flatConfigProps = [
|
|
|
1557
1608
|
"rules",
|
|
1558
1609
|
"settings"
|
|
1559
1610
|
];
|
|
1611
|
+
const defaultPluginRenaming = { "@eslint-react": "react" };
|
|
1560
1612
|
function resolveSubOptions(options, key) {
|
|
1561
1613
|
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
|
1562
1614
|
}
|
|
@@ -1636,7 +1688,10 @@ function ncontiero(options = {}, ...userConfigs) {
|
|
|
1636
1688
|
return acc;
|
|
1637
1689
|
}, {});
|
|
1638
1690
|
if (Object.keys(fusedConfig).length > 0) configs.push([fusedConfig]);
|
|
1639
|
-
return composer(
|
|
1691
|
+
return composer({
|
|
1692
|
+
items: [...configs, ...userConfigs],
|
|
1693
|
+
pluginsNameMap: defaultPluginRenaming
|
|
1694
|
+
});
|
|
1640
1695
|
}
|
|
1641
1696
|
//#endregion
|
|
1642
|
-
export { GLOB_ALL_SRC, GLOB_CSS, GLOB_DIST, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_LOCKFILE, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_NODE_MODULES, GLOB_POSTCSS, GLOB_REACT, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_YAML, combine, command, comments, composer, deMorgan, ensurePackages, getOverrides, hasNextJs, hasReact, hasTailwind, hasTanStackReactQuery, hasTypeScript, html, ignores, imports, interopDefault, javascript, jsdoc, jsonc, markdown, ncontiero, nextJs, node, parserPlain, perfectionist, prettier, promise, react, regexp, resolveSubOptions, restrictedSyntaxJs, sortPackageJson, sortPnpmWorkspace, sortTsconfig, tailwindcss, toArray, toml, typescript, unicorn, yml };
|
|
1697
|
+
export { GLOB_ALL_SRC, GLOB_CSS, GLOB_DIST, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_LOCKFILE, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_NODE_MODULES, GLOB_POSTCSS, GLOB_REACT, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_YAML, combine, command, comments, composer, deMorgan, defaultPluginRenaming, ensurePackages, getOverrides, hasNextJs, hasReact, hasTailwind, hasTanStackReactQuery, hasTypeScript, html, ignores, imports, interopDefault, javascript, jsdoc, jsonc, markdown, ncontiero, nextJs, node, parserPlain, perfectionist, prettier, promise, react, regexp, renamePluginInConfigs, renameRules, resolveSubOptions, restrictedSyntaxJs, sortPackageJson, sortPnpmWorkspace, sortTsconfig, tailwindcss, toArray, toml, typescript, unicorn, yml };
|