Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3812d41

Browse files
Add vue/operator-linebreak rule (#1200)
* Add `vue/operator-linebreak` rule * fix
1 parent ba6ae96 commit 3812d41

File tree

6 files changed

+166
-0
lines changed

6 files changed

+166
-0
lines changed

‎docs/rules/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ The following rules extend the rules provided by ESLint itself and apply them to
333333
| [vue/object-curly-newline](./object-curly-newline.md) | enforce consistent line breaks inside braces | :wrench: |
334334
| [vue/object-curly-spacing](./object-curly-spacing.md) | enforce consistent spacing inside braces | :wrench: |
335335
| [vue/object-property-newline](./object-property-newline.md) | enforce placing object properties on separate lines | :wrench: |
336+
| [vue/operator-linebreak](./operator-linebreak.md) | enforce consistent linebreak style for operators | :wrench: |
336337
| [vue/prefer-template](./prefer-template.md) | require template literals instead of string concatenation | :wrench: |
337338
| [vue/space-in-parens](./space-in-parens.md) | enforce consistent spacing inside parentheses | :wrench: |
338339
| [vue/space-infix-ops](./space-infix-ops.md) | require spacing around infix operators | :wrench: |

‎docs/rules/operator-linebreak.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/operator-linebreak
5+
description: enforce consistent linebreak style for operators
6+
---
7+
# vue/operator-linebreak
8+
> enforce consistent linebreak style for operators
9+
10+
- :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.
11+
12+
This rule is the same rule as core [operator-linebreak] rule but it applies to the expressions in `<template>`.
13+
14+
## :books: Further reading
15+
16+
- [operator-linebreak]
17+
18+
[operator-linebreak]: https://eslint.org/docs/rules/operator-linebreak
19+
20+
## :mag: Implementation
21+
22+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/operator-linebreak.js)
23+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/operator-linebreak.js)
24+
25+
<sup>Taken with ❤️ [from ESLint core](https://eslint.org/docs/rules/operator-linebreak)</sup>

‎lib/configs/no-layout-rules.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = {
3333
'vue/object-curly-newline': 'off',
3434
'vue/object-curly-spacing': 'off',
3535
'vue/object-property-newline': 'off',
36+
'vue/operator-linebreak': 'off',
3637
'vue/padding-line-between-blocks': 'off',
3738
'vue/script-indent': 'off',
3839
'vue/singleline-html-element-content-newline': 'off',

‎lib/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ module.exports = {
108108
'object-curly-spacing': require('./rules/object-curly-spacing'),
109109
'object-property-newline': require('./rules/object-property-newline'),
110110
'one-component-per-file': require('./rules/one-component-per-file'),
111+
'operator-linebreak': require('./rules/operator-linebreak'),
111112
'order-in-components': require('./rules/order-in-components'),
112113
'padding-line-between-blocks': require('./rules/padding-line-between-blocks'),
113114
'prefer-template': require('./rules/prefer-template'),

‎lib/rules/operator-linebreak.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Yosuke Ota
3+
*/
4+
'use strict'
5+
6+
const { wrapCoreRule } = require('../utils')
7+
8+
// eslint-disable-next-line no-invalid-meta, no-invalid-meta-docs-categories
9+
module.exports = wrapCoreRule(require('eslint/lib/rules/operator-linebreak'))
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/**
2+
* @author Yosuke Ota
3+
*/
4+
'use strict'
5+
6+
const RuleTester = require('eslint').RuleTester
7+
const rule = require('../../../lib/rules/operator-linebreak')
8+
9+
const tester = new RuleTester({
10+
parser: require.resolve('vue-eslint-parser'),
11+
parserOptions: { ecmaVersion: 2020 }
12+
})
13+
14+
tester.run('operator-linebreak', rule, {
15+
valid: [
16+
`
17+
<template>
18+
<div :foo="1 + 2" />
19+
</template>
20+
`,
21+
{
22+
code: `
23+
<template>
24+
<div :foo="1 + 2" />
25+
</template>
26+
`,
27+
options: ['before']
28+
},
29+
{
30+
code: `
31+
<template>
32+
<div :foo="1 + 2" />
33+
</template>
34+
`,
35+
options: ['none']
36+
},
37+
`
38+
<template>
39+
<div :[foo+bar]="value" />
40+
</template>
41+
`,
42+
{
43+
code: `
44+
<template>
45+
<div :[foo+bar]="value" />
46+
</template>
47+
`,
48+
options: ['before']
49+
},
50+
{
51+
code: `
52+
<template>
53+
<div :[foo+bar]="value" />
54+
</template>
55+
`,
56+
options: ['none']
57+
}
58+
],
59+
invalid: [
60+
{
61+
code: `
62+
<template>
63+
<div :foo="1
64+
+ 2" />
65+
</template>
66+
`,
67+
output: `
68+
<template>
69+
<div :foo="1 +
70+
2" />
71+
</template>
72+
`,
73+
errors: [
74+
{
75+
message: "'+' should be placed at the end of the line.",
76+
line: 4
77+
}
78+
]
79+
},
80+
{
81+
code: `
82+
<template>
83+
<div :foo="1 +
84+
2" />
85+
</template>
86+
`,
87+
output: `
88+
<template>
89+
<div :foo="1
90+
+ 2" />
91+
</template>
92+
`,
93+
options: ['before'],
94+
errors: [
95+
{
96+
message: "'+' should be placed at the beginning of the line.",
97+
line: 3
98+
}
99+
]
100+
},
101+
{
102+
code: `
103+
<template>
104+
<div :foo="1 +
105+
2" />
106+
<div :foo="1
107+
+ 2" />
108+
</template>
109+
`,
110+
output: `
111+
<template>
112+
<div :foo="1 + 2" />
113+
<div :foo="1 + 2" />
114+
</template>
115+
`,
116+
options: ['none'],
117+
errors: [
118+
{
119+
message: "There should be no line break before or after '+'.",
120+
line: 3
121+
},
122+
{
123+
message: "There should be no line break before or after '+'.",
124+
line: 6
125+
}
126+
]
127+
}
128+
]
129+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /