|
| 1 | +/** |
| 2 | + * @author tyankatsu <https://github.com/tyankatsu0105> |
| 3 | + */ |
| 4 | +'use strict' |
| 5 | + |
| 6 | +const RuleTester = require('eslint').RuleTester |
| 7 | +const rule = require('../../../lib/rules/no-empty-component-block') |
| 8 | + |
| 9 | +const tester = new RuleTester({ |
| 10 | + parser: require.resolve('vue-eslint-parser'), |
| 11 | + parserOptions: { ecmaVersion: 2018 } |
| 12 | +}) |
| 13 | + |
| 14 | +tester.run('no-empty-component-block', rule, { |
| 15 | + valid: [ |
| 16 | + `<template><p>foo</p></template>`, |
| 17 | + `<template> foobar </template>`, |
| 18 | + `<template><p>foo</p></template><script>console.log('foo')</script>`, |
| 19 | + `<template><p>foo</p></template><script>console.log('foo')</script><style>p{display: inline;}</style>`, |
| 20 | + `<template src="./template.html"></template>`, |
| 21 | + `<template src="./template.html" />`, |
| 22 | + `<template src="./template.html"></template><script src="./script.js"></script>`, |
| 23 | + `<template src="./template.html" /><script src="./script.js" />`, |
| 24 | + `<template src="./template.html"></template><script src="./script.js"></script><style src="./style.css"></style>`, |
| 25 | + `<template src="./template.html" /><script src="./script.js" /><style src="./style.css" />` |
| 26 | + ], |
| 27 | + invalid: [ |
| 28 | + { |
| 29 | + code: `<template></template>`, |
| 30 | + errors: [ |
| 31 | + { |
| 32 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 33 | + } |
| 34 | + ] |
| 35 | + }, |
| 36 | + { |
| 37 | + code: `<template> </template>`, |
| 38 | + errors: [ |
| 39 | + { |
| 40 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 41 | + } |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + code: `<template> |
| 46 | +</template>`, |
| 47 | + errors: [ |
| 48 | + { |
| 49 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 50 | + } |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + code: '<template />', |
| 55 | + errors: [ |
| 56 | + { |
| 57 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 58 | + } |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + code: '<template src="" />', |
| 63 | + errors: [ |
| 64 | + { |
| 65 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 66 | + } |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + code: '<template></template><script></script>', |
| 71 | + errors: [ |
| 72 | + { |
| 73 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 74 | + }, |
| 75 | + { |
| 76 | + message: '`<script>` is empty. Empty block is not allowed.' |
| 77 | + } |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + code: '<template /><script />', |
| 82 | + errors: [ |
| 83 | + { |
| 84 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 85 | + }, |
| 86 | + { |
| 87 | + message: '`<script>` is empty. Empty block is not allowed.' |
| 88 | + } |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + code: '<template src="" /><script src="" />', |
| 93 | + errors: [ |
| 94 | + { |
| 95 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 96 | + }, |
| 97 | + { |
| 98 | + message: '`<script>` is empty. Empty block is not allowed.' |
| 99 | + } |
| 100 | + ] |
| 101 | + }, |
| 102 | + { |
| 103 | + code: '<template></template><script></script><style></style>', |
| 104 | + errors: [ |
| 105 | + { |
| 106 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 107 | + }, |
| 108 | + { |
| 109 | + message: '`<script>` is empty. Empty block is not allowed.' |
| 110 | + }, |
| 111 | + { |
| 112 | + message: '`<style>` is empty. Empty block is not allowed.' |
| 113 | + } |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + code: '<template /><script /><style />', |
| 118 | + errors: [ |
| 119 | + { |
| 120 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 121 | + }, |
| 122 | + { |
| 123 | + message: '`<script>` is empty. Empty block is not allowed.' |
| 124 | + }, |
| 125 | + { |
| 126 | + message: '`<style>` is empty. Empty block is not allowed.' |
| 127 | + } |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + code: '<template src="" /><script src="" /><style src="" />', |
| 132 | + errors: [ |
| 133 | + { |
| 134 | + message: '`<template>` is empty. Empty block is not allowed.' |
| 135 | + }, |
| 136 | + { |
| 137 | + message: '`<script>` is empty. Empty block is not allowed.' |
| 138 | + }, |
| 139 | + { |
| 140 | + message: '`<style>` is empty. Empty block is not allowed.' |
| 141 | + } |
| 142 | + ] |
| 143 | + } |
| 144 | + ] |
| 145 | +}) |
0 commit comments