Skip to content

Commit

Permalink
Chore: fix errors in tests using ESLint v9.0.0-alpha.2 (#2382)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Jan 29, 2024
1 parent 037ada2 commit 9bf52e4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 49 deletions.
1 change: 0 additions & 1 deletion tests/lib/rules/no-reserved-component-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ const invalidElements = [
'menu',
'Menu',
'menuitem',
'menuitem',
'summary',
'Summary',
'content',
Expand Down
103 changes: 55 additions & 48 deletions tests/lib/rules/this-in-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ function createValidTests(prefix, options) {
code: `<template><div v-if="${prefix}foo()">{{ ${prefix}bar }}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div :parent="this"></div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div v-for="x of ${prefix}xs">{{this.x}}</div></template><!-- ${comment} -->`,
options
Expand All @@ -67,26 +63,6 @@ function createValidTests(prefix, options) {
code: `<template><div v-for="x of ${prefix}xs">{{this['x']}}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div>{{ this.class }}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div>{{ this['0'] }}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div>{{ this['this'] }}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div>{{ this['foo bar'] }}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div>{{ }}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template>
<div>
Expand All @@ -97,12 +73,6 @@ function createValidTests(prefix, options) {
</div>
</template><!-- ${comment} -->`,
options
},

// We cannot use `.` in dynamic arguments because the right of the `.` becomes a modifier.
{
code: `<template><div v-on:[x]="1"></div></template><!-- ${comment} -->`,
options
}
]
}
Expand Down Expand Up @@ -181,30 +151,14 @@ function createInvalidTests(prefix, options, message, type) {
)}bar"></div></template><!-- ${comment} -->`,
errors: [{ message, type }],
options
},
}

// We cannot use `.` in dynamic arguments because the right of the `.` becomes a modifier.
// {
// code: `<template><div v-on:[${prefix}name]="1"></div></template><!-- ${comment} -->`,
// errors: [{ message, type }],
// options
// }
...(options[0] === 'always'
? []
: [
{
code: `<template><div>{{ this['xs'] }}</div></template><!-- ${comment} -->`,
output: `<template><div>{{ xs }}</div></template><!-- ${comment} -->`,
errors: [{ message, type }],
options
},
{
code: `<template><div>{{ this['xs0AZ_foo'] }}</div></template><!-- ${comment} -->`,
output: `<template><div>{{ xs0AZ_foo }}</div></template><!-- ${comment} -->`,
errors: [{ message, type }],
options
}
])
]
}

Expand All @@ -216,7 +170,41 @@ ruleTester.run('this-in-template', rule, {
...createValidTests('', []),
...createValidTests('', ['never']),
...createValidTests('this.', ['always']),
...createValidTests('this?.', ['always'])
...createValidTests('this?.', ['always']),
...[[], ['never'], ['always']].flatMap((options) => {
const comment = options.join('')
return [
{
code: `<template><div :parent="this"></div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div>{{ this.class }}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div>{{ this['0'] }}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div>{{ this['this'] }}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div>{{ this['foo bar'] }}</div></template><!-- ${comment} -->`,
options
},
{
code: `<template><div>{{ }}</div></template><!-- ${comment} -->`,
options
},
// We cannot use `.` in dynamic arguments because the right of the `.` becomes a modifier.
{
code: `<template><div v-on:[x]="1"></div></template><!-- ${comment} -->`,
options
}
]
})
],
invalid: [
...createInvalidTests(
Expand Down Expand Up @@ -244,6 +232,25 @@ ruleTester.run('this-in-template', rule, {
'ThisExpression'
),
...createInvalidTests('', ['always'], "Expected 'this'.", 'Identifier'),
...[[], ['never']].flatMap((options) => {
const comment = options.join('')
const message = "Unexpected usage of 'this'."
const type = 'ThisExpression'
return [
{
code: `<template><div>{{ this['xs'] }}</div></template><!-- ${comment} -->`,
output: `<template><div>{{ xs }}</div></template><!-- ${comment} -->`,
errors: [{ message, type }],
options
},
{
code: `<template><div>{{ this['xs0AZ_foo'] }}</div></template><!-- ${comment} -->`,
output: `<template><div>{{ xs0AZ_foo }}</div></template><!-- ${comment} -->`,
errors: [{ message, type }],
options
}
]
}),
{
code: `<template><div v-if="fn(this.$foo)"></div></template><!-- never -->`,
output: `<template><div v-if="fn($foo)"></div></template><!-- never -->`,
Expand Down

0 comments on commit 9bf52e4

Please sign in to comment.