Skip to content

Commit c6163fa

Browse files
committed
fix(eslint-config): update dependencies and improve ESLint configuration
- Updated various dependencies in the ESLint configuration, including @eslint/js, @typescript-eslint/eslint-plugin, and @visulima/package to their latest versions. - Enhanced the ESLint configuration by adding new utility functions for resolving sub-options and retrieving overrides, improving maintainability and clarity. - This update ensures compatibility with the latest ESLint features and improves the overall configuration structure.
1 parent 2e1cf7f commit c6163fa

File tree

5 files changed

+2600
-228
lines changed

5 files changed

+2600
-228
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@
136136
"pnpm": {
137137
"onlyBuiltDependencies": [
138138
"esbuild",
139-
"nx"
139+
"nx",
140+
"unrs-resolver"
140141
],
141142
"overrides": {
142143
"@babel/helpers@<7.26.10": ">=7.26.10",

packages/eslint-config/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ Create `eslint.config.mjs` in your project root:
7777

7878
```js
7979
// eslint.config.mjs
80-
80+
import type { PromiseFlatConfigComposer } from "@anolilab/eslint-config";
8181
import { createConfig } from "@anolilab/eslint-config";
8282

83-
export default createConfig();
83+
export default createConfig() as PromiseFlatConfigComposer;
8484
```
8585

8686
<details>
@@ -92,6 +92,7 @@ If you still use some configs from the legacy eslintrc format, you can use the [
9292

9393
```js
9494
// eslint.config.mjs
95+
import type { PromiseFlatConfigComposer } from "@anolilab/eslint-config";
9596
import { createConfig } from "@anolilab/eslint-config";
9697
import { FlatCompat } from "@eslint/eslintrc";
9798

@@ -111,7 +112,7 @@ export default createConfig(
111112
}),
112113

113114
// Other flat configs...
114-
);
115+
) as PromiseFlatConfigComposer;
115116
```
116117

117118
> Note that `.eslintignore` no longer works in Flat config.
@@ -122,6 +123,7 @@ Or you can configure each integration individually, for example:
122123

123124
```js
124125
// eslint.config.js
126+
import type { PromiseFlatConfigComposer } from "@anolilab/eslint-config";
125127
import { createConfig } from "@anolilab/eslint-config";
126128

127129
export default createConfig({
@@ -147,7 +149,7 @@ export default createConfig({
147149
vue: true,
148150

149151
yaml: false,
150-
});
152+
}) as PromiseFlatConfigComposer;
151153
```
152154

153155
### Add script for package.json
@@ -167,6 +169,7 @@ The factory function also accepts any number of arbitrary custom config override
167169

168170
```js
169171
// eslint.config.js
172+
import type { PromiseFlatConfigComposer } from "@anolilab/eslint-config";
170173
import { createConfig } from "@anolilab/eslint-config";
171174

172175
export default createConfig(
@@ -183,13 +186,14 @@ export default createConfig(
183186
{
184187
rules: {},
185188
},
186-
);
189+
) as PromiseFlatConfigComposer;
187190
```
188191

189192
We also provided the `overrides` options in each integration to make it easier:
190193

191194
```js
192195
// eslint.config.js
196+
import type { PromiseFlatConfigComposer } from "@anolilab/eslint-config";
193197
import { createConfig } from "@anolilab/eslint-config";
194198

195199
export default createConfig({
@@ -203,7 +207,7 @@ export default createConfig({
203207
// ...
204208
},
205209
},
206-
});
210+
}) as PromiseFlatConfigComposer;
207211
```
208212

209213
## IDE Support (auto fix on save)
@@ -403,13 +407,14 @@ You can optionally enable the [type aware](https://typescript-eslint.io/linting/
403407

404408
```js
405409
// eslint.config.js
406-
import antfu from "@antfu/eslint-config";
410+
import type { PromiseFlatConfigComposer } from "@anolilab/eslint-config";
411+
import { createConfig } from "@anolilab/eslint-config";
407412

408-
export default antfu({
413+
export default createConfig({
409414
typescript: {
410415
tsconfigPath: "tsconfig.json",
411416
},
412-
});
417+
}) as PromiseFlatConfigComposer;
413418
```
414419

415420
### Utilities

packages/eslint-config/package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,29 +122,29 @@
122122
"dependencies": {
123123
"@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
124124
"@eslint/compat": "^1.2.9",
125-
"@eslint/js": "^9.27.0",
125+
"@eslint/js": "^9.28.0",
126126
"@eslint/markdown": "^6.4.0",
127127
"@html-eslint/eslint-plugin": "^0.41.0",
128128
"@html-eslint/parser": "^0.41.0",
129129
"@stylistic/eslint-plugin": "^4.4.0",
130130
"@stylistic/eslint-plugin-ts": "^4.4.0",
131-
"@typescript-eslint/eslint-plugin": "^8.32.1",
132-
"@typescript-eslint/parser": "^8.32.1",
133-
"@visulima/package": "^3.5.4",
134-
"@visulima/tsconfig": "^1.1.16",
131+
"@typescript-eslint/eslint-plugin": "^8.33.0",
132+
"@typescript-eslint/parser": "^8.33.0",
133+
"@visulima/package": "^3.5.6",
134+
"@visulima/tsconfig": "^1.1.17",
135135
"@vitest/eslint-plugin": "^1.2.1",
136136
"confusing-browser-globals": "^1.0.11",
137137
"eslint-config-flat-gitignore": "^2.1.0",
138138
"eslint-flat-config-utils": "^2.1.0",
139139
"eslint-import-resolver-node": "^0.3.9",
140-
"eslint-import-resolver-typescript": "^4.4.1",
140+
"eslint-import-resolver-typescript": "^4.4.2",
141141
"eslint-merge-processors": "^2.0.0",
142142
"eslint-plugin-antfu": "^3.1.1",
143143
"eslint-plugin-compat": "^6.0.2",
144144
"eslint-plugin-es-x": "^8.6.2",
145145
"eslint-plugin-html": "^8.1.3",
146-
"eslint-plugin-import-x": "^4.13.3",
147-
"eslint-plugin-jsdoc": "^50.6.17",
146+
"eslint-plugin-import-x": "^4.15.0",
147+
"eslint-plugin-jsdoc": "^50.7.1",
148148
"eslint-plugin-jsonc": "^2.20.1",
149149
"eslint-plugin-n": "^17.18.0",
150150
"eslint-plugin-no-for-of-array": "^0.1.0",
@@ -166,7 +166,7 @@
166166
"parse-gitignore": "^2.0.0",
167167
"semver": "^7.7.2",
168168
"toml-eslint-parser": "^0.10.0",
169-
"typescript-eslint": "^8.32.1",
169+
"typescript-eslint": "^8.33.0",
170170
"yaml-eslint-parser": "^1.3.0"
171171
},
172172
"devDependencies": {
@@ -185,11 +185,11 @@
185185
"@types/eslint-plugin-jsx-a11y": "^6.10.0",
186186
"@types/eslint-plugin-tailwindcss": "^3.17.0",
187187
"@types/semver": "^7.7.0",
188-
"@unocss/eslint-plugin": "^66.1.2",
189-
"@visulima/packem": "^1.19.1",
188+
"@unocss/eslint-plugin": "^66.1.3",
189+
"@visulima/packem": "^1.19.4",
190190
"astro-eslint-parser": "^1.2.2",
191191
"esbuild": "^0.25.5",
192-
"eslint": "^9.27.0",
192+
"eslint": "^9.28.0",
193193
"eslint-plugin-astro": "^1.3.1",
194194
"eslint-plugin-format": "^1.0.1",
195195
"eslint-plugin-jsx-a11y": "^6.10.2",
@@ -198,10 +198,10 @@
198198
"eslint-plugin-react-hooks": "^5.2.0",
199199
"eslint-plugin-react-perf": "^3.3.3",
200200
"eslint-plugin-react-refresh": "^0.4.20",
201-
"eslint-plugin-react-you-might-not-need-an-effect": "^0.0.35",
202-
"eslint-plugin-storybook": "^0.12.0",
201+
"eslint-plugin-react-you-might-not-need-an-effect": "^0.0.38",
202+
"eslint-plugin-storybook": "^9.0.4",
203203
"eslint-plugin-tailwindcss": "^3.18.0",
204-
"eslint-plugin-testing-library": "^7.2.2",
204+
"eslint-plugin-testing-library": "^7.3.0",
205205
"eslint-plugin-tsdoc": "^0.4.0",
206206
"eslint-plugin-validate-jsx-nesting": "^0.1.1",
207207
"eslint-plugin-vitest": "^0.5.4",

packages/eslint-config/src/index.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,25 @@ export type {
9494
export { getFilesGlobs } from "./utils/create-config";
9595
export type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
9696

97+
/**
98+
* Resolves sub-options from the main configuration object.
99+
* If the option for the given key is a boolean, it returns an empty object;
100+
* otherwise, it returns the sub-options object or an empty object if undefined.
101+
* @param {OptionsConfig} options The main configuration object.
102+
* @param {K} key The key of the sub-options to resolve.
103+
* @returns {ResolvedOptions<OptionsConfig[K]>} The resolved sub-options.
104+
* @template K
105+
*/
97106
export const resolveSubOptions = <K extends keyof OptionsConfig>(options: OptionsConfig, key: K): ResolvedOptions<OptionsConfig[K]> => (typeof options[key] === "boolean" ? {} : options[key] || {}) as ResolvedOptions<OptionsConfig[K]>;
107+
108+
/**
109+
* Retrieves override rules for a specific configuration key.
110+
* It merges global overrides with sub-option overrides.
111+
* @param {OptionsConfig} options The main configuration object.
112+
* @param {K} key The key of the configuration to get overrides for.
113+
* @returns {Partial<Linter.RulesRecord & RuleOptions>} The merged override rules.
114+
* @template K
115+
*/
98116
export const getOverrides = <K extends keyof OptionsConfig>(options: OptionsConfig, key: K): Partial<Linter.RulesRecord & RuleOptions> => {
99117
const sub = resolveSubOptions(options, key);
100118

@@ -105,6 +123,13 @@ export const getOverrides = <K extends keyof OptionsConfig>(options: OptionsConf
105123
};
106124
};
107125

126+
/**
127+
* Retrieves file globs for a specific configuration key from sub-options.
128+
* @param {OptionsConfig} options The main configuration object.
129+
* @param {K} key The key of the configuration to get file globs for.
130+
* @returns {string[] | undefined} An array of file globs, or undefined if not specified.
131+
* @template K
132+
*/
108133
export const getFiles = <K extends keyof OptionsConfig>(options: OptionsConfig, key: K): string[] | undefined => {
109134
const sub = resolveSubOptions(options, key);
110135

@@ -119,21 +144,26 @@ export const getFiles = <K extends keyof OptionsConfig>(options: OptionsConfig,
119144
return undefined;
120145
};
121146

147+
/**
148+
* Type alias for a Promise that resolves to a FlatConfigComposer instance.
149+
*/
150+
export type PromiseFlatConfigComposer = Promise<FlatConfigComposer<TypedFlatConfigItem, ConfigNames>>;
151+
122152
/**
123153
* Construct an array of ESLint flat config items.
124154
* @param {OptionsConfig & TypedFlatConfigItem} options
125155
* The options for generating the ESLint configurations.
126156
* @param {Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[]>[]} userConfigs
127157
* The user configurations to be merged with the generated configurations.
128-
* @returns {Promise<TypedFlatConfigItem[]>}
129-
* The merged ESLint configurations.
158+
* @returns {PromiseFlatConfigComposer}
159+
* A promise that resolves to the merged ESLint configurations composer.
130160
*/
131161
export const createConfig = async (
132162
options: Omit<TypedFlatConfigItem, "files"> & OptionsConfig = {},
133163
// eslint-disable-next-line @typescript-eslint/no-explicit-any
134164
...userConfigs: Awaitable<FlatConfigComposer<any, any> | Linter.Config[] | TypedFlatConfigItem | TypedFlatConfigItem[]>[]
135165
// eslint-disable-next-line sonarjs/cognitive-complexity
136-
): Promise<FlatConfigComposer<TypedFlatConfigItem, ConfigNames>> => {
166+
): PromiseFlatConfigComposer => {
137167
if ("files" in options) {
138168
throw new Error(
139169
"[@anolilab/eslint-config] The first argument should not contain the \"files\" property as the options are supposed to be global. Place it in the second or later config instead.",
@@ -509,7 +539,7 @@ export const createConfig = async (
509539
} = options;
510540

511541
if (isCwdInScope) {
512-
const packages = [];
542+
let packages = [];
513543

514544
if (enableZod) {
515545
packages.push("eslint-plugin-zod");
@@ -595,6 +625,8 @@ export const createConfig = async (
595625
}
596626
}
597627

628+
packages = packages.filter(Boolean) as string[];
629+
598630
if (packages.length > 0) {
599631
await ensurePackages(packageJson, packages, "devDependencies", {
600632
confirm: {

0 commit comments

Comments
 (0)