Skip to content

Commit ce38da7

Browse files
authored
Supports Optional Chaining (vuejs#1209)
* Supports Optional Chaining * Refactored to resemble eslint core util function naming. e.g. unwrap -> skip * update config * upgrade eslint-utils * Change the supported version of ESLint from 6.0.0 to 6.2.0.
1 parent 8cabc18 commit ce38da7

File tree

60 files changed

+1307
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1307
-378
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- run:
4444
name: Install eslint@6
4545
command: |
46-
npm install -D eslint@6.0.0
46+
npm install -D eslint@6.2.0
4747
- run:
4848
name: Install dependencies
4949
command: npm install

.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ module.exports = {
135135
{
136136
pattern: `https://eslint.vuejs.org/rules/{{name}}.html`
137137
}
138-
]
138+
],
139+
140+
'eslint-plugin/fixer-return': 'off'
139141
}
140142
}
141143
]

docs/.vuepress/components/eslint-code-block.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default {
8989
rules: this.rules,
9090
parser: 'vue-eslint-parser',
9191
parserOptions: {
92-
ecmaVersion: 2019,
92+
ecmaVersion: 2020,
9393
sourceType: 'module',
9494
ecmaFeatures: {
9595
jsx: true

docs/rules/valid-v-bind-sync.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ This rule checks whether every `.sync` modifier on `v-bind` directives is valid.
1515

1616
This rule reports `.sync` modifier on `v-bind` directives in the following cases:
1717

18-
- The `.sync` modifier does not have the attribute value which is valid as LHS. E.g. `<MyComponent v-bind:aaa.sync="foo() + bar()" />`
18+
- The `.sync` modifier does not have the attribute value which is valid as LHS. E.g. `<MyComponent v-bind:aaa.sync="foo() + bar()" />`, `<MyComponent v-bind:aaa.sync="a?.b" />`
19+
- The `.sync` modifier has potential null object property access. E.g. `<MyComponent v-bind:aaa.sync="(a?.b).c" />`
1920
- The `.sync` modifier is on non Vue-components. E.g. `<input v-bind:aaa.sync="foo"></div>`
2021
- The `.sync` modifier's reference is iteration variables. E.g. `<div v-for="x in list"><MyComponent v-bind:aaa.sync="x" /></div>`
2122

@@ -36,6 +37,9 @@ This rule reports `.sync` modifier on `v-bind` directives in the following cases
3637
<MyComponent v-bind:aaa.sync="foo + bar" />
3738
<MyComponent :aaa.sync="foo + bar" />
3839
40+
<MyComponent :aaa.sync="a?.b.c" />
41+
<MyComponent :aaa.sync="(a?.b).c" />
42+
3943
<input v-bind:aaa.sync="foo">
4044
<input :aaa.sync="foo">
4145

docs/rules/valid-v-model.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ This rule reports `v-model` directives in the following cases:
1818
- The directive used on HTMLElement has an argument. E.g. `<input v-model:aaa="foo">`
1919
- The directive used on HTMLElement has modifiers which are not supported. E.g. `<input v-model.bbb="foo">`
2020
- The directive does not have that attribute value. E.g. `<input v-model>`
21-
- The directive does not have the attribute value which is valid as LHS. E.g. `<input v-model="foo() + bar()">`
21+
- The directive does not have the attribute value which is valid as LHS. E.g. `<input v-model="foo() + bar()">`, `<input v-model="a?.b">`
22+
- The directive has potential null object property access. E.g. `<input v-model="(a?.b).c">`
2223
- The directive is on unsupported elements. E.g. `<div v-model="foo"></div>`
2324
- The directive is on `<input>` elements which their types are `file`. E.g. `<input type="file" v-model="foo">`
2425
- The directive's reference is iteration variables. E.g. `<div v-for="x in list"><input type="file" v-model="x"></div>`
@@ -44,6 +45,8 @@ This rule reports `v-model` directives in the following cases:
4445
<input v-model:aaa="foo">
4546
<input v-model.bbb="foo">
4647
<input v-model="foo + bar">
48+
<input v-model="a?.b.c">
49+
<input v-model="(a?.b).c">
4750
<div v-model="foo"/>
4851
<div v-for="todo in todos">
4952
<input v-model="todo">

docs/user-guide/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ yarn add -D eslint eslint-plugin-vue@next
1818
```
1919

2020
::: tip Requirements
21-
- ESLint v6.0.0 and above
21+
- ESLint v6.2.0 and above
2222
- Node.js v8.10.0 and above
2323
:::
2424

lib/configs/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
module.exports = {
77
parser: require.resolve('vue-eslint-parser'),
88
parserOptions: {
9-
ecmaVersion: 2018,
9+
ecmaVersion: 2020,
1010
sourceType: 'module'
1111
},
1212
env: {

lib/rules/component-name-in-template-casing.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,13 @@ module.exports = {
135135
name,
136136
caseType
137137
},
138-
fix: (fixer) => {
138+
*fix(fixer) {
139+
yield fixer.replaceText(open, `<${casingName}`)
139140
const endTag = node.endTag
140-
if (!endTag) {
141-
return fixer.replaceText(open, `<${casingName}`)
141+
if (endTag) {
142+
const endTagOpen = tokens.getFirstToken(endTag)
143+
yield fixer.replaceText(endTagOpen, `</${casingName}`)
142144
}
143-
const endTagOpen = tokens.getFirstToken(endTag)
144-
return [
145-
fixer.replaceText(open, `<${casingName}`),
146-
fixer.replaceText(endTagOpen, `</${casingName}`)
147-
]
148145
}
149146
})
150147
}

lib/rules/custom-event-name-casing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function getNameParamNode(node) {
4848
* @param {CallExpression} node CallExpression
4949
*/
5050
function getCalleeMemberNode(node) {
51-
const callee = node.callee
51+
const callee = utils.skipChainExpression(node.callee)
5252

5353
if (callee.type === 'MemberExpression') {
5454
const name = utils.getStaticPropertyName(callee)
@@ -116,7 +116,7 @@ module.exports = {
116116
utils.compositingVisitors(
117117
utils.defineVueVisitor(context, {
118118
onSetupFunctionEnter(node, { node: vueNode }) {
119-
const contextParam = utils.unwrapAssignmentPattern(node.params[1])
119+
const contextParam = utils.skipDefaultParamValue(node.params[1])
120120
if (!contextParam) {
121121
// no arguments
122122
return

lib/rules/html-self-closing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ module.exports = {
163163
elementType: ELEMENT_TYPE_MESSAGES[elementType],
164164
name: node.rawName
165165
},
166-
fix: (fixer) => {
166+
fix(fixer) {
167167
const tokens = context.parserServices.getTemplateBodyTokenStore()
168168
const close = tokens.getLastToken(node.startTag)
169169
if (close.type !== 'HTMLTagClose') {
@@ -187,7 +187,7 @@ module.exports = {
187187
elementType: ELEMENT_TYPE_MESSAGES[elementType],
188188
name: node.rawName
189189
},
190-
fix: (fixer) => {
190+
fix(fixer) {
191191
const tokens = context.parserServices.getTemplateBodyTokenStore()
192192
const close = tokens.getLastToken(node.startTag)
193193
if (close.type !== 'HTMLSelfClosingTagClose') {

0 commit comments

Comments
 (0)