Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion lib/rules/no-undef-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ module.exports = {
properties: {
ignorePatterns: {
type: 'array'
},
strict: {
type: 'boolean'
}
},
additionalProperties: false
Expand Down Expand Up @@ -155,10 +158,15 @@ module.exports = {
return false
}
const pascalCaseName = casing.pascalCase(rawName)

// Check ignored patterns
if (
ignorePatterns.some((pattern) => {
const regExp = new RegExp(pattern)
const regExp = new RegExp(
options.strict === true || options.strict === undefined
? `^${pattern}$`
: pattern
)
return (
regExp.test(rawName) ||
regExp.test(kebabCaseName) ||
Expand Down
36 changes: 36 additions & 0 deletions tests/lib/rules/no-undef-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ tester.run('no-undef-components', rule, {
}
]
},

// circular references
{
filename: 'test.vue',
Expand Down Expand Up @@ -685,6 +686,7 @@ tester.run('no-undef-components', rule, {
}
}
],

invalid: [
// <script setup>
{
Expand Down Expand Up @@ -843,6 +845,40 @@ tester.run('no-undef-components', rule, {
]
},

// Strict ignore pattern
{
filename: 'test.vue',
code: `
<template>
<FooBar />
</template>
`,
options: [{ ignorePatterns: ['Foo'], strict: true }],
errors: [
{
message: "The '<FooBar>' component has been used, but not defined.",
line: 3
}
]
},

// Default to strict
{
filename: 'test.vue',
code: `
<template>
<FooBar />
</template>
`,
options: [{ ignorePatterns: ['Foo'] }],
errors: [
{
message: "The '<FooBar>' component has been used, but not defined.",
line: 3
}
]
},

// options API
{
filename: 'test.vue',
Expand Down