/**
* @author Yosuke Ota
*/
'use strict'
const rule = require('../../../lib/rules/component-name-in-template-casing')
const semver = require('semver')
const RuleTester = require('../../eslint-compat').RuleTester
const tester = new RuleTester({
languageOptions: {
parser: require('vue-eslint-parser'),
ecmaVersion: 2018,
sourceType: 'module'
}
})
tester.run('component-name-in-template-casing', rule, {
valid: [
// default
{
filename: 'test.vue',
code: `
`
},
// element types test
{
code: '',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: '
',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: '
',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: 'bar
',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: 'Title
',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: 'Title
',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['PascalCase', { registeredComponentsOnly: false }]
},
// kebab-case
{
code: '',
options: ['kebab-case', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['kebab-case', { registeredComponentsOnly: false }]
},
{
code: '
',
options: ['kebab-case', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['kebab-case', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['kebab-case', { registeredComponentsOnly: false }]
},
{
code: '',
options: ['kebab-case', { registeredComponentsOnly: false }]
},
// ignores
{
code: '',
options: [
'PascalCase',
{ ignores: ['custom-element'], registeredComponentsOnly: false }
]
},
{
code: '',
options: [
'PascalCase',
{ ignores: ['custom-element'], registeredComponentsOnly: false }
]
},
// regexp ignores
{
filename: 'test.vue',
code: `
`,
options: [
'PascalCase',
{ registeredComponentsOnly: false, ignores: ['/^global/'] }
]
},
// Invalid EOF
{
code: '
import type Foo from './Foo.vue'
import type { HelloWorld1 } from './components/HelloWorld'
import { type HelloWorld2 } from './components/HelloWorld2'
import type { HelloWorld as HelloWorld3 } from './components/HelloWorld3'
import { type HelloWorld as HelloWorld4 } from './components/HelloWorld4';
import { type default as HelloWorld5 } from './components/HelloWorld5';
import { type Component } from 'vue';
`,
options: ['PascalCase', { registeredComponentsOnly: true }],
languageOptions: {
parserOptions: {
parser: require.resolve('@typescript-eslint/parser')
}
}
}
]
: [])
],
invalid: [
{
filename: 'test.vue',
code: `
`,
output: `
`,
errors: [
{
message: 'Component name "cool-component" is not PascalCase.',
line: 4,
column: 11,
endLine: 4,
endColumn: 26
},
{
message: 'Component name "coolComponent" is not PascalCase.',
line: 5,
column: 11,
endLine: 5,
endColumn: 25
},
{
message: 'Component name "Cool-component" is not PascalCase.',
line: 6,
column: 11,
endLine: 6,
endColumn: 26
}
]
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['kebab-case'],
errors: [
{
message: 'Component name "CoolComponent" is not kebab-case.',
line: 4
},
{
message: 'Component name "coolComponent" is not kebab-case.',
line: 5
},
{
message: 'Component name "Cool-component" is not kebab-case.',
line: 6
}
]
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
content
`,
output: `
content
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['kebab-case'],
errors: ['Component name "TheComponent" is not kebab-case.']
},
{
code: `
`,
output: `
`,
options: ['kebab-case', { registeredComponentsOnly: false }],
errors: ['Component name "TheComponent" is not kebab-case.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "theComponent" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['kebab-case'],
errors: ['Component name "theComponent" is not kebab-case.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "The-component" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['kebab-case'],
errors: ['Component name "The-component" is not kebab-case.']
},
{
code: `
`,
output: `
`,
options: ['kebab-case', { registeredComponentsOnly: false }],
errors: ['Component name "Thecomponent" is not kebab-case.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
{
filename: 'test.vue',
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
// ignores
{
code: `
`,
output: `
`,
options: [
'PascalCase',
{
ignores: ['custom-element1', 'custom-element2'],
registeredComponentsOnly: false
}
],
errors: [
'Component name "the-component" is not PascalCase.',
'Component name "the-component" is not PascalCase.'
]
},
{
code: `
`,
output: `
`,
options: [
'PascalCase',
{
ignores: ['/^custom-element/'],
registeredComponentsOnly: false
}
],
errors: [
'Component name "the-component" is not PascalCase.',
'Component name "the-component" is not PascalCase.'
]
},
{
code: `
`,
output: `
`,
options: [
'kebab-case',
{
registeredComponentsOnly: false
}
],
errors: [
'Component name "foo--bar" is not kebab-case.',
'Component name "Foo--Bar" is not kebab-case.',
'Component name "FooBar" is not kebab-case.',
'Component name "FooBar_Baz-qux" is not kebab-case.'
]
},
{
// built-in components (behave the same way as other components)
code: `
`,
output: `
`,
options: ['PascalCase', { registeredComponentsOnly: false }],
errors: [
'Component name "suspense" is not PascalCase.',
'Component name "teleport" is not PascalCase.',
'Component name "client-only" is not PascalCase.',
'Component name "keep-alive" is not PascalCase.'
]
},
{
code: `
`,
output: `
`,
options: ['PascalCase'],
errors: ['Component name "the-component" is not PascalCase.']
},
{
code: `
`,
output: `
`,
options: ['kebab-case'],
errors: ['Component name "TheComponent" is not kebab-case.']
},
{
code: `
`,
output: `
`,
options: ['PascalCase', { globals: ['RouterView'] }],
errors: [
{
message: 'Component name "router-view" is not PascalCase.',
line: 3,
column: 11
}
]
},
{
code: `
`,
output: `
`,
options: ['kebab-case', { globals: ['RouterView'] }],
errors: [
{
message: 'Component name "RouterView" is not kebab-case.',
line: 3,
column: 11
}
]
},
{
code: `
`,
output: `
`,
options: ['kebab-case', { globals: ['router-view'] }],
errors: [
{
message: 'Component name "RouterView" is not kebab-case.',
line: 3,
column: 11
}
]
},
// type-only imports
...(semver.gte(
require('@typescript-eslint/parser/package.json').version,
'5.0.0'
)
? [
{
code: `
`,
options: ['PascalCase', { registeredComponentsOnly: false }],
languageOptions: {
parserOptions: {
parser: require.resolve('@typescript-eslint/parser')
}
},
output: `
`,
errors: [
{
message: 'Component name "foo" is not PascalCase.',
line: 13,
column: 17
},
{
message: 'Component name "hello-world1" is not PascalCase.',
line: 14,
column: 17
},
{
message: 'Component name "hello-world2" is not PascalCase.',
line: 15,
column: 17
},
{
message: 'Component name "hello-world3" is not PascalCase.',
line: 16,
column: 17
},
{
message: 'Component name "hello-world4" is not PascalCase.',
line: 17,
column: 17
},
{
message: 'Component name "hello-world5" is not PascalCase.',
line: 18,
column: 17
}
]
}
]
: [])
]
})