-
-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added array-element-newline rule from eslint (#2066)
Co-authored-by: Antoine SAVAJOLS <[email protected]>
- Loading branch information
Showing
6 changed files
with
315 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/array-element-newline | ||
description: Enforce line breaks after each array element in `<template>` | ||
--- | ||
# vue/array-element-newline | ||
|
||
> Enforce line breaks after each array element in `<template>` | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
- :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-element-newline] rule but it applies to the expressions in `<template>`. | ||
|
||
## :books: Further Reading | ||
|
||
- [array-bracket-spacing] | ||
|
||
[array-bracket-spacing]: https://eslint.org/docs/rules/array-bracket-spacing | ||
|
||
- [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-element-newline.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/array-element-newline.js) | ||
|
||
<sup>Taken with ❤️ [from ESLint core](https://eslint.org/docs/rules/array-element-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
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 alshyra | ||
*/ | ||
'use strict' | ||
|
||
const { wrapCoreRule } = require('../utils') | ||
|
||
// eslint-disable-next-line no-invalid-meta, no-invalid-meta-docs-categories | ||
module.exports = wrapCoreRule('array-element-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,270 @@ | ||
/** | ||
* @author alshyra | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../lib/rules/array-element-newline') | ||
|
||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module' | ||
} | ||
}) | ||
|
||
tester.run('array-element-newline', rule, { | ||
valid: [ | ||
'<template><div :attr="[]" /></template>', | ||
'<template><div :attr="[a]" /></template>', | ||
` | ||
<template> | ||
<div :attr="[a, | ||
b, | ||
c]" /> | ||
</template>`, | ||
`<template> | ||
<div :attr="[a, | ||
b, | ||
c | ||
]" /> | ||
</template>`, | ||
'<template><div :[attr]="a" /></template>', | ||
'<template><div :[[attr]]="a" /></template>', | ||
`<template> | ||
<div :attr="[ | ||
a, | ||
b, | ||
c | ||
]" /> | ||
</template>`, | ||
` | ||
<template> | ||
<div :attr="[a | ||
b]" /> | ||
</template>`, | ||
{ | ||
code: ` | ||
<template> | ||
<div :attr="[a, | ||
b, | ||
c]" /> | ||
</template>`, | ||
options: ['always'] | ||
}, | ||
{ | ||
code: '<template><div :attr="[a]" /></template>', | ||
options: ['never'] | ||
}, | ||
{ | ||
code: '<template><div :attr="[a,b,c]" /></template>', | ||
options: ['never'] | ||
}, | ||
{ | ||
code: '<template><div :attr="[a, b, c]" /></template>', | ||
options: [{ multiline: true }] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :attr="[a, | ||
{ | ||
b:c | ||
}]" /> | ||
</template>`, | ||
options: [{ multiline: true }] | ||
}, | ||
{ | ||
code: '<template><div :attr="[a, b, c]" /></template>', | ||
options: ['consistent'] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :attr="[a, | ||
b, | ||
c | ||
]" /> | ||
</template>`, | ||
options: ['consistent'] | ||
}, | ||
{ | ||
code: '<template><div :attr="[a,b]" /></template>', | ||
options: [{ minItems: 3 }] | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div :attr="[a, b]" /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<div :attr="[a, | ||
b]" /> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: 'There should be a linebreak after this element.', | ||
line: 3, | ||
column: 26, | ||
endLine: 3, | ||
endColumn: 27 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :attr="[a,b,c]" /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<div :attr="[a, | ||
b, | ||
c]" /> | ||
</template>`, | ||
options: ['always'], | ||
errors: [ | ||
{ | ||
message: 'There should be a linebreak after this element.', | ||
line: 3, | ||
column: 26, | ||
endLine: 3, | ||
endColumn: 26 | ||
}, | ||
{ | ||
message: 'There should be a linebreak after this element.', | ||
line: 3, | ||
column: 28, | ||
endLine: 3, | ||
endColumn: 28 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :attr="[a, | ||
b,c]" /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<div :attr="[a, | ||
b, | ||
c]" /> | ||
</template>`, | ||
options: ['always'], | ||
errors: [ | ||
{ | ||
message: 'There should be a linebreak after this element.', | ||
line: 4, | ||
column: 25, | ||
endLine: 4, | ||
endColumn: 25 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :attr="[a, | ||
b,c]" /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<div :attr="[a, | ||
b, | ||
c]" /> | ||
</template>`, | ||
options: ['consistent'], | ||
errors: [ | ||
{ | ||
message: 'There should be a linebreak after this element.', | ||
line: 4, | ||
column: 26, | ||
endLine: 4, | ||
endColumn: 26 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :attr="[a, | ||
b, c]" /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<div :attr="[a, b, c]" /> | ||
</template>`, | ||
options: [{ multiline: true }], | ||
errors: [ | ||
{ | ||
message: 'There should be no linebreak here.', | ||
line: 3, | ||
column: 26, | ||
endLine: 4, | ||
endColumn: 24 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :attr="[a, { | ||
b:c | ||
}]" /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<div :attr="[a, | ||
{ | ||
b:c | ||
}]" /> | ||
</template>`, | ||
options: [{ multiline: true }], | ||
errors: [ | ||
{ | ||
message: 'There should be a linebreak after this element.', | ||
line: 3, | ||
column: 26, | ||
endLine: 3, | ||
endColumn: 27 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div :attr="[a,b,c]" /> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<div :attr="[a, | ||
b, | ||
c]" /> | ||
</template>`, | ||
options: [{ minItems: 2 }], | ||
errors: [ | ||
{ | ||
message: 'There should be a linebreak after this element.', | ||
line: 3, | ||
column: 26, | ||
endLine: 3, | ||
endColumn: 26 | ||
}, | ||
{ | ||
message: 'There should be a linebreak after this element.', | ||
line: 3, | ||
column: 28, | ||
endLine: 3, | ||
endColumn: 28 | ||
} | ||
] | ||
} | ||
] | ||
}) |