diff --git a/lib/rules/no-empty-component-block.js b/lib/rules/no-empty-component-block.js index 4ba3b9143..d53be5eb7 100644 --- a/lib/rules/no-empty-component-block.js +++ b/lib/rules/no-empty-component-block.js @@ -11,6 +11,7 @@ // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ + /** * check whether has attribute `src` */ @@ -26,6 +27,17 @@ function hasAttributeSrc(componentBlock) { return hasAttribute && hasSrc } +/** + * check whether value under the component block is only whitespaces or break lines + */ +function isValueOnlyWhiteSpacesOrLineBreaks(componentBlock) { + return ( + componentBlock.children.length === 1 && + componentBlock.children[0].type === 'VText' && + /^(\s|\n)+$/.test(componentBlock.children[0].value) + ) +} + module.exports = { meta: { type: 'suggestion', @@ -67,7 +79,10 @@ module.exports = { // https://vue-loader.vuejs.org/spec.html#src-imports if (hasAttributeSrc(componentBlock)) return - if (componentBlock.children.length === 0) { + if ( + isValueOnlyWhiteSpacesOrLineBreaks(componentBlock) || + componentBlock.children.length === 0 + ) { context.report({ node: componentBlock, loc: componentBlock.loc, diff --git a/tests/lib/rules/no-empty-component-block.js b/tests/lib/rules/no-empty-component-block.js index bff931a1a..92813aa28 100644 --- a/tests/lib/rules/no-empty-component-block.js +++ b/tests/lib/rules/no-empty-component-block.js @@ -14,21 +14,36 @@ const tester = new RuleTester({ tester.run('no-empty-component-block', rule, { valid: [ ``, + ``, ``, ``, - ``, `