Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module)!: generate withNuxt function for easer composition #344

Merged
merged 2 commits into from
Mar 20, 2024

Conversation

antfu
Copy link
Member

@antfu antfu commented Mar 20, 2024

This PR makes .nuxt/eslint.config.mjs export a function withNuxt instead of the plan config array. This provides auto-type declaration for users and makes the compositions with other presets easier. It also makes the config factory async in case we later need to dynamic load some modules on conditions.

Copy link

cloudflare-pages bot commented Mar 20, 2024

Deploying nuxt-eslint with  Cloudflare Pages  Cloudflare Pages

Latest commit: 35cd711
Status: ✅  Deploy successful!
Preview URL: https://a55300db.nuxt-eslint.pages.dev
Branch Preview URL: https://feat-with-nuxt.nuxt-eslint.pages.dev

View logs

@DamianGlowala
Copy link
Member

DamianGlowala commented Mar 20, 2024

What do you think about defineEslintConfig((nuxt) => [ ... ]) for most flexibility in terms of ordering (also, got used to the defineEslintConfig naming and thinking whether withNuxt would be a better one)?

@antfu
Copy link
Member Author

antfu commented Mar 20, 2024

I did make this

/**
* Provide type definitions for constructing ESLint flat config items.
*
* This function takes flat config item, or an array of them as rest arguments.
* It also automatically resolves the promise if the config item is a promise.
*/
export async function defineFlatConfigs(...configs: Awaitable<FlatConfig | FlatConfig[]>[]): Promise<FlatConfig[]> {
const resolved = await Promise.all(configs)
return resolved.flat()
}

and mentioned this
To make it easier, you can also use our helper `defineFlatConfigs`, which will also resolve and flatten the configs for you:
```js [eslint.config.mjs]
import { defineFlatConfigs, createConfigForNuxt } from '@nuxt/eslint-config/flat'
export default defineFlatConfigs(
createConfigForNuxt({
// options here
}),
// other configs
)
```

But I think withNuxt would be easier for most of the users and most of time the order of configure don't usually matter as the user configure comes later with higher priority to override stuff.

@antfu antfu merged commit 9c9f8f3 into main Mar 20, 2024
2 checks passed
@antfu antfu deleted the feat/with-nuxt branch March 20, 2024 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants