diff --git a/packages/eslint-config/src/flat/configs/nuxt.ts b/packages/eslint-config/src/flat/configs/nuxt.ts index 30346f86..afce073b 100644 --- a/packages/eslint-config/src/flat/configs/nuxt.ts +++ b/packages/eslint-config/src/flat/configs/nuxt.ts @@ -15,12 +15,14 @@ export default function nuxt(options: NuxtESLintConfigOptions): Linter.Config[] ...(dirs.components?.map(componentsDir => join(componentsDir, `**/*.server.${GLOB_EXTS}`)) || []), ].sort() - const stylistic = options.features?.stylistic === true ? {} : options.features?.stylistic || undefined + const { + sortConfigKeys = !!(options.features?.stylistic), + } = options.features?.nuxt || {} const configs: Linter.Config[] = [] configs.push({ - name: 'nuxt/configs', + name: 'nuxt/setup', plugins: { nuxt: nuxtPlugin, }, @@ -48,7 +50,7 @@ export default function nuxt(options: NuxtESLintConfigOptions): Linter.Config[] }, }) - if (stylistic && stylistic.nuxtConfigSort !== false) { + if (sortConfigKeys) { configs.push({ name: 'nuxt/sort-config', files: [ diff --git a/packages/eslint-config/src/flat/types.ts b/packages/eslint-config/src/flat/types.ts index 8f20797c..93e8945e 100644 --- a/packages/eslint-config/src/flat/types.ts +++ b/packages/eslint-config/src/flat/types.ts @@ -23,6 +23,15 @@ export interface ToolingOptions { jsdoc?: boolean } +export interface NuxtSpecificOptions { + /** + * Sort keys in nuxt.config to maintain a consistent order + * + * @default true when `features.stylistic` is enabled + */ + sortConfigKeys?: boolean +} + export interface NuxtESLintFeaturesOptions { /** * Setup basic JavaScript, TypeScript and Vue plugins and rules. @@ -47,7 +56,12 @@ export interface NuxtESLintFeaturesOptions { * @see https://eslint.style/guide/config-presets * @default false */ - stylistic?: boolean | StylisticOptions + stylistic?: boolean | StylisticCustomizeOptions + + /** + * Options for Nuxt specific rules + */ + nuxt?: NuxtSpecificOptions /** * Enable TypeScript support. Can also be an object to config the options. @@ -126,17 +140,6 @@ export interface NuxtESLintConfigOptions { } } -export interface NuxtSpecificStylisticOptions { - /** - * Sort keys in nuxt.config to maintain a consistent order - * - * @default true - */ - nuxtConfigSort?: boolean -} - -export interface StylisticOptions extends StylisticCustomizeOptions, NuxtSpecificStylisticOptions {} - type NotNill = T extends null | undefined ? never : T export interface NuxtESLintConfigOptionsResolved { diff --git a/packages/eslint-config/test/__snapshots__/flat-compose.test.ts.snap b/packages/eslint-config/test/__snapshots__/flat-compose.test.ts.snap index d15da71b..93c80b66 100644 --- a/packages/eslint-config/test/__snapshots__/flat-compose.test.ts.snap +++ b/packages/eslint-config/test/__snapshots__/flat-compose.test.ts.snap @@ -57,7 +57,7 @@ exports[`flat config composition > custom src dirs 1`] = ` "name": "nuxt/import/rules", }, { - "name": "nuxt/configs", + "name": "nuxt/setup", }, { "files": [ @@ -148,7 +148,7 @@ exports[`flat config composition > empty 1`] = ` "name": "nuxt/import/rules", }, { - "name": "nuxt/configs", + "name": "nuxt/setup", }, { "files": [ @@ -185,7 +185,7 @@ exports[`flat config composition > empty 1`] = ` exports[`flat config composition > non-standalone 1`] = ` [ { - "name": "nuxt/configs", + "name": "nuxt/setup", }, { "files": [ @@ -218,3 +218,103 @@ exports[`flat config composition > non-standalone 1`] = ` }, ] `; + +exports[`flat config composition > with stylistic 1`] = ` +[ + { + "ignores": [ + "**/node_modules", + "**/*.iml", + "**/.idea", + "**/*.log", + "**/.nuxt", + "**/.output", + "**/.yarn/cache", + "**/.yarn/*state*", + "**/dist", + "**/.eslintcache", + ], + "name": "gitignore", + }, + { + "ignores": [ + "**/dist", + "**/node_modules", + "**/.nuxt", + "**/.output", + "**/.vercel", + "**/.netlify", + "**/public", + ], + }, + { + "name": "nuxt/javascript", + }, + { + "name": "nuxt/typescript/setup", + }, + { + "files": [ + "**/*.ts", + "**/*.tsx", + "**/*.mts", + "**/*.cts", + "**/*.vue", + ], + "name": "nuxt/typescript/rules", + }, + { + "name": "nuxt/vue/setup", + }, + { + "files": [ + "**/*.vue", + ], + "name": "nuxt/vue/rules", + }, + { + "name": "nuxt/import/rules", + }, + { + "name": "nuxt/setup", + }, + { + "files": [ + "app/components/**/*.server.{js,ts,jsx,tsx,vue}", + "app/layouts/**/*.{js,ts,jsx,tsx,vue}", + "app/pages/**/*.{js,ts,jsx,tsx,vue}", + "components/**/*.server.{js,ts,jsx,tsx,vue}", + "layouts/**/*.{js,ts,jsx,tsx,vue}", + "pages/**/*.{js,ts,jsx,tsx,vue}", + ], + "name": "nuxt/vue/single-root", + }, + { + "name": "nuxt/rules", + }, + { + "files": [ + "**/nuxt.config.?([cm])[jt]s?(x)", + ], + "name": "nuxt/sort-config", + }, + { + "name": "nuxt/stylistic", + }, + { + "files": [ + "app.{js,ts,jsx,tsx,vue}", + "app/app.{js,ts,jsx,tsx,vue}", + "app/components/*/**/*.{js,ts,jsx,tsx,vue}", + "app/error.{js,ts,jsx,tsx,vue}", + "app/layouts/**/*.{js,ts,jsx,tsx,vue}", + "app/pages/**/*.{js,ts,jsx,tsx,vue}", + "components/*/**/*.{js,ts,jsx,tsx,vue}", + "error.{js,ts,jsx,tsx,vue}", + "layouts/**/*.{js,ts,jsx,tsx,vue}", + "pages/**/*.{js,ts,jsx,tsx,vue}", + ], + "name": "nuxt/disables/routes", + }, +] +`;