Skip to content

Commit 19963be

Browse files
committed
feat: autofix
1 parent 00c5f82 commit 19963be

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

lib/rules/no-empty-component-block.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,32 +105,22 @@ module.exports = {
105105

106106
if (emptyBlocks.length === 0) return
107107

108-
if (autofix) {
109-
const firstEmptyBlock = emptyBlocks[0]
108+
for (const componentBlock of emptyBlocks) {
110109
context.report({
111-
node: firstEmptyBlock,
112-
loc: firstEmptyBlock.loc,
110+
node: componentBlock,
111+
loc: componentBlock.loc,
113112
messageId: 'unexpected',
114113
data: {
115-
blockName: firstEmptyBlock.name
114+
blockName: componentBlock.name
116115
},
117-
*fix(fixer) {
118-
for (const componentBlock of emptyBlocks) {
119-
yield fixer.remove(componentBlock)
120-
}
121-
}
116+
fix: autofix
117+
? function* (fixer) {
118+
for (const componentBlock of emptyBlocks) {
119+
yield fixer.remove(componentBlock)
120+
}
121+
}
122+
: undefined
122123
})
123-
} else {
124-
for (const componentBlock of emptyBlocks) {
125-
context.report({
126-
node: componentBlock,
127-
loc: componentBlock.loc,
128-
messageId: 'unexpected',
129-
data: {
130-
blockName: componentBlock.name
131-
}
132-
})
133-
}
134124
}
135125
}
136126
}

tests/lib/rules/no-empty-component-block.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,42 +169,63 @@ tester.run('no-empty-component-block', rule, {
169169
]
170170
},
171171
{
172-
code: '<template></template><script></script><style></style>',
173-
output: '',
172+
code: '<template></template> <script></script> <style></style>',
173+
output: ' ',
174174
options: [{ autofix: true }],
175175
errors: [
176176
{
177177
message: '`<template>` is empty. Empty block is not allowed.'
178+
},
179+
{
180+
message: '`<script>` is empty. Empty block is not allowed.'
181+
},
182+
{
183+
message: '`<style>` is empty. Empty block is not allowed.'
178184
}
179185
]
180186
},
181187
{
182-
code: '<template /><script /><style />',
183-
output: '',
188+
code: '<template /> <script /> <style />',
189+
output: ' ',
184190
options: [{ autofix: true }],
185191
errors: [
186192
{
187193
message: '`<template>` is empty. Empty block is not allowed.'
194+
},
195+
{
196+
message: '`<script>` is empty. Empty block is not allowed.'
197+
},
198+
{
199+
message: '`<style>` is empty. Empty block is not allowed.'
188200
}
189201
]
190202
},
191203
{
192-
code: '<template src="" /><script src="" /><style src="" />',
193-
output: '',
204+
code: '<template src="" /> <script src="" /> <style src="" />',
205+
output: ' ',
194206
options: [{ autofix: true }],
195207
errors: [
196208
{
197209
message: '`<template>` is empty. Empty block is not allowed.'
210+
},
211+
{
212+
message: '`<script>` is empty. Empty block is not allowed.'
213+
},
214+
{
215+
message: '`<style>` is empty. Empty block is not allowed.'
198216
}
199217
]
200218
},
201219
{
202-
code: '<template><p></p></template><script src="" /><style src="" />',
203-
output: '<template><p></p></template>',
220+
code: '<template><p></p></template> <script src="" /> <style src="" />',
221+
output: '<template><p></p></template> ',
204222
options: [{ autofix: true }],
205223
errors: [
206224
{
207225
message: '`<script>` is empty. Empty block is not allowed.'
226+
},
227+
{
228+
message: '`<style>` is empty. Empty block is not allowed.'
208229
}
209230
]
210231
}

0 commit comments

Comments
 (0)