Skip to content

Commit 8c861d3

Browse files
committed
feat(RFC0005): provide autofix fix for deprecated v-bind.prop.sync modifier
1 parent 7fcd2eb commit 8c861d3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

docs/rules/no-deprecated-v-bind-sync.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ description: disallow use of deprecated `.sync` modifier on `v-bind` directive (
77
# vue/no-deprecated-v-bind-sync
88
> disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+)
99
10+
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
11+
1012
## :book: Rule Details
1113

1214
This rule reports use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+)
1315

14-
<eslint-code-block :rules="{'vue/no-deprecated-v-bind-sync': ['error']}">
16+
<eslint-code-block fix :rules="{'vue/no-deprecated-v-bind-sync': ['error']}">
1517

1618
```vue
1719
<template>

lib/rules/no-deprecated-v-bind-sync.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
category: undefined,
2323
url: 'https://eslint.vuejs.org/rules/no-deprecated-v-bind-sync.html'
2424
},
25-
fixable: null,
25+
fixable: 'code',
2626
schema: [],
2727
messages: {
2828
syncModifierIsDeprecated: "'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."
@@ -35,7 +35,14 @@ module.exports = {
3535
context.report({
3636
node,
3737
loc: node.loc,
38-
messageId: 'syncModifierIsDeprecated'
38+
messageId: 'syncModifierIsDeprecated',
39+
fix: (fixer) => {
40+
const isUsingSpreadSyntax = node.key.argument == null
41+
if (isUsingSpreadSyntax) {
42+
return
43+
}
44+
return fixer.replaceText(node.key, `v-model:${node.key.argument.rawName}`)
45+
}
3946
})
4047
}
4148
}

0 commit comments

Comments
 (0)