Skip to content

Commit cd0157c

Browse files
committedMay 9, 2024
fix: allow single name file under prefixed components folder, fix #419
1 parent 8a065c7 commit cd0157c

File tree

8 files changed

+47
-11
lines changed

8 files changed

+47
-11
lines changed
 

‎eslint.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export default createConfigForNuxt({
1111
'playground',
1212
'docs',
1313
],
14+
componentsPrefixed: [
15+
'playground/components-prefixed',
16+
],
1417
},
1518
})
1619
.append(

‎packages/eslint-config/src/flat/configs/disables.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function disables(options: NuxtESLintConfigOptions): Linter.FlatC
99
const dirs = resolved.dirs
1010
const nestedGlobPattern = `**/*.${GLOB_EXTS}`
1111

12-
const fileRoutes = [
12+
const fileRoutes = [...new Set([
1313
// These files must have one-word names as they have a special meaning in Nuxt.
1414
...dirs.src.flatMap(layersDir => [
1515
join(layersDir, `app.${GLOB_EXTS}`),
@@ -22,7 +22,9 @@ export default function disables(options: NuxtESLintConfigOptions): Linter.FlatC
2222

2323
// These files should have multiple words in their names as they are within subdirectories.
2424
...(dirs.components.map(componentsDir => join(componentsDir, '*', nestedGlobPattern)) || []),
25-
]
25+
// Prefixed components can have one-word names in file
26+
...(dirs.componentsPrefixed.map(componentsDir => join(componentsDir, nestedGlobPattern)) || []),
27+
])]
2628

2729
const configs: Linter.FlatConfig[] = []
2830

‎packages/eslint-config/src/flat/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ export interface NuxtESLintConfigOptions {
7070
*/
7171
components?: string[]
7272

73+
/**
74+
* Directory for components with prefix
75+
* Ignore `vue/multi-word-component-names`
76+
*/
77+
componentsPrefixed?: string[]
78+
7379
/**
7480
* Directory for composobles
7581
*/

‎packages/eslint-config/src/flat/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function resolveOptions(
2525
dirs.modules ||= dirs.src.map(src => `${src}/modules`)
2626
dirs.middleware ||= dirs.src.map(src => `${src}/middleware`)
2727
dirs.servers ||= dirs.src.map(src => `${src}/servers`)
28+
dirs.componentsPrefixed ||= []
2829

2930
const resolved: NuxtESLintConfigOptionsResolved = {
3031
features: {

‎packages/module/src/modules/config/utils.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export function getDirs(nuxt: Nuxt): NuxtESLintConfigOptions['dirs'] {
77
pages: [],
88
composables: [],
99
components: [],
10+
componentsPrefixed: [],
1011
layouts: [],
1112
plugins: [],
1213
middleware: [],
@@ -17,7 +18,7 @@ export function getDirs(nuxt: Nuxt): NuxtESLintConfigOptions['dirs'] {
1718
}
1819

1920
for (const layer of nuxt.options._layers) {
20-
const r = (t: string) => relative(nuxt.options.rootDir, resolve(layer.config.srcDir, t))
21+
const r = (t: string) => relative(nuxt.options.rootDir, resolve(layer.config.srcDir, t.replace(/^~[/\\]/, '')))
2122

2223
dirs.src.push(r(''))
2324
dirs.pages.push(r(nuxt.options.dir.pages || 'pages'))
@@ -33,14 +34,17 @@ export function getDirs(nuxt: Nuxt): NuxtESLintConfigOptions['dirs'] {
3334
dirs.composables.push(r(dir))
3435
}
3536

36-
if (layer.config.components) {
37-
const options = layer.config.components || {}
38-
if (options !== true && 'dirs' in options) {
39-
for (const dir of options.dirs || []) {
40-
if (typeof dir === 'string')
41-
dirs.components.push(r(dir))
42-
else if (dir && 'path' in dir && typeof dir.path === 'string')
43-
dirs.components.push(r(dir.path))
37+
if (layer.config.components && layer.config.components !== true) {
38+
const options = Array.isArray(layer.config.components)
39+
? { dirs: layer.config.components }
40+
: layer.config.components
41+
for (const dir of options.dirs || []) {
42+
if (typeof dir === 'string')
43+
dirs.components.push(r(dir))
44+
else if (dir && 'path' in dir && typeof dir.path === 'string') {
45+
dirs.components.push(r(dir.path))
46+
if (dir.prefix)
47+
dirs.componentsPrefixed.push(r(dir.path))
4448
}
4549
}
4650
}

‎playground/components-prefixed/A.vue

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script setup lang="ts">
2+
</script>
3+
4+
<template>
5+
<div>
6+
<slot />
7+
</div>
8+
</template>

‎playground/components/TheB.vue

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script setup lang="ts">
2+
</script>
3+
4+
<template>
5+
<div>
6+
<slot />
7+
</div>
8+
</template>

‎playground/nuxt.config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ export default defineNuxtConfig({
55
devtools: {
66
enabled: true,
77
},
8+
components: [
9+
'~/components',
10+
{ path: '~/components-prefixed', prefix: 'Prefix' },
11+
],
812
eslint: {
913
config: {
1014
stylistic: true,

0 commit comments

Comments
 (0)
Please sign in to comment.