Skip to content

Commit

Permalink
Added array-element-newline rule from eslint (#2066)
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine SAVAJOLS <[email protected]>
  • Loading branch information
alshyra and Antoine SAVAJOLS authored Dec 25, 2022
1 parent a15d036 commit 89fb2fe
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/rules/array-element-newline.md
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>
1 change: 1 addition & 0 deletions docs/rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ The following rules extend the rules provided by ESLint itself and apply them to
|:--------|:------------|:--:|:--:|
| [vue/array-bracket-newline](./array-bracket-newline.md) | Enforce linebreaks after opening and before closing array brackets in `<template>` | :wrench: | :lipstick: |
| [vue/array-bracket-spacing](./array-bracket-spacing.md) | Enforce consistent spacing inside array brackets in `<template>` | :wrench: | :lipstick: |
| [vue/array-element-newline](./array-element-newline.md) | Enforce line breaks after each array element in `<template>` | :wrench: | :lipstick: |
| [vue/arrow-spacing](./arrow-spacing.md) | Enforce consistent spacing before and after the arrow in arrow functions in `<template>` | :wrench: | :lipstick: |
| [vue/block-spacing](./block-spacing.md) | Disallow or enforce spaces inside of blocks after opening block and before closing block in `<template>` | :wrench: | :lipstick: |
| [vue/brace-style](./brace-style.md) | Enforce consistent brace style for blocks in `<template>` | :wrench: | :lipstick: |
Expand Down
1 change: 1 addition & 0 deletions lib/configs/no-layout-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
rules: {
'vue/array-bracket-newline': 'off',
'vue/array-bracket-spacing': 'off',
'vue/array-element-newline': 'off',
'vue/arrow-spacing': 'off',
'vue/block-spacing': 'off',
'vue/block-tag-newline': 'off',
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
rules: {
'array-bracket-newline': require('./rules/array-bracket-newline'),
'array-bracket-spacing': require('./rules/array-bracket-spacing'),
'array-element-newline': require('./rules/array-element-newline'),
'arrow-spacing': require('./rules/arrow-spacing'),
'attribute-hyphenation': require('./rules/attribute-hyphenation'),
'attributes-order': require('./rules/attributes-order'),
Expand Down
11 changes: 11 additions & 0 deletions lib/rules/array-element-newline.js
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
})
270 changes: 270 additions & 0 deletions tests/lib/rules/array-element-newline.js
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
}
]
}
]
})

0 comments on commit 89fb2fe

Please sign in to comment.