Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
vue/no-unsupported-features
rule to support Vue 3.2 syntaxes. (
- Loading branch information
Showing
9 changed files
with
226 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
module.exports = { | ||
supported: '>=3.2.0', | ||
/** @param {RuleContext} context @returns {TemplateListener} */ | ||
createTemplateBodyVisitor(context) { | ||
/** | ||
* Reports `v-bind.attr` node | ||
* @param { VIdentifier } mod node of `v-bind.attr` | ||
* @returns {void} | ||
*/ | ||
function report(mod) { | ||
context.report({ | ||
node: mod, | ||
messageId: 'forbiddenVBindAttrModifier' | ||
}) | ||
} | ||
|
||
return { | ||
"VAttribute[directive=true][key.name.name='bind']"(node) { | ||
const attrMod = node.key.modifiers.find((m) => m.name === 'attr') | ||
if (attrMod) { | ||
report(attrMod) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
module.exports = { | ||
supported: '>=3.2.0', | ||
/** @param {RuleContext} context @returns {TemplateListener} */ | ||
createTemplateBodyVisitor(context) { | ||
/** | ||
* Reports `v-is` node | ||
* @param {VDirective} vMemoAttr node of `v-is` | ||
* @returns {void} | ||
*/ | ||
function reportVMemo(vMemoAttr) { | ||
context.report({ | ||
node: vMemoAttr.key, | ||
messageId: 'forbiddenVMemo' | ||
}) | ||
} | ||
|
||
return { | ||
"VAttribute[directive=true][key.name.name='memo']": reportVMemo | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tests/lib/rules/no-unsupported-features/v-bind-attr-modifier.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../../lib/rules/no-unsupported-features') | ||
const utils = require('./utils') | ||
|
||
const buildOptions = utils.optionsBuilder('v-bind-attr-modifier', '^3.1.0') | ||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { | ||
ecmaVersion: 2019 | ||
} | ||
}) | ||
|
||
tester.run('no-unsupported-features/v-bind-attr-modifier', rule, { | ||
valid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo.attr="foo" /> | ||
</template>`, | ||
options: buildOptions({ version: '^3.2.0' }) | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div v-bind:attr="foo" /> | ||
</template>`, | ||
options: buildOptions() | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo.attr="foo" /> | ||
</template>`, | ||
options: buildOptions({ | ||
version: '^2.5.0', | ||
ignores: ['v-bind-attr-modifier'] | ||
}) | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div :foo.attr="foo" /> | ||
</template>`, | ||
options: buildOptions(), | ||
errors: [ | ||
{ | ||
message: | ||
'`.attr` modifiers on `v-bind` are not supported until Vue.js "3.2.0".', | ||
line: 3 | ||
} | ||
] | ||
} | ||
] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../../lib/rules/no-unsupported-features') | ||
const utils = require('./utils') | ||
|
||
const buildOptions = utils.optionsBuilder('v-memo', '^3.1.0') | ||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { | ||
ecmaVersion: 2019 | ||
} | ||
}) | ||
|
||
tester.run('no-unsupported-features/v-memo', rule, { | ||
valid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div v-memo="foo" /> | ||
</template>`, | ||
options: buildOptions({ version: '^3.2.0' }) | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :memo="foo" /> | ||
</template>`, | ||
options: buildOptions() | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div v-memo="foo" /> | ||
</template>`, | ||
options: buildOptions({ version: '^2.5.0', ignores: ['v-memo'] }) | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div v-memo="foo" /> | ||
</template>`, | ||
options: buildOptions(), | ||
errors: [ | ||
{ | ||
message: '`v-memo` are not supported until Vue.js "3.2.0".', | ||
line: 3 | ||
} | ||
] | ||
} | ||
] | ||
}) |