Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(component-name-in-template-casing):global option support regex#2928

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
FloEdelmann merged 4 commits intomasterfromglobal-regex-patterns
Sep 5, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions.changeset/rude-heads-serve.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-vue': minor
---

Changed `vue/component-name-in-template-casing` `globals` option to support regex patterns
12 changes: 9 additions & 3 deletionsdocs/rules/component-name-in-template-casing.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,7 +34,7 @@ This rule aims to warn the tag names other than the configured casing in Vue.js
- `registeredComponentsOnly` ... If `true`, only registered components (in PascalCase) are checked. If `false`, check all.
default `true`
- `ignores` (`string[]`) ... The element names to ignore. Sets the element name to allow. For example, custom elements or Vue components with special name. You can set the regexp by writing it like `"/^name/"`.
- `globals` (`string[]`) ... Globally registered component names to check. For example, `RouterView` and `RouterLink` are globally registered by `vue-router` and can't be detected as registered in a SFC file.
- `globals` (`string[]`) ... Globally registered component names to check. For example, `RouterView` and `RouterLink` are globally registered by `vue-router` and can't be detected as registered in a SFC file. You can set the regexp by writing it like `"/^c-/"` to match component names with patterns.

### `"PascalCase", { registeredComponentsOnly: true }` (default)

Expand DownExpand Up@@ -143,17 +143,23 @@ export default {

</eslint-code-block>

### `"PascalCase", { globals: ["RouterView"] }`
### `"PascalCase", { globals: ["RouterView", "/^c-/"] }`

<eslint-code-block fix :rules="{'vue/component-name-in-template-casing': ['error', 'PascalCase', {globals: ['RouterView']}]}">
<eslint-code-block fix :rules="{'vue/component-name-in-template-casing': ['error', 'PascalCase', {globals: ['RouterView', '/^c-/']}]}">

```vue
<template>
<!-- ✓ GOOD -->
<RouterView></RouterView>
<CButton />
<CCard />
<CInput />

<!-- ✗ BAD -->
<router-view></router-view>
<c-button />
<c-card />
<c-input />
</template>
```

Expand Down
24 changes: 18 additions & 6 deletionslib/rules/component-name-in-template-casing.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@

constutils=require('../utils')
constcasing=require('../utils/casing')
const{ toRegExpGroupMatcher}=require('../utils/regexp')
const{ toRegExpGroupMatcher, isRegExp}=require('../utils/regexp')

constallowedCaseOptions=['PascalCase','kebab-case']
constdefaultCase='PascalCase'
Expand DownExpand Up@@ -82,16 +82,26 @@ module.exports = {
?caseOption
:defaultCase
constisIgnored=toRegExpGroupMatcher(options.ignores)
/**@type {string[]} */
constglobals=(options.globals||[]).map(casing.pascalCase)

constglobalStrings=[]
constglobalPatterns=[]
for(constglobalofoptions.globals||[]){
if(isRegExp(global)){
globalPatterns.push(global)
}else{
globalStrings.push(global)
}
}

constisGlobalPattern=toRegExpGroupMatcher(globalPatterns)
constregisteredComponentsOnly=options.registeredComponentsOnly!==false
constsourceCode=context.getSourceCode()
consttokens=
sourceCode.parserServices.getTemplateBodyTokenStore&&
sourceCode.parserServices.getTemplateBodyTokenStore()

/**@type { Set<string>} */
constregisteredComponents=newSet(globals)
constregisteredComponents=newSet(globalStrings.map(casing.pascalCase))

if(utils.isScriptSetup(context)){
// For <script setup>
Expand DownExpand Up@@ -137,8 +147,10 @@ module.exports = {
returntrue
}

// We only verify the registered components.
returnregisteredComponents.has(casing.pascalCase(node.rawName))
return(
registeredComponents.has(casing.pascalCase(node.rawName))||
isGlobalPattern(node.rawName)
)
}

lethasInvalidEOF=false
Expand Down
81 changes: 81 additions & 0 deletionstests/lib/rules/component-name-in-template-casing.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -202,6 +202,21 @@ tester.run('component-name-in-template-casing', rule, {
options: ['kebab-case', { globals: ['RouterView', 'router-link'] }]
},

// globals with regex patterns
{
code: `
<template>
<div>
<c-button />
<c-card />
<c-input />
<other-component />
</div>
</template>
`,
options: ['kebab-case', { globals: ['/^c-/', 'other-component'] }]
},

// type-only imports
...(semver.gte(
require('@typescript-eslint/parser/package.json').version,
Expand DownExpand Up@@ -1223,6 +1238,72 @@ tester.run('component-name-in-template-casing', rule, {
}
]
},
{
code: `
<template>
<c-button />
<c-card />
<CInput />
</template>
`,
output: `
<template>
<CButton />
<CCard />
<CInput />
</template>
`,
options: ['PascalCase', { globals: ['/^c-/'] }],
errors: [
{
message: 'Component name "c-button" is not PascalCase.',
line: 3,
column: 11,
endLine: 3,
endColumn: 20
},
{
message: 'Component name "c-card" is not PascalCase.',
line: 4,
column: 11,
endLine: 4,
endColumn: 18
}
]
},
{
code: `
<template>
<CButton />
<CCard />
<c-input />
</template>
`,
output: `
<template>
<c-button />
<c-card />
<c-input />
</template>
`,
options: ['kebab-case', { globals: ['/^C[A-Z]/', '/^c-/'] }],
errors: [
{
message: 'Component name "CButton" is not kebab-case.',
line: 3,
column: 11,
endLine: 3,
endColumn: 19
},
{
message: 'Component name "CCard" is not kebab-case.',
line: 4,
column: 11,
endLine: 4,
endColumn: 17
}
]
},
// type-only imports
...(semver.gte(
require('@typescript-eslint/parser/package.json').version,
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp