-
-
Notifications
You must be signed in to change notification settings - Fork 667
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade vue-eslint-parser and add support for v-bind same-name shorth…
…and (#2357)
- Loading branch information
Showing
13 changed files
with
195 additions
and
46 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
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,34 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
const utils = require('../../utils') | ||
|
||
module.exports = { | ||
supported: '>=3.4.0', | ||
/** @param {RuleContext} context @returns {TemplateListener} */ | ||
createTemplateBodyVisitor(context) { | ||
/** | ||
* Verify the directive node | ||
* @param {VDirective} node The directive node to check | ||
* @returns {void} | ||
*/ | ||
function checkDirective(node) { | ||
if (utils.isVBindSameNameShorthand(node)) { | ||
context.report({ | ||
node, | ||
messageId: 'forbiddenVBindSameNameShorthand', | ||
// fix to use `:x="x"` (downgrade) | ||
fix: (fixer) => | ||
fixer.insertTextAfter(node, `="${node.value.expression.name}"`) | ||
}) | ||
} | ||
} | ||
|
||
return { | ||
"VAttribute[directive=true][key.name.name='bind']": checkDirective | ||
} | ||
} | ||
} |
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
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
95 changes: 95 additions & 0 deletions
95
tests/lib/rules/no-unsupported-features/v-bind-same-name-shorthand.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,95 @@ | ||
/** | ||
* @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-same-name-shorthand', | ||
'^3.3.0' | ||
) | ||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { | ||
ecmaVersion: 2019 | ||
} | ||
}) | ||
|
||
tester.run('no-unsupported-features/v-bind-same-name-shorthand', rule, { | ||
valid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div :x /> | ||
</template>`, | ||
options: buildOptions({ version: '3.4.0' }) | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :x="x" /> | ||
</template>`, | ||
options: buildOptions() | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div :x /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<div :x="x" /> | ||
</template>`, | ||
options: buildOptions(), | ||
errors: [ | ||
{ | ||
message: | ||
'`v-bind` same-name shorthand is not supported until Vue.js "3.4.0".', | ||
line: 3 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :x /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<div :x="x" /> | ||
</template>`, | ||
options: buildOptions({ version: '2.7.0' }), | ||
errors: [ | ||
{ | ||
message: | ||
'`v-bind` same-name shorthand is not supported until Vue.js "3.4.0".', | ||
line: 3 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :data-x /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<div :data-x="dataX" /> | ||
</template>`, | ||
options: buildOptions(), | ||
errors: [ | ||
{ | ||
message: | ||
'`v-bind` same-name shorthand is not supported until Vue.js "3.4.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
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