|
| 1 | +const eslint = require('eslint'); |
| 2 | +const rule = require('../../../lib/rules/template-no-whitespace-within-word'); |
| 3 | + |
| 4 | +const { RuleTester } = eslint; |
| 5 | + |
| 6 | +const ruleTester = new RuleTester({ |
| 7 | + parser: require.resolve('ember-eslint-parser'), |
| 8 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 9 | +}); |
| 10 | + |
| 11 | +ruleTester.run('template-no-whitespace-within-word', rule, { |
| 12 | + valid: [ |
| 13 | + // No whitespace |
| 14 | + '<template>{{value}}</template>', |
| 15 | + '<template>{{this.property}}</template>', |
| 16 | + '<template>{{@arg}}</template>', |
| 17 | + '<template>{{#if condition}}content{{/if}}</template>', |
| 18 | + |
| 19 | + '<template>Welcome</template>', |
| 20 | + '<template>Hey - I like this!</template>', |
| 21 | + '<template>Expected: 5-10 guests</template>', |
| 22 | + '<template>Expected: 5 - 10 guests</template>', |
| 23 | + '<template>It is possible to get some examples of in-word emph a sis past this rule.</template>', |
| 24 | + '<template>However, I do not want a rule that flags annoying false positives for correctly-used single-character words.</template>', |
| 25 | + '<template><div>Welcome</div></template>', |
| 26 | + '<template><div enable-background="a b c d e f g h i j k l m">We want to ignore values of HTML attributes</div></template>', |
| 27 | + `<template><style> |
| 28 | + .my-custom-class > * { |
| 29 | + border: 2px dotted red; |
| 30 | + } |
| 31 | +</style></template>`, |
| 32 | + ], |
| 33 | + invalid: [ |
| 34 | + { |
| 35 | + code: '<template><div>W e l c o m e</div></template>', |
| 36 | + output: null, |
| 37 | + errors: [{ messageId: 'excessWhitespace' }], |
| 38 | + }, |
| 39 | + { |
| 40 | + code: '<template><span>H e l l o</span></template>', |
| 41 | + output: null, |
| 42 | + errors: [{ messageId: 'excessWhitespace' }], |
| 43 | + }, |
| 44 | + { |
| 45 | + code: '<template><p>C l i c k</p></template>', |
| 46 | + output: null, |
| 47 | + errors: [{ messageId: 'excessWhitespace' }], |
| 48 | + }, |
| 49 | + |
| 50 | + { |
| 51 | + code: '<template>W e l c o m e</template>', |
| 52 | + output: null, |
| 53 | + errors: [{ messageId: 'excessWhitespace' }], |
| 54 | + }, |
| 55 | + { |
| 56 | + code: '<template>W e l c o m e</template>', |
| 57 | + output: null, |
| 58 | + errors: [{ messageId: 'excessWhitespace' }], |
| 59 | + }, |
| 60 | + { |
| 61 | + code: '<template>Wel c o me</template>', |
| 62 | + output: null, |
| 63 | + errors: [{ messageId: 'excessWhitespace' }], |
| 64 | + }, |
| 65 | + { |
| 66 | + code: '<template>Wel c o me</template>', |
| 67 | + output: null, |
| 68 | + errors: [{ messageId: 'excessWhitespace' }], |
| 69 | + }, |
| 70 | + { |
| 71 | + code: '<template><div>Wel c o me</div></template>', |
| 72 | + output: null, |
| 73 | + errors: [{ messageId: 'excessWhitespace' }], |
| 74 | + }, |
| 75 | + { |
| 76 | + code: '<template>A B C </template>', |
| 77 | + output: null, |
| 78 | + errors: [{ messageId: 'excessWhitespace' }], |
| 79 | + }, |
| 80 | + ], |
| 81 | +}); |
| 82 | + |
| 83 | +const hbsRuleTester = new RuleTester({ |
| 84 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 85 | + parserOptions: { |
| 86 | + ecmaVersion: 2022, |
| 87 | + sourceType: 'module', |
| 88 | + }, |
| 89 | +}); |
| 90 | + |
| 91 | +hbsRuleTester.run('template-no-whitespace-within-word', rule, { |
| 92 | + valid: [ |
| 93 | + 'Welcome', |
| 94 | + 'Hey - I like this!', |
| 95 | + 'Expected: 5-10 guests', |
| 96 | + 'Expected: 5 - 10 guests', |
| 97 | + 'It is possible to get some examples of in-word emph a sis past this rule.', |
| 98 | + 'However, I do not want a rule that flags annoying false positives for correctly-used single-character words.', |
| 99 | + '<div>Welcome</div>', |
| 100 | + '<div enable-background="a b c d e f g h i j k l m">We want to ignore values of HTML attributes</div>', |
| 101 | + `<style> |
| 102 | + .my-custom-class > * { |
| 103 | + border: 2px dotted red; |
| 104 | + } |
| 105 | +</style>`, |
| 106 | + ], |
| 107 | + invalid: [ |
| 108 | + { |
| 109 | + code: 'W e l c o m e', |
| 110 | + output: null, |
| 111 | + errors: [{ message: 'Excess whitespace in layout detected.' }], |
| 112 | + }, |
| 113 | + { |
| 114 | + code: 'W e l c o m e', |
| 115 | + output: null, |
| 116 | + errors: [{ message: 'Excess whitespace in layout detected.' }], |
| 117 | + }, |
| 118 | + { |
| 119 | + code: 'Wel c o me', |
| 120 | + output: null, |
| 121 | + errors: [{ message: 'Excess whitespace in layout detected.' }], |
| 122 | + }, |
| 123 | + { |
| 124 | + code: 'Wel c o me', |
| 125 | + output: null, |
| 126 | + errors: [{ message: 'Excess whitespace in layout detected.' }], |
| 127 | + }, |
| 128 | + { |
| 129 | + code: '<div>W e l c o m e</div>', |
| 130 | + output: null, |
| 131 | + errors: [{ message: 'Excess whitespace in layout detected.' }], |
| 132 | + }, |
| 133 | + { |
| 134 | + code: '<div>Wel c o me</div>', |
| 135 | + output: null, |
| 136 | + errors: [{ message: 'Excess whitespace in layout detected.' }], |
| 137 | + }, |
| 138 | + { |
| 139 | + code: 'A B C ', |
| 140 | + output: null, |
| 141 | + errors: [{ message: 'Excess whitespace in layout detected.' }], |
| 142 | + }, |
| 143 | + ], |
| 144 | +}); |
0 commit comments