Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: add
vue/no-empty-pattern
rule (#798)
- Loading branch information
1 parent
5d26e94
commit 4d01589
Showing
5 changed files
with
284 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/no-empty-pattern | ||
description: disallow empty destructuring patterns | ||
--- | ||
# vue/no-empty-pattern | ||
> disallow empty destructuring patterns | ||
This rule is the same rule as core [no-empty-pattern] rule but it applies to the expressions in `<template>`. | ||
|
||
## :books: Further reading | ||
|
||
- [no-empty-pattern] | ||
|
||
[no-empty-pattern]: https://eslint.org/docs/rules/no-empty-pattern | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-empty-pattern.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-empty-pattern.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
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,9 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const { wrapCoreRule } = require('../utils') | ||
|
||
// eslint-disable-next-line | ||
module.exports = wrapCoreRule(require('eslint/lib/rules/no-empty-pattern')) |
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,252 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../lib/rules/no-empty-pattern') | ||
|
||
const tester = new RuleTester({ | ||
parser: 'vue-eslint-parser', | ||
parserOptions: { ecmaVersion: 2018 } | ||
}) | ||
|
||
tester.run('no-empty-pattern', rule, { | ||
valid: [ | ||
`<template> | ||
<div | ||
@attr="() => { | ||
var {a = {}} = foo; | ||
var {a = []} = foo; | ||
}" | ||
/> | ||
</template>`, | ||
`<template> | ||
<div | ||
@attr="function foo({a = {}}) {}" | ||
/> | ||
</template>`, | ||
`<template> | ||
<div | ||
@attr="function foo({a = []}) {}" | ||
/> | ||
</template>`, | ||
`<template> | ||
<div | ||
@attr="({a = {}}) => a" | ||
/> | ||
</template>`, | ||
`<template> | ||
<div | ||
@attr="({a = []}) => a" | ||
/> | ||
</template>`, | ||
`<template> | ||
<div | ||
slot-scope="{a = []}" | ||
/> | ||
</template>` | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
@attr="() => { | ||
var {} = foo; | ||
var [] = foo; | ||
var {a: {}} = foo; | ||
var {a: []} = foo; | ||
}" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty object pattern.', | ||
line: 5 | ||
}, | ||
{ | ||
message: 'Unexpected empty array pattern.', | ||
line: 6 | ||
}, | ||
{ | ||
message: 'Unexpected empty object pattern.', | ||
line: 7 | ||
}, | ||
{ | ||
message: 'Unexpected empty array pattern.', | ||
line: 8 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
@attr="function foo({}) {}" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty object pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
@attr="function foo([]) {}" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty array pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
@attr="function foo({a: {}}) {}" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty object pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
@attr="function foo({a: []}) {}" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty array pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
@attr="({}) => foo()" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty object pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
@attr="([]) => foo()" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty array pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
@attr="({a: {}}) => a" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty object pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
@attr="({a: []}) => a" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty array pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
slot-scope="{}" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty object pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
slot-scope="[]" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty array pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
slot-scope="{a: {}}" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty object pattern.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div | ||
slot-scope="{a: []}" | ||
/> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected empty array pattern.', | ||
line: 4 | ||
} | ||
] | ||
} | ||
|
||
] | ||
}) |