Skip to content

Commit

Permalink
feat(RFC0005): provide autofix fix for deprecated v-bind.prop.sync mo…
Browse files Browse the repository at this point in the history
…difier
  • Loading branch information
przemkow committed Jan 25, 2020
1 parent 050e295 commit 723ffab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/rules/no-deprecated-v-bind-sync.md
Expand Up @@ -7,11 +7,13 @@ description: Disallow use of deprecated `.sync` modifier on `v-bind` directive (
# vue/no-deprecated-v-bind-sync
> Disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+)
- :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.

## :book: Rule Details

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

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

```vue
<template>
Expand Down
11 changes: 9 additions & 2 deletions lib/rules/no-deprecated-v-bind-sync.js
Expand Up @@ -22,7 +22,7 @@ module.exports = {
category: undefined,
url: 'https://eslint.vuejs.org/rules/no-deprecated-v-bind-sync.html'
},
fixable: null,
fixable: 'code',
schema: [],
messages: {
syncModifierIsDeprecated: "'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."
Expand All @@ -35,7 +35,14 @@ module.exports = {
context.report({
node,
loc: node.loc,
messageId: 'syncModifierIsDeprecated'
messageId: 'syncModifierIsDeprecated',
fix: (fixer) => {
const isUsingSpreadSyntax = node.key.argument == null
if (isUsingSpreadSyntax) {
return
}
return fixer.replaceText(node.key, `v-model:${node.key.argument.rawName}`)
}
})
}
}
Expand Down

0 comments on commit 723ffab

Please sign in to comment.