|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// Requirements |
| 3 | +//------------------------------------------------------------------------------ |
| 4 | + |
| 5 | +const rule = require('../../../lib/rules/template-no-multiple-empty-lines'); |
| 6 | +const RuleTester = require('eslint').RuleTester; |
| 7 | + |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | +// Tests |
| 10 | +//------------------------------------------------------------------------------ |
| 11 | + |
| 12 | +const ruleTester = new RuleTester({ |
| 13 | + parser: require.resolve('ember-eslint-parser'), |
| 14 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 15 | +}); |
| 16 | + |
| 17 | +ruleTester.run('template-no-multiple-empty-lines', rule, { |
| 18 | + valid: [ |
| 19 | + `<template> |
| 20 | + <div>Hello</div> |
| 21 | +
|
| 22 | + <div>World</div> |
| 23 | + </template>`, |
| 24 | + { |
| 25 | + code: `<template> |
| 26 | + <div>Hello</div> |
| 27 | +
|
| 28 | +
|
| 29 | + <div>World</div> |
| 30 | + </template>`, |
| 31 | + options: [{ max: 2 }], |
| 32 | + }, |
| 33 | + `<template> |
| 34 | + <div>Content</div> |
| 35 | + </template>`, |
| 36 | + |
| 37 | + '<template><div>foo</div><div>bar</div></template>', |
| 38 | + `<template><div>foo</div> |
| 39 | +<div>bar</div></template>`, |
| 40 | + `<template><div>foo</div>r |
| 41 | +<div>bar</div></template>`, |
| 42 | + `<template><div>foo</div> |
| 43 | +
|
| 44 | +<div>bar</div></template>`, |
| 45 | + `<template><div>foo</div>r |
| 46 | +r |
| 47 | +<div>bar</div></template>`, |
| 48 | + `<template> |
| 49 | +<div>foo</div> |
| 50 | +
|
| 51 | +<div>bar</div> |
| 52 | +</template>`, |
| 53 | + ], |
| 54 | + |
| 55 | + invalid: [ |
| 56 | + { |
| 57 | + code: `<template> |
| 58 | + <div>Hello</div> |
| 59 | +
|
| 60 | +
|
| 61 | + <div>World</div> |
| 62 | + </template>`, |
| 63 | + output: null, |
| 64 | + errors: [ |
| 65 | + { |
| 66 | + message: 'More than 1 blank line not allowed.', |
| 67 | + }, |
| 68 | + ], |
| 69 | + }, |
| 70 | + { |
| 71 | + code: `<template> |
| 72 | + <div>First</div> |
| 73 | +
|
| 74 | +
|
| 75 | +
|
| 76 | + <div>Second</div> |
| 77 | + </template>`, |
| 78 | + output: null, |
| 79 | + errors: [ |
| 80 | + { |
| 81 | + message: 'More than 1 blank line not allowed.', |
| 82 | + }, |
| 83 | + ], |
| 84 | + }, |
| 85 | + |
| 86 | + { |
| 87 | + code: `<template><div>foo</div> |
| 88 | +
|
| 89 | +
|
| 90 | +<div>bar</div></template>`, |
| 91 | + output: null, |
| 92 | + errors: [{ message: 'More than 1 blank line not allowed.' }], |
| 93 | + }, |
| 94 | + { |
| 95 | + code: `<template><div>foo</div> |
| 96 | +
|
| 97 | +
|
| 98 | +
|
| 99 | +
|
| 100 | +<div>bar</div></template>`, |
| 101 | + output: null, |
| 102 | + errors: [{ message: 'More than 1 blank line not allowed.' }], |
| 103 | + }, |
| 104 | + ], |
| 105 | +}); |
| 106 | + |
| 107 | +const hbsRuleTester = new RuleTester({ |
| 108 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 109 | + parserOptions: { |
| 110 | + ecmaVersion: 2022, |
| 111 | + sourceType: 'module', |
| 112 | + }, |
| 113 | +}); |
| 114 | + |
| 115 | +hbsRuleTester.run('template-no-multiple-empty-lines', rule, { |
| 116 | + valid: [ |
| 117 | + '<div>foo</div><div>bar</div>', |
| 118 | + `<div>foo</div> |
| 119 | +<div>bar</div>`, |
| 120 | + `<div>foo</div> |
| 121 | +
|
| 122 | +<div>bar</div>`, |
| 123 | + ` |
| 124 | +<div>foo</div> |
| 125 | +
|
| 126 | +<div>bar</div> |
| 127 | +`, |
| 128 | + '<div>foo</div>\r\n<div>bar</div>', |
| 129 | + '<div>foo</div>\r\n\r\n<div>bar</div>', |
| 130 | + { |
| 131 | + code: '<div>foo</div>\n\n\n<div>bar</div>', |
| 132 | + options: [{ max: 2 }], |
| 133 | + }, |
| 134 | + { |
| 135 | + code: '<div>foo</div>\r\n\r\n\r\n<div>bar</div>', |
| 136 | + options: [{ max: 2 }], |
| 137 | + }, |
| 138 | + ], |
| 139 | + invalid: [ |
| 140 | + { |
| 141 | + code: `<div>foo</div> |
| 142 | +
|
| 143 | +
|
| 144 | +<div>bar</div>`, |
| 145 | + output: null, |
| 146 | + errors: [{ message: 'More than 1 blank line not allowed.' }], |
| 147 | + }, |
| 148 | + { |
| 149 | + code: `<div>foo</div> |
| 150 | +
|
| 151 | +
|
| 152 | +
|
| 153 | +
|
| 154 | +<div>bar</div>`, |
| 155 | + output: null, |
| 156 | + errors: [{ message: 'More than 1 blank line not allowed.' }], |
| 157 | + }, |
| 158 | + { |
| 159 | + code: '<div>foo</div>\n\n\n\n\n<div>bar</div>', |
| 160 | + output: null, |
| 161 | + options: [{ max: 3 }], |
| 162 | + errors: [{ message: 'More than 3 blank lines not allowed.' }], |
| 163 | + }, |
| 164 | + ], |
| 165 | +}); |
0 commit comments