Skip to content

Commit

Permalink
feat(config): support Nuxt 4 convention by default, resolve #487
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 29, 2024
1 parent b776e3a commit 42aeded
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-config/src/flat/configs/disables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function disables(options: NuxtESLintConfigOptions): Linter.Confi
...(dirs.components.map(componentsDir => join(componentsDir, '*', nestedGlobPattern)) || []),
// Prefixed components can have one-word names in file
...(dirs.componentsPrefixed.map(componentsDir => join(componentsDir, nestedGlobPattern)) || []),
])]
])].sort()

const configs: Linter.Config[] = []

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/flat/configs/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function nuxt(options: NuxtESLintConfigOptions): Linter.Config[]
...(dirs.layouts?.map(layoutsDir => join(layoutsDir, `**/*.${GLOB_EXTS}`)) || []),
...(dirs.pages?.map(pagesDir => join(pagesDir, `**/*.${GLOB_EXTS}`)) || []),
...(dirs.components?.map(componentsDir => join(componentsDir, `**/*.server.${GLOB_EXTS}`)) || []),
]
].sort()

const configs: Linter.Config[] = []

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/src/flat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function resolveOptions(
...config.dirs,
} as NuxtESLintConfigOptionsResolved['dirs']

dirs.root ||= ['.']
dirs.root ||= ['.', './app'] // Support both Nuxt 3 and 4 conventions by default
dirs.src ||= dirs.root
dirs.pages ||= dirs.src.map(src => `${src}/pages`)
dirs.layouts ||= dirs.src.map(src => `${src}/layouts`)
Expand Down
86 changes: 43 additions & 43 deletions packages/eslint-config/test/__snapshots__/flat-compose.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@ exports[`flat config composition > custom src dirs 1`] = `
[
{
"ignores": [
"node_modules",
"**/node_modules/**",
"*.iml",
"**/*.iml/**",
".idea",
"**/.idea/**",
"*.log",
"**/*.log/**",
".nuxt",
"**/.nuxt/**",
".output",
"**/.output/**",
"**/node_modules",
"**/*.iml",
"**/.idea",
"**/*.log",
"**/.nuxt",
"**/.output",
"**/.yarn/cache",
"**/.yarn/*state*",
"dist",
"**/dist/**",
".eslintcache",
"**/.eslintcache/**",
"**/dist",
"**/.eslintcache",
],
},
{
Expand Down Expand Up @@ -68,12 +60,12 @@ exports[`flat config composition > custom src dirs 1`] = `
},
{
"files": [
"src1/components/**/*.server.{js,ts,jsx,tsx,vue}",
"src1/layouts/**/*.{js,ts,jsx,tsx,vue}",
"src2/layouts/**/*.{js,ts,jsx,tsx,vue}",
"src1/pages/**/*.{js,ts,jsx,tsx,vue}",
"src2/pages/**/*.{js,ts,jsx,tsx,vue}",
"src1/components/**/*.server.{js,ts,jsx,tsx,vue}",
"src2/components/**/*.server.{js,ts,jsx,tsx,vue}",
"src2/layouts/**/*.{js,ts,jsx,tsx,vue}",
"src2/pages/**/*.{js,ts,jsx,tsx,vue}",
],
"name": "nuxt/vue/single-root",
},
Expand All @@ -83,15 +75,15 @@ exports[`flat config composition > custom src dirs 1`] = `
{
"files": [
"src1/app.{js,ts,jsx,tsx,vue}",
"src1/components/*/**/*.{js,ts,jsx,tsx,vue}",
"src1/error.{js,ts,jsx,tsx,vue}",
"src1/layouts/**/*.{js,ts,jsx,tsx,vue}",
"src1/pages/**/*.{js,ts,jsx,tsx,vue}",
"src2/app.{js,ts,jsx,tsx,vue}",
"src2/components/*/**/*.{js,ts,jsx,tsx,vue}",
"src2/error.{js,ts,jsx,tsx,vue}",
"src1/layouts/**/*.{js,ts,jsx,tsx,vue}",
"src2/layouts/**/*.{js,ts,jsx,tsx,vue}",
"src1/pages/**/*.{js,ts,jsx,tsx,vue}",
"src2/pages/**/*.{js,ts,jsx,tsx,vue}",
"src1/components/*/**/*.{js,ts,jsx,tsx,vue}",
"src2/components/*/**/*.{js,ts,jsx,tsx,vue}",
],
"name": "nuxt/disables/routes",
},
Expand All @@ -102,24 +94,16 @@ exports[`flat config composition > empty 1`] = `
[
{
"ignores": [
"node_modules",
"**/node_modules/**",
"*.iml",
"**/*.iml/**",
".idea",
"**/.idea/**",
"*.log",
"**/*.log/**",
".nuxt",
"**/.nuxt/**",
".output",
"**/.output/**",
"**/node_modules",
"**/*.iml",
"**/.idea",
"**/*.log",
"**/.nuxt",
"**/.output",
"**/.yarn/cache",
"**/.yarn/*state*",
"dist",
"**/dist/**",
".eslintcache",
"**/.eslintcache/**",
"**/dist",
"**/.eslintcache",
],
},
{
Expand Down Expand Up @@ -166,9 +150,12 @@ exports[`flat config composition > empty 1`] = `
},
{
"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}",
"components/**/*.server.{js,ts,jsx,tsx,vue}",
],
"name": "nuxt/vue/single-root",
},
Expand All @@ -178,10 +165,15 @@ exports[`flat config composition > empty 1`] = `
{
"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}",
"components/*/**/*.{js,ts,jsx,tsx,vue}",
],
"name": "nuxt/disables/routes",
},
Expand All @@ -195,9 +187,12 @@ exports[`flat config composition > non-standalone 1`] = `
},
{
"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}",
"components/**/*.server.{js,ts,jsx,tsx,vue}",
],
"name": "nuxt/vue/single-root",
},
Expand All @@ -207,10 +202,15 @@ exports[`flat config composition > non-standalone 1`] = `
{
"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}",
"components/*/**/*.{js,ts,jsx,tsx,vue}",
],
"name": "nuxt/disables/routes",
},
Expand Down

0 comments on commit 42aeded

Please sign in to comment.