File tree Expand file tree Collapse file tree 6 files changed +177
-0
lines changed Expand file tree Collapse file tree 6 files changed +177
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,7 @@ For example:
149
149
| [ vue/dot-location] ( ./dot-location.md ) | enforce consistent newlines before and after dots | :wrench : |
150
150
| [ vue/eqeqeq] ( ./eqeqeq.md ) | require the use of ` === ` and ` !== ` | :wrench : |
151
151
| [ vue/key-spacing] ( ./key-spacing.md ) | enforce consistent spacing between keys and values in object literal properties | :wrench : |
152
+ | [ vue/keyword-spacing] ( ./keyword-spacing.md ) | enforce consistent spacing before and after keywords | :wrench : |
152
153
| [ vue/match-component-file-name] ( ./match-component-file-name.md ) | require component name property to match its file name | |
153
154
| [ vue/no-boolean-default] ( ./no-boolean-default.md ) | disallow boolean defaults | :wrench : |
154
155
| [ vue/no-empty-pattern] ( ./no-empty-pattern.md ) | disallow empty destructuring patterns | |
Original file line number Diff line number Diff line change
1
+ ---
2
+ pageClass : rule-details
3
+ sidebarDepth : 0
4
+ title : vue/keyword-spacing
5
+ description : enforce consistent spacing before and after keywords
6
+ ---
7
+ # vue/keyword-spacing
8
+ > enforce consistent spacing before and after keywords
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 [ keyword-spacing] rule but it applies to the expressions in ` <template> ` .
13
+
14
+ ## :books : Further reading
15
+
16
+ - [ keyword-spacing]
17
+
18
+ [ keyword-spacing ] : https://eslint.org/docs/rules/keyword-spacing
19
+
20
+ ## :mag : Implementation
21
+
22
+ - [ Rule source] ( https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/keyword-spacing.js )
23
+ - [ Test source] ( https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/keyword-spacing.js )
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ module.exports = {
17
17
'vue/html-quotes' : 'off' ,
18
18
'vue/html-self-closing' : 'off' ,
19
19
'vue/key-spacing' : 'off' ,
20
+ 'vue/keyword-spacing' : 'off' ,
20
21
'vue/max-attributes-per-line' : 'off' ,
21
22
'vue/multiline-html-element-content-newline' : 'off' ,
22
23
'vue/mustache-interpolation-spacing' : 'off' ,
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ module.exports = {
27
27
'html-self-closing' : require ( './rules/html-self-closing' ) ,
28
28
'jsx-uses-vars' : require ( './rules/jsx-uses-vars' ) ,
29
29
'key-spacing' : require ( './rules/key-spacing' ) ,
30
+ 'keyword-spacing' : require ( './rules/keyword-spacing' ) ,
30
31
'match-component-file-name' : require ( './rules/match-component-file-name' ) ,
31
32
'max-attributes-per-line' : require ( './rules/max-attributes-per-line' ) ,
32
33
'multiline-html-element-content-newline' : require ( './rules/multiline-html-element-content-newline' ) ,
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/keyword-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/keyword-spacing' )
8
+
9
+ const tester = new RuleTester ( {
10
+ parser : 'vue-eslint-parser' ,
11
+ parserOptions : { ecmaVersion : 2015 }
12
+ } )
13
+
14
+ tester . run ( 'keyword-spacing' , rule , {
15
+ valid : [
16
+ `<template>
17
+ <div @event="
18
+ if (foo) {
19
+ //...
20
+ } else if (bar) {
21
+ //...
22
+ } else {
23
+ //...
24
+ }
25
+ " />
26
+ </template>` ,
27
+ {
28
+ code :
29
+ `<template>
30
+ <div @event="
31
+ if(foo) {
32
+ //...
33
+ }else if(bar) {
34
+ //...
35
+ }else{
36
+ //...
37
+ }
38
+ " />
39
+ </template>` ,
40
+ options : [ { before : false , after : false } ]
41
+ }
42
+ ] ,
43
+ invalid : [
44
+ {
45
+ code :
46
+ `<template>
47
+ <div @event="
48
+ if(foo) {
49
+ //...
50
+ }else if(bar) {
51
+ //...
52
+ }else{
53
+ //...
54
+ }
55
+ " />
56
+ </template>` ,
57
+ output :
58
+ `<template>
59
+ <div @event="
60
+ if (foo) {
61
+ //...
62
+ } else if (bar) {
63
+ //...
64
+ } else {
65
+ //...
66
+ }
67
+ " />
68
+ </template>` ,
69
+ errors : [
70
+ {
71
+ message : 'Expected space(s) after "if".' ,
72
+ line : 3
73
+ } ,
74
+ {
75
+ message : 'Expected space(s) before "else".' ,
76
+ line : 5
77
+ } ,
78
+ {
79
+ message : 'Expected space(s) after "if".' ,
80
+ line : 5
81
+ } ,
82
+ {
83
+ message : 'Expected space(s) before "else".' ,
84
+ line : 7
85
+ } ,
86
+ {
87
+ message : 'Expected space(s) after "else".' ,
88
+ line : 7
89
+ }
90
+ ]
91
+ } ,
92
+ {
93
+ code :
94
+ `<template>
95
+ <div @event="
96
+ if (foo) {
97
+ //...
98
+ } else if (bar) {
99
+ //...
100
+ } else {
101
+ //...
102
+ }
103
+ " />
104
+ </template>` ,
105
+ options : [ { before : false , after : false } ] ,
106
+ output :
107
+ `<template>
108
+ <div @event="
109
+ if(foo) {
110
+ //...
111
+ }else if(bar) {
112
+ //...
113
+ }else{
114
+ //...
115
+ }
116
+ " />
117
+ </template>` ,
118
+ errors : [
119
+ {
120
+ message : 'Unexpected space(s) after "if".' ,
121
+ line : 3
122
+ } ,
123
+ {
124
+ message : 'Unexpected space(s) before "else".' ,
125
+ line : 5
126
+ } ,
127
+ {
128
+ message : 'Unexpected space(s) after "if".' ,
129
+ line : 5
130
+ } ,
131
+ {
132
+ message : 'Unexpected space(s) before "else".' ,
133
+ line : 7
134
+ } ,
135
+ {
136
+ message : 'Unexpected space(s) after "else".' ,
137
+ line : 7
138
+ }
139
+ ]
140
+ }
141
+ ]
142
+ } )
You can’t perform that action at this time.
0 commit comments