File tree Expand file tree Collapse file tree 6 files changed +188
-0
lines changed Expand file tree Collapse file tree 6 files changed +188
-0
lines changed Original file line number Diff line number Diff line change @@ -330,6 +330,7 @@ The following rules extend the rules provided by ESLint itself and apply them to
330330| [ vue/no-irregular-whitespace] ( ./no-irregular-whitespace.md ) | disallow irregular whitespace | |
331331| [ vue/no-restricted-syntax] ( ./no-restricted-syntax.md ) | disallow specified syntax | |
332332| [ vue/no-useless-concat] ( ./no-useless-concat.md ) | disallow unnecessary concatenation of literals or template literals | |
333+ | [ vue/object-curly-newline] ( ./object-curly-newline.md ) | enforce consistent line breaks inside braces | :wrench : |
333334| [ vue/object-curly-spacing] ( ./object-curly-spacing.md ) | enforce consistent spacing inside braces | :wrench : |
334335| [ vue/object-property-newline] ( ./object-property-newline.md ) | enforce placing object properties on separate lines | :wrench : |
335336| [ vue/prefer-template] ( ./prefer-template.md ) | require template literals instead of string concatenation | :wrench : |
Original file line number Diff line number Diff line change 1+ ---
2+ pageClass : rule-details
3+ sidebarDepth : 0
4+ title : vue/object-curly-newline
5+ description : enforce consistent line breaks inside braces
6+ ---
7+ # vue/object-curly-newline
8+ > enforce consistent line breaks inside braces
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 [ object-curly-newline] rule but it applies to the expressions in ` <template> ` .
13+
14+ ## :books : Further reading
15+
16+ - [ object-curly-newline]
17+
18+ [ object-curly-newline ] : https://eslint.org/docs/rules/object-curly-newline
19+
20+ ## :mag : Implementation
21+
22+ - [ Rule source] ( https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/object-curly-newline.js )
23+ - [ Test source] ( https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/object-curly-newline.js )
24+
25+ <sup >Taken with ❤️ [ from ESLint core] ( https://eslint.org/docs/rules/object-curly-newline ) </sup >
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ module.exports = {
3030 'vue/no-extra-parens' : 'off' ,
3131 'vue/no-multi-spaces' : 'off' ,
3232 'vue/no-spaces-around-equal-signs-in-attribute' : 'off' ,
33+ 'vue/object-curly-newline' : 'off' ,
3334 'vue/object-curly-spacing' : 'off' ,
3435 'vue/object-property-newline' : 'off' ,
3536 'vue/padding-line-between-blocks' : 'off' ,
Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ module.exports = {
104104 'no-v-html' : require ( './rules/no-v-html' ) ,
105105 'no-v-model-argument' : require ( './rules/no-v-model-argument' ) ,
106106 'no-watch-after-await' : require ( './rules/no-watch-after-await' ) ,
107+ 'object-curly-newline' : require ( './rules/object-curly-newline' ) ,
107108 'object-curly-spacing' : require ( './rules/object-curly-spacing' ) ,
108109 'object-property-newline' : require ( './rules/object-property-newline' ) ,
109110 'one-component-per-file' : require ( './rules/one-component-per-file' ) ,
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 (
10+ require ( 'eslint/lib/rules/object-curly-newline' ) ,
11+ { skipDynamicArguments : true }
12+ )
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/object-curly-newline' )
8+
9+ const tester = new RuleTester ( {
10+ parser : require . resolve ( 'vue-eslint-parser' ) ,
11+ parserOptions : { ecmaVersion : 2020 }
12+ } )
13+
14+ tester . run ( 'object-curly-newline' , rule , {
15+ valid : [
16+ `
17+ <template>
18+ <div :foo="{a: 1}" />
19+ </template>
20+ ` ,
21+ {
22+ code : `
23+ <template>
24+ <div :foo="{a: 1}" />
25+ </template>
26+ ` ,
27+ options : [ 'never' ]
28+ } ,
29+ `
30+ <template>
31+ <div :foo="{
32+ a: 1
33+ }" />
34+ </template>
35+ ` ,
36+ {
37+ code : `
38+ <template>
39+ <div :foo="{
40+ a: 1
41+ }" />
42+ </template>
43+ ` ,
44+ options : [ 'always' ]
45+ } ,
46+ `
47+ <template>
48+ <div :[{a:1}]="value" />
49+ </template>
50+ ` ,
51+ {
52+ code : `
53+ <template>
54+ <div :[{a:1}]="value" />
55+ </template>
56+ ` ,
57+ options : [ 'always' ]
58+ } ,
59+ {
60+ code : `
61+ <template>
62+ <div :[{a:1}]="value" />
63+ </template>
64+ ` ,
65+ options : [ 'never' ]
66+ }
67+ ] ,
68+ invalid : [
69+ {
70+ code : `
71+ <template>
72+ <div :foo="{a: 1
73+ }" />
74+ </template>
75+ ` ,
76+ output : `
77+ <template>
78+ <div :foo="{a: 1}" />
79+ </template>
80+ ` ,
81+ errors : [
82+ {
83+ message : 'Unexpected line break before this closing brace.' ,
84+ line : 4 ,
85+ column : 9
86+ }
87+ ]
88+ } ,
89+ {
90+ code : `
91+ <template>
92+ <div :foo="{
93+ a: 1}" />
94+ </template>
95+ ` ,
96+ output : `
97+ <template>
98+ <div :foo="{a: 1}" />
99+ </template>
100+ ` ,
101+ errors : [
102+ {
103+ message : 'Unexpected line break after this opening brace.' ,
104+ line : 3 ,
105+ column : 20
106+ }
107+ ]
108+ } ,
109+ {
110+ code : `
111+ <template>
112+ <div :foo="{a: 1}" />
113+ </template>
114+ ` ,
115+ output : `
116+ <template>
117+ <div :foo="{
118+ a: 1
119+ }" />
120+ </template>
121+ ` ,
122+ options : [ 'always' ] ,
123+ errors : [
124+ 'Expected a line break after this opening brace.' ,
125+ 'Expected a line break before this closing brace.'
126+ ]
127+ } ,
128+ {
129+ code : `
130+ <template>
131+ <div :foo="{
132+ a: 1
133+ }" />
134+ </template>
135+ ` ,
136+ output : `
137+ <template>
138+ <div :foo="{a: 1}" />
139+ </template>
140+ ` ,
141+ options : [ 'never' ] ,
142+ errors : [
143+ 'Unexpected line break after this opening brace.' ,
144+ 'Unexpected line break before this closing brace.'
145+ ]
146+ }
147+ ]
148+ } )
You can’t perform that action at this time.
0 commit comments