File tree Expand file tree Collapse file tree 6 files changed +150
-0
lines changed Expand file tree Collapse file tree 6 files changed +150
-0
lines changed Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ For example:
140
140
| Rule ID | Description | |
141
141
| :--------| :------------| :---|
142
142
| [ vue/array-bracket-spacing] ( ./array-bracket-spacing.md ) | enforce consistent spacing inside array brackets | :wrench : |
143
+ | [ vue/block-spacing] ( ./block-spacing.md ) | disallow or enforce spaces inside of blocks after opening block and before closing block | :wrench : |
143
144
| [ vue/component-name-in-template-casing] ( ./component-name-in-template-casing.md ) | enforce specific casing for the component naming style in template | :wrench : |
144
145
| [ vue/eqeqeq] ( ./eqeqeq.md ) | require the use of ` === ` and ` !== ` | :wrench : |
145
146
| [ vue/key-spacing] ( ./key-spacing.md ) | enforce consistent spacing between keys and values in object literal properties | :wrench : |
Original file line number Diff line number Diff line change
1
+ ---
2
+ pageClass : rule-details
3
+ sidebarDepth : 0
4
+ title : vue/block-spacing
5
+ description : disallow or enforce spaces inside of blocks after opening block and before closing block
6
+ ---
7
+ # vue/block-spacing
8
+ > disallow or enforce spaces inside of blocks after opening block and before closing block
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 [ block-spacing] rule but it applies to the expressions in ` <template> ` .
13
+
14
+ ## :books : Further reading
15
+
16
+ - [ block-spacing]
17
+
18
+ [ block-spacing ] : https://eslint.org/docs/rules/block-spacing
19
+
20
+ ## :mag : Implementation
21
+
22
+ - [ Rule source] ( https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/block-spacing.js )
23
+ - [ Test source] ( https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/block-spacing.js )
Original file line number Diff line number Diff line change 6
6
module . exports = {
7
7
rules : {
8
8
'vue/array-bracket-spacing' : 'off' ,
9
+ 'vue/block-spacing' : 'off' ,
9
10
'vue/html-closing-bracket-newline' : 'off' ,
10
11
'vue/html-closing-bracket-spacing' : 'off' ,
11
12
'vue/html-indent' : 'off' ,
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ module.exports = {
10
10
'array-bracket-spacing' : require ( './rules/array-bracket-spacing' ) ,
11
11
'attribute-hyphenation' : require ( './rules/attribute-hyphenation' ) ,
12
12
'attributes-order' : require ( './rules/attributes-order' ) ,
13
+ 'block-spacing' : require ( './rules/block-spacing' ) ,
13
14
'comment-directive' : require ( './rules/comment-directive' ) ,
14
15
'component-name-in-template-casing' : require ( './rules/component-name-in-template-casing' ) ,
15
16
'eqeqeq' : require ( './rules/eqeqeq' ) ,
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
9
+ module . exports = wrapCoreRule ( require ( 'eslint/lib/rules/block-spacing' ) )
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/block-spacing' )
8
+
9
+ const tester = new RuleTester ( {
10
+ parser : 'vue-eslint-parser' ,
11
+ parserOptions : { ecmaVersion : 2015 }
12
+ } )
13
+
14
+ tester . run ( 'block-spacing' , rule , {
15
+ valid : [
16
+ '<template><div :attr="function foo() { return true; }" /></template>' ,
17
+ {
18
+ code : '<template><div :attr="function foo() {return true;}" /></template>' ,
19
+ options : [ 'never' ]
20
+ }
21
+ ] ,
22
+ invalid : [
23
+ {
24
+ code : `
25
+ <template>
26
+ <div :attr="function foo() {return true;}" />
27
+ </template>` ,
28
+ output : `
29
+ <template>
30
+ <div :attr="function foo() { return true; }" />
31
+ </template>` ,
32
+ errors : [
33
+ {
34
+ messageId : 'missing' ,
35
+ data : {
36
+ location : 'after' ,
37
+ token : '{'
38
+ } ,
39
+ // message: 'Requires a space after \'{\'',
40
+ line : 3
41
+ } ,
42
+ {
43
+ messageId : 'missing' ,
44
+ data : {
45
+ location : 'before' ,
46
+ token : '}'
47
+ } ,
48
+ // message: 'Requires a space before \' }\'',
49
+ line : 3
50
+ }
51
+ ]
52
+ } ,
53
+ {
54
+ code : `
55
+ <template>
56
+ <button @click="() => {return true;}" />
57
+ </template>` ,
58
+ output : `
59
+ <template>
60
+ <button @click="() => { return true; }" />
61
+ </template>` ,
62
+ errors : [
63
+ {
64
+ messageId : 'missing' ,
65
+ data : {
66
+ location : 'after' ,
67
+ token : '{'
68
+ } ,
69
+ // message: 'Requires a space after \'{\'',
70
+ line : 3
71
+ } ,
72
+ {
73
+ messageId : 'missing' ,
74
+ data : {
75
+ location : 'before' ,
76
+ token : '}'
77
+ } ,
78
+ // message: 'Requires a space before \' }\'',
79
+ line : 3
80
+ }
81
+ ]
82
+ } ,
83
+ {
84
+ code : `
85
+ <template>
86
+ <div :attr="function foo() { return true; }" />
87
+ </template>` ,
88
+ options : [ 'never' ] ,
89
+ output : `
90
+ <template>
91
+ <div :attr="function foo() {return true;}" />
92
+ </template>` ,
93
+ errors : [
94
+ {
95
+ messageId : 'extra' ,
96
+ data : {
97
+ location : 'after' ,
98
+ token : '{'
99
+ } ,
100
+ // message: 'Unexpected space(s) after \'{\'',
101
+ line : 3
102
+ } ,
103
+ {
104
+ messageId : 'extra' ,
105
+ data : {
106
+ location : 'before' ,
107
+ token : '}'
108
+ } ,
109
+ // message: 'Unexpected space(s) before \' }\'',
110
+ line : 3
111
+ }
112
+ ]
113
+ }
114
+ ]
115
+ } )
You can’t perform that action at this time.
0 commit comments