Skip to content

Commit 7fcd2eb

Browse files
committed
feat(RFC0005): add no-deprecated-v-bind-sync rule
1 parent efe4a58 commit 7fcd2eb

File tree

6 files changed

+216
-0
lines changed

6 files changed

+216
-0
lines changed

docs/rules/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ For example:
159159
| [vue/no-deprecated-scope-attribute](./no-deprecated-scope-attribute.md) | disallow deprecated `scope` attribute (in Vue.js 2.5.0+) | :wrench: |
160160
| [vue/no-deprecated-slot-attribute](./no-deprecated-slot-attribute.md) | disallow deprecated `slot` attribute (in Vue.js 2.6.0+) | :wrench: |
161161
| [vue/no-deprecated-slot-scope-attribute](./no-deprecated-slot-scope-attribute.md) | disallow deprecated `slot-scope` attribute (in Vue.js 2.6.0+) | :wrench: |
162+
| [vue/no-deprecated-v-bind-sync](./no-deprecated-v-bind-sync.md) | disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+) | :wrench: |
162163
| [vue/no-empty-pattern](./no-empty-pattern.md) | disallow empty destructuring patterns | |
163164
| [vue/no-irregular-whitespace](./no-irregular-whitespace.md) | disallow irregular whitespace | |
164165
| [vue/no-reserved-component-names](./no-reserved-component-names.md) | disallow the use of reserved names in component definitions | |
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/no-deprecated-v-bind-sync
5+
description: disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+)
6+
---
7+
# vue/no-deprecated-v-bind-sync
8+
> disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+)
9+
10+
## :book: Rule Details
11+
12+
This rule reports use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+)
13+
14+
<eslint-code-block :rules="{'vue/no-deprecated-v-bind-sync': ['error']}">
15+
16+
```vue
17+
<template>
18+
<!-- ✓ GOOD -->
19+
<MyComponent v-bind:propName="foo"/>
20+
<MyComponent :propName="foo"/>
21+
22+
23+
<!-- ✗ BAD -->
24+
<MyComponent v-bind:propName.sync="foo"/>
25+
<MyComponent v-bind.sync="foo"/>
26+
<MyComponent :propName.sync="foo"/>
27+
</template>
28+
```
29+
30+
</eslint-code-block>
31+
32+
## :wrench: Options
33+
34+
Nothing.
35+
36+
## :couple: Related rules
37+
38+
- [valid-v-bind]
39+
40+
[valid-v-bind]: valid-v-bind.md
41+
42+
## :books: Further reading
43+
44+
- [RFC: Replace v-bind.sync with v-model argument](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0005-replace-v-bind-sync-with-v-model-argument.md)
45+
46+
## :mag: Implementation
47+
48+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-v-bind-sync.js)
49+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-v-bind-sync.js)

docs/rules/valid-v-bind.md

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ Nothing.
5454

5555
[no-parsing-error]: no-parsing-error.md
5656

57+
- [no-deprecated-v-bind-sync]
58+
59+
[no-deprecated-v-bind-sync]: no-deprecated-v-bind-sync.md
60+
61+
- [valid-v-bind-sync]
62+
63+
[valid-v-bind-sync]: valid-v-bind-sync.md
64+
5765
## :mag: Implementation
5866

5967
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/valid-v-bind.js)

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module.exports = {
4242
'no-deprecated-scope-attribute': require('./rules/no-deprecated-scope-attribute'),
4343
'no-deprecated-slot-attribute': require('./rules/no-deprecated-slot-attribute'),
4444
'no-deprecated-slot-scope-attribute': require('./rules/no-deprecated-slot-scope-attribute'),
45+
'no-deprecated-v-bind-sync': require('./rules/no-deprecated-v-bind-sync'),
4546
'no-dupe-keys': require('./rules/no-dupe-keys'),
4647
'no-duplicate-attributes': require('./rules/no-duplicate-attributes'),
4748
'no-empty-pattern': require('./rules/no-empty-pattern'),
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @author Przemyslaw Falowski (@przemkow)
3+
* @fileoverview Disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+)
4+
*/
5+
'use strict'
6+
7+
// ------------------------------------------------------------------------------
8+
// Requirements
9+
// ------------------------------------------------------------------------------
10+
11+
const utils = require('../utils')
12+
13+
// ------------------------------------------------------------------------------
14+
// Rule Definition
15+
// ------------------------------------------------------------------------------
16+
17+
module.exports = {
18+
meta: {
19+
type: 'problem',
20+
docs: {
21+
description: 'disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+)',
22+
category: undefined,
23+
url: 'https://eslint.vuejs.org/rules/no-deprecated-v-bind-sync.html'
24+
},
25+
fixable: null,
26+
schema: [],
27+
messages: {
28+
syncModifierIsDeprecated: "'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."
29+
}
30+
},
31+
create (context) {
32+
return utils.defineTemplateBodyVisitor(context, {
33+
"VAttribute[directive=true][key.name.name='bind']" (node) {
34+
if (node.key.modifiers.map(mod => mod.name).includes('sync')) {
35+
context.report({
36+
node,
37+
loc: node.loc,
38+
messageId: 'syncModifierIsDeprecated'
39+
})
40+
}
41+
}
42+
})
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* @author Przemyslaw Falowski (@przemkow)
3+
* @fileoverview Disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+)
4+
*/
5+
'use strict'
6+
7+
// ------------------------------------------------------------------------------
8+
// Requirements
9+
// ------------------------------------------------------------------------------
10+
11+
const rule = require('../../../lib/rules/no-deprecated-v-bind-sync')
12+
const RuleTester = require('eslint').RuleTester
13+
14+
// ------------------------------------------------------------------------------
15+
// Tests
16+
// ------------------------------------------------------------------------------
17+
18+
const ruleTester = new RuleTester({
19+
parser: require.resolve('vue-eslint-parser'),
20+
parserOptions: { ecmaVersion: 2015 }
21+
})
22+
23+
ruleTester.run('no-deprecated-v-bind-sync', rule, {
24+
25+
valid: [
26+
{
27+
filename: 'test.vue',
28+
code: "<template><MyComponent v-bind:foo='bar'/></template>"
29+
},
30+
{
31+
filename: 'test.vue',
32+
code: "<template><MyComponent :foo='bar'/></template>"
33+
}
34+
],
35+
36+
invalid: [
37+
{
38+
filename: 'test.vue',
39+
code: "<template><MyComponent v-bind:foo.sync='bar'/></template>",
40+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
41+
},
42+
{
43+
filename: 'test.vue',
44+
code: "<template><MyComponent :foo.sync='bar'/></template>",
45+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
46+
},
47+
{
48+
filename: 'test.vue',
49+
code: "<template><MyComponent v-bind.sync='bar'/></template>",
50+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
51+
},
52+
{
53+
filename: 'test.vue',
54+
code: '<template><MyComponent :foo.sync.unknown="foo" /></template>',
55+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
56+
},
57+
{
58+
filename: 'test.vue',
59+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="x.foo" /></div></div></template>',
60+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
61+
},
62+
{
63+
filename: 'test.vue',
64+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="foo[x]" /></div></div></template>',
65+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
66+
},
67+
{
68+
filename: 'test.vue',
69+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="foo[x - 1]" /></div></div></template>',
70+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
71+
},
72+
{
73+
filename: 'test.vue',
74+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="foo[`${x}`]" /></div></div></template>',
75+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
76+
},
77+
{
78+
filename: 'test.vue',
79+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="foo[`prefix_${x}`]" /></div></div></template>',
80+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
81+
},
82+
{
83+
filename: 'test.vue',
84+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="foo[x ? x : \'_\']" /></div></div></template>',
85+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
86+
},
87+
{
88+
filename: 'test.vue',
89+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="foo[x || \'_\']" /></div></div></template>',
90+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
91+
},
92+
{
93+
filename: 'test.vue',
94+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="foo[x()]" /></div></div></template>',
95+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
96+
},
97+
{
98+
filename: 'test.vue',
99+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="foo[/r/.match(x) ? 0 : 1]" /></div></div></template>',
100+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
101+
},
102+
{
103+
filename: 'test.vue',
104+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="foo[typeof x]" /></div></div></template>',
105+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
106+
},
107+
{
108+
filename: 'test.vue',
109+
code: '<template><div><div v-for="x in list"><MyComponent :foo.sync="foo[tag`${x}`]" /></div></div></template>',
110+
errors: ["'.sync' modifier on 'v-bind' directive is deprecated. Use 'v-model:propName' instead."]
111+
}
112+
]
113+
})

0 commit comments

Comments
 (0)