Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
vue/array-bracket-newline
rule (#1326)
* Add `vue/array-bracket-newline` rule `vue/array-bracket-newline` rule that applies `array-bracket-newline` rule to expressions in <template>. * update
- Loading branch information
Showing
6 changed files
with
147 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,25 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/array-bracket-newline | ||
description: enforce linebreaks after opening and before closing array brackets | ||
--- | ||
# vue/array-bracket-newline | ||
> enforce linebreaks after opening and before closing array brackets | ||
- :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. | ||
|
||
This rule is the same rule as core [array-bracket-newline] rule but it applies to the expressions in `<template>`. | ||
|
||
## :books: Further Reading | ||
|
||
- [array-bracket-newline] | ||
|
||
[array-bracket-newline]: https://eslint.org/docs/rules/array-bracket-newline | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/array-bracket-newline.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/array-bracket-newline.js) | ||
|
||
<sup>Taken with ❤️ [from ESLint core](https://eslint.org/docs/rules/array-bracket-newline)</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
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,11 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const { wrapCoreRule } = require('../utils') | ||
|
||
// eslint-disable-next-line no-invalid-meta, no-invalid-meta-docs-categories | ||
module.exports = wrapCoreRule('array-bracket-newline', { | ||
skipDynamicArguments: true | ||
}) |
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,108 @@ | ||
/** | ||
* @author Yosuke Ota | ||
*/ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../lib/rules/array-bracket-newline') | ||
|
||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { ecmaVersion: 2015 } | ||
}) | ||
|
||
tester.run('array-bracket-newline', rule, { | ||
valid: [ | ||
'<template><div :attr="[a]" /></template>', | ||
'<template><div :attr="[\na,\nb,\nc\n]" /></template>', | ||
{ | ||
code: '<template><div :attr="[a]" /></template>', | ||
options: ['never'] | ||
}, | ||
{ | ||
code: '<template><div :attr="[\na\n]" /></template>', | ||
options: ['always'] | ||
}, | ||
'<template><div :[attr]="a" /></template>', | ||
{ | ||
code: '<template><div :[attr]="a" /></template>', | ||
options: ['always'] | ||
}, | ||
'<template><div :[[attr]]="a" /></template>', | ||
{ | ||
code: '<template><div :[[attr]]="a" /></template>', | ||
options: ['always'] | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: '<template><div :attr="[\na]" /></template>', | ||
output: '<template><div :attr="[a]" /></template>', | ||
errors: ["There should be no linebreak after '['."] | ||
}, | ||
{ | ||
code: '<template><div :attr="[a\n]" /></template>', | ||
output: '<template><div :attr="[a]" /></template>', | ||
errors: ["There should be no linebreak before ']'."] | ||
}, | ||
{ | ||
code: '<template><div :attr="[\na\n]" /></template>', | ||
output: '<template><div :attr="[a]" /></template>', | ||
errors: [ | ||
"There should be no linebreak after '['.", | ||
"There should be no linebreak before ']'." | ||
] | ||
}, | ||
{ | ||
code: '<template><div :attr="[\na]" /></template>', | ||
options: ['never'], | ||
output: '<template><div :attr="[a]" /></template>', | ||
errors: ["There should be no linebreak after '['."] | ||
}, | ||
{ | ||
code: '<template><div :attr="[a\n]" /></template>', | ||
options: ['never'], | ||
output: '<template><div :attr="[a]" /></template>', | ||
errors: ["There should be no linebreak before ']'."] | ||
}, | ||
{ | ||
code: '<template><div :attr="[\na\n]" /></template>', | ||
options: ['never'], | ||
output: '<template><div :attr="[a]" /></template>', | ||
errors: [ | ||
"There should be no linebreak after '['.", | ||
"There should be no linebreak before ']'." | ||
] | ||
}, | ||
{ | ||
code: '<template><div :attr="[\na]" /></template>', | ||
options: ['always'], | ||
output: '<template><div :attr="[\na\n]" /></template>', | ||
errors: ["A linebreak is required before ']'."] | ||
}, | ||
{ | ||
code: '<template><div :attr="[a\n]" /></template>', | ||
options: ['always'], | ||
output: '<template><div :attr="[\na\n]" /></template>', | ||
errors: ["A linebreak is required after '['."] | ||
}, | ||
{ | ||
code: '<template><div :attr="[a]" /></template>', | ||
options: ['always'], | ||
output: '<template><div :attr="[\na\n]" /></template>', | ||
errors: [ | ||
"A linebreak is required after '['.", | ||
"A linebreak is required before ']'." | ||
] | ||
}, | ||
{ | ||
code: '<template><div :[[attr]]="[a]" /></template>', | ||
options: ['always'], | ||
output: '<template><div :[[attr]]="[\na\n]" /></template>', | ||
errors: [ | ||
"A linebreak is required after '['.", | ||
"A linebreak is required before ']'." | ||
] | ||
} | ||
] | ||
}) |