File tree 6 files changed +166
-0
lines changed
6 files changed +166
-0
lines changed Original file line number Diff line number Diff line change @@ -333,6 +333,7 @@ The following rules extend the rules provided by ESLint itself and apply them to
333
333
| [ vue/object-curly-newline] ( ./object-curly-newline.md ) | enforce consistent line breaks inside braces | :wrench : |
334
334
| [ vue/object-curly-spacing] ( ./object-curly-spacing.md ) | enforce consistent spacing inside braces | :wrench : |
335
335
| [ 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 : |
336
337
| [ vue/prefer-template] ( ./prefer-template.md ) | require template literals instead of string concatenation | :wrench : |
337
338
| [ vue/space-in-parens] ( ./space-in-parens.md ) | enforce consistent spacing inside parentheses | :wrench : |
338
339
| [ vue/space-infix-ops] ( ./space-infix-ops.md ) | require spacing around infix operators | :wrench : |
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ module.exports = {
33
33
'vue/object-curly-newline' : 'off' ,
34
34
'vue/object-curly-spacing' : 'off' ,
35
35
'vue/object-property-newline' : 'off' ,
36
+ 'vue/operator-linebreak' : 'off' ,
36
37
'vue/padding-line-between-blocks' : 'off' ,
37
38
'vue/script-indent' : 'off' ,
38
39
'vue/singleline-html-element-content-newline' : 'off' ,
Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ module.exports = {
108
108
'object-curly-spacing' : require ( './rules/object-curly-spacing' ) ,
109
109
'object-property-newline' : require ( './rules/object-property-newline' ) ,
110
110
'one-component-per-file' : require ( './rules/one-component-per-file' ) ,
111
+ 'operator-linebreak' : require ( './rules/operator-linebreak' ) ,
111
112
'order-in-components' : require ( './rules/order-in-components' ) ,
112
113
'padding-line-between-blocks' : require ( './rules/padding-line-between-blocks' ) ,
113
114
'prefer-template' : require ( './rules/prefer-template' ) ,
Original file line number Diff line number Diff line change
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' ) )
Original file line number Diff line number Diff line change
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
+ } )
You can’t perform that action at this time.
0 commit comments