Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
vue/no-sparse-arrays
rule (#1243)
- Loading branch information
Showing
5 changed files
with
89 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,23 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/no-sparse-arrays | ||
description: disallow sparse arrays | ||
--- | ||
# vue/no-sparse-arrays | ||
> disallow sparse arrays | ||
This rule is the same rule as core [no-sparse-arrays] rule but it applies to the expressions in `<template>`. | ||
|
||
## :books: Further reading | ||
|
||
- [no-sparse-arrays] | ||
|
||
[no-sparse-arrays]: https://eslint.org/docs/rules/no-sparse-arrays | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-sparse-arrays.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-sparse-arrays.js) | ||
|
||
<sup>Taken with ❤️ [from ESLint core](https://eslint.org/docs/rules/no-sparse-arrays)</sup> |
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 no-invalid-meta, no-invalid-meta-docs-categories | ||
module.exports = wrapCoreRule(require('eslint/lib/rules/no-sparse-arrays')) |
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,55 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../lib/rules/no-sparse-arrays') | ||
|
||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { ecmaVersion: 2015 } | ||
}) | ||
|
||
tester.run('no-sparse-arrays', rule, { | ||
valid: [ | ||
`<template> | ||
<div :class="['foo', 'bar']" /> | ||
</template>`, | ||
`<template> | ||
<div v-bind:[['foo'][0]]="bar" /> | ||
</template>` | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div :class="[, 'foo', 'bar']" /> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected comma in middle of array.', | ||
line: 3, | ||
column: 22, | ||
endLine: 3, | ||
endColumn: 38 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div v-bind:[[,'foo'][1]]="bar" /> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'Unexpected comma in middle of array.', | ||
line: 3, | ||
column: 22, | ||
endLine: 3, | ||
endColumn: 30 | ||
} | ||
] | ||
} | ||
] | ||
}) |