@zayne-labs/eslint-config 0.9.12 → 0.9.14
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/cli/index.js +16 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +115 -35
- package/dist/index.js +91 -23
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, defineEnum, isObject as isObject$1 } from "@zayne-labs/toolkit-type-helpers";
|
|
1
|
+
import { assert, defineEnum, isFunction, isObject as isObject$1 } from "@zayne-labs/toolkit-type-helpers";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { isPackageExists } from "local-pkg";
|
|
4
4
|
import { globalIgnores } from "eslint/config";
|
|
@@ -24,7 +24,7 @@ const GLOB_JSON5 = "**/*.json5";
|
|
|
24
24
|
const GLOB_JSONC = "**/*.jsonc";
|
|
25
25
|
const GLOB_MARKDOWN = "**/*.md";
|
|
26
26
|
const GLOB_MARKDOWN_IN_MARKDOWN = "**/*.md/*.md";
|
|
27
|
-
const GLOB_SVELTE = "**/*.svelte";
|
|
27
|
+
const GLOB_SVELTE = "**/*.svelte?(.{js,ts})";
|
|
28
28
|
const GLOB_VUE = "**/*.vue";
|
|
29
29
|
const GLOB_YAML = "**/*.y?(a)ml";
|
|
30
30
|
const GLOB_TOML = "**/*.toml";
|
|
@@ -138,28 +138,89 @@ const renamePlugins = (plugins, renameMap) => {
|
|
|
138
138
|
});
|
|
139
139
|
return Object.fromEntries(renamedPluginEntries);
|
|
140
140
|
};
|
|
141
|
+
const getResolvedOverrides = (options) => {
|
|
142
|
+
const { configItem, overrides } = options;
|
|
143
|
+
return isFunction(overrides) ? overrides(configItem) : overrides;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* @description - Override configurations in a flat configs array with either a static config object or a function that returns a config object
|
|
147
|
+
* @param options - Configuration options
|
|
148
|
+
* @param options.configs - Array of flat config items to override
|
|
149
|
+
* @param options.overrides - Either a config object to merge or a function that takes a config and returns overrides
|
|
150
|
+
* @returns Array of merged config items with overrides applied
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { overrideConfigs } from '@zayne-labs/eslint-config'
|
|
155
|
+
*
|
|
156
|
+
* // Override with static config
|
|
157
|
+
* overrideConfigs({
|
|
158
|
+
* configArray: existingConfigs,
|
|
159
|
+
* overrides: {
|
|
160
|
+
* rules: {
|
|
161
|
+
* 'no-console': 'error'
|
|
162
|
+
* }
|
|
163
|
+
* }
|
|
164
|
+
* })
|
|
165
|
+
*
|
|
166
|
+
* // Override with function
|
|
167
|
+
* overrideConfigs({
|
|
168
|
+
* configArray: existingConfigs,
|
|
169
|
+
* overrides: (config) => ({
|
|
170
|
+
* ...config,
|
|
171
|
+
* rules: {
|
|
172
|
+
* ...config.rules,
|
|
173
|
+
* 'no-console': 'error'
|
|
174
|
+
* }
|
|
175
|
+
* })
|
|
176
|
+
* })
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
const overrideConfigs = (options) => {
|
|
180
|
+
const { configArray, overrides } = options;
|
|
181
|
+
return configArray.map((configItem) => ({
|
|
182
|
+
...configItem,
|
|
183
|
+
...getResolvedOverrides({
|
|
184
|
+
configItem,
|
|
185
|
+
overrides
|
|
186
|
+
})
|
|
187
|
+
}));
|
|
188
|
+
};
|
|
141
189
|
/**
|
|
142
|
-
* @description - Rename plugin names a flat configs array
|
|
190
|
+
* @description - Rename plugin names and rules in a flat configs array
|
|
191
|
+
*
|
|
192
|
+
* @param options - Configuration options
|
|
193
|
+
* @param options.configArray - Array of flat config items to process
|
|
194
|
+
* @param options.overrides - Optional config overrides to apply
|
|
195
|
+
* @param options.renameMap - Map of old plugin names to new names
|
|
143
196
|
*
|
|
144
197
|
* @example
|
|
145
198
|
* ```ts
|
|
146
199
|
* import { renamePluginInConfigs } from '@zayne-labs/eslint-config'
|
|
147
200
|
* import someConfigs from './some-configs'
|
|
148
201
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
202
|
+
* renamePluginInConfigs({
|
|
203
|
+
* configArray: someConfigs,
|
|
204
|
+
* renameMap: {
|
|
205
|
+
* '@typescript-eslint': 'ts',
|
|
206
|
+
* 'import-x': 'import',
|
|
207
|
+
* }
|
|
152
208
|
* })
|
|
153
209
|
* ```
|
|
154
210
|
*/
|
|
155
211
|
const renamePluginInConfigs = (options) => {
|
|
156
|
-
const {
|
|
157
|
-
const renamedConfigs =
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
212
|
+
const { configArray, overrides, renameMap } = options;
|
|
213
|
+
const renamedConfigs = overrideConfigs({
|
|
214
|
+
configArray,
|
|
215
|
+
overrides: (configItem) => ({
|
|
216
|
+
...getResolvedOverrides({
|
|
217
|
+
configItem,
|
|
218
|
+
overrides
|
|
219
|
+
}),
|
|
220
|
+
...isObject(configItem.plugins) && { plugins: renamePlugins(configItem.plugins, renameMap) },
|
|
221
|
+
...isObject(configItem.rules) && { rules: renameRules(configItem.rules, renameMap) }
|
|
222
|
+
})
|
|
223
|
+
});
|
|
163
224
|
return renamedConfigs;
|
|
164
225
|
};
|
|
165
226
|
const scopeUrl = fileURLToPath(new URL(".", import.meta.url));
|
|
@@ -272,8 +333,11 @@ const depend = async (options = {}) => {
|
|
|
272
333
|
const expo = async (options = {}) => {
|
|
273
334
|
const { overrides } = options;
|
|
274
335
|
await ensurePackages(["eslint-config-expo"]);
|
|
275
|
-
const eslintConfigExpo = await interopDefault(import("eslint-config-expo/flat/
|
|
276
|
-
return [
|
|
336
|
+
const eslintConfigExpo = await interopDefault(import("eslint-config-expo/flat/utils/expo.js"));
|
|
337
|
+
return [...overrideConfigs({
|
|
338
|
+
configArray: eslintConfigExpo,
|
|
339
|
+
overrides: { name: "zayne/expo/recommended" }
|
|
340
|
+
}), {
|
|
277
341
|
name: "zayne/expo/rules",
|
|
278
342
|
rules: { ...overrides }
|
|
279
343
|
}];
|
|
@@ -921,7 +985,7 @@ const defaultPluginRenameMap = defineEnum({
|
|
|
921
985
|
"@eslint-react/naming-convention": "react-naming-convention",
|
|
922
986
|
"@eslint-react/web-api": "react-web-api",
|
|
923
987
|
"@eslint-react": "react",
|
|
924
|
-
"@next/next": "nextjs
|
|
988
|
+
"@next/next": "nextjs",
|
|
925
989
|
"@stylistic": "stylistic",
|
|
926
990
|
"@tanstack/query": "tanstack-query",
|
|
927
991
|
"@tanstack/router": "tanstack-router",
|
|
@@ -950,7 +1014,11 @@ const allowedReactRouterExportNames = [
|
|
|
950
1014
|
"links",
|
|
951
1015
|
"headers",
|
|
952
1016
|
"loader",
|
|
953
|
-
"action"
|
|
1017
|
+
"action",
|
|
1018
|
+
"clientLoader",
|
|
1019
|
+
"clientAction",
|
|
1020
|
+
"handle",
|
|
1021
|
+
"shouldRevalidate"
|
|
954
1022
|
];
|
|
955
1023
|
|
|
956
1024
|
//#endregion
|
|
@@ -1055,7 +1123,7 @@ const react = async (options = {}) => {
|
|
|
1055
1123
|
if (nextjs && eslintPluginNextjs) config.push({
|
|
1056
1124
|
files,
|
|
1057
1125
|
name: "zayne/react/nextjs",
|
|
1058
|
-
plugins: {
|
|
1126
|
+
plugins: { nextjs: fixupPluginRules(eslintPluginNextjs) },
|
|
1059
1127
|
rules: renameRules({
|
|
1060
1128
|
...eslintPluginNextjs.configs?.recommended?.rules,
|
|
1061
1129
|
...eslintPluginNextjs.configs?.["core-web-vitals"]?.rules,
|
|
@@ -1205,7 +1273,7 @@ const sortPackageJson = () => [{
|
|
|
1205
1273
|
* Requires `jsonc` config
|
|
1206
1274
|
*/
|
|
1207
1275
|
const sortTsconfig = () => [{
|
|
1208
|
-
files: ["**/
|
|
1276
|
+
files: ["**/[jt]sconfig.json", "**/[jt]sconfig.*.json"],
|
|
1209
1277
|
name: "zayne/sort/tsconfig.json",
|
|
1210
1278
|
rules: { "jsonc/sort-keys": [
|
|
1211
1279
|
"error",
|
|
@@ -1527,7 +1595,7 @@ const typescript = async (options = {}) => {
|
|
|
1527
1595
|
...isTypeAware && makeParser(filesTypeAware, ignoresTypeAware)
|
|
1528
1596
|
},
|
|
1529
1597
|
...renamePluginInConfigs({
|
|
1530
|
-
|
|
1598
|
+
configArray: tsEslint.configs[selectedBaseRuleSet],
|
|
1531
1599
|
overrides: {
|
|
1532
1600
|
files,
|
|
1533
1601
|
name: `zayne/ts-eslint/${selectedBaseRuleSet}`
|
|
@@ -1535,7 +1603,7 @@ const typescript = async (options = {}) => {
|
|
|
1535
1603
|
renameMap: { "@typescript-eslint": "ts-eslint" }
|
|
1536
1604
|
}),
|
|
1537
1605
|
...stylistic$1 ? renamePluginInConfigs({
|
|
1538
|
-
|
|
1606
|
+
configArray: tsEslint.configs[selectedStylisticRuleSet],
|
|
1539
1607
|
overrides: {
|
|
1540
1608
|
files,
|
|
1541
1609
|
name: `zayne/ts-eslint/${selectedStylisticRuleSet}`
|
|
@@ -1876,7 +1944,7 @@ const zayne = (options = {}, ...userConfigs) => {
|
|
|
1876
1944
|
const enableUnicorn = restOfOptions.unicorn ?? withDefaults;
|
|
1877
1945
|
const enableYaml = restOfOptions.yaml ?? withDefaults;
|
|
1878
1946
|
const isStylistic = Boolean(enableStylistic);
|
|
1879
|
-
const tsconfigPath = isObject(enableTypeScript) && "tsconfigPath" in enableTypeScript ? enableTypeScript.tsconfigPath :
|
|
1947
|
+
const tsconfigPath = isObject(enableTypeScript) && "tsconfigPath" in enableTypeScript ? enableTypeScript.tsconfigPath : enableTypeScript === true ? enableTypeScript : null;
|
|
1880
1948
|
const isTypeAware = Boolean(tsconfigPath);
|
|
1881
1949
|
const configs = [];
|
|
1882
1950
|
configs.push(ignores(restOfOptions.ignores), javascript(restOfOptions.javascript));
|
|
@@ -1959,5 +2027,5 @@ const zayne = (options = {}, ...userConfigs) => {
|
|
|
1959
2027
|
};
|
|
1960
2028
|
|
|
1961
2029
|
//#endregion
|
|
1962
|
-
export { GLOB_ALL_SRC, GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CSS, GLOB_EXCLUDE, GLOB_GRAPHQL, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLES, GLOB_SVELTE, GLOB_SVG, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_XML, GLOB_YAML, astro, combine, comments, depend, ensurePackages, expo, gitIgnores, ignores, imports, interopDefault, isObject, isPackageInScope, javascript, jsdoc, jsonc, node, perfectionist, pnpm, react, renamePluginInConfigs, renamePlugins, renameRules, resolveOptions, solid, sortPackageJson, sortTsconfig, stylistic, tailwindcssBetter, tanstack, toml, typescript, unicorn, vue, yaml, zayne };
|
|
2030
|
+
export { GLOB_ALL_SRC, GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CSS, GLOB_EXCLUDE, GLOB_GRAPHQL, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLES, GLOB_SVELTE, GLOB_SVG, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_XML, GLOB_YAML, allowedNextJsExportNames, allowedReactRouterExportNames, astro, combine, comments, defaultPluginRenameMap, depend, ensurePackages, expo, gitIgnores, ignores, imports, interopDefault, isObject, isPackageInScope, javascript, jsdoc, jsonc, node, overrideConfigs, perfectionist, pnpm, react, renamePluginInConfigs, renamePlugins, renameRules, resolveOptions, solid, sortPackageJson, sortTsconfig, stylistic, tailwindcssBetter, tanstack, toml, typescript, unicorn, vue, yaml, zayne };
|
|
1963
2031
|
//# sourceMappingURL=index.js.map
|