|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// Requirements |
| 3 | +//------------------------------------------------------------------------------ |
| 4 | + |
| 5 | +const rule = require('../../../lib/rules/template-no-whitespace-for-layout'); |
| 6 | +const RuleTester = require('eslint').RuleTester; |
| 7 | + |
| 8 | +const validHbs = [ |
| 9 | + 'Start to finish', |
| 10 | + 'Start to finish', |
| 11 | + 'Start<br>to<br>finish', |
| 12 | + `<div> |
| 13 | + example |
| 14 | +</div>`, |
| 15 | + `<div |
| 16 | + foo="bar" |
| 17 | + baz="qux" |
| 18 | +> |
| 19 | + example |
| 20 | +</div>`, |
| 21 | +]; |
| 22 | + |
| 23 | +const invalidHbs = [ |
| 24 | + { |
| 25 | + code: 'START FINISH', |
| 26 | + output: null, |
| 27 | + errors: [{ message: 'Excess whitespace detected.' }], |
| 28 | + }, |
| 29 | + { |
| 30 | + code: 'START FINISH', |
| 31 | + output: null, |
| 32 | + errors: [{ message: 'Excess whitespace detected.' }], |
| 33 | + }, |
| 34 | + { |
| 35 | + code: 'START FINISH', |
| 36 | + output: null, |
| 37 | + errors: [{ message: 'Excess whitespace detected.' }], |
| 38 | + }, |
| 39 | + { |
| 40 | + code: 'START FINISH', |
| 41 | + output: null, |
| 42 | + errors: [{ message: 'Excess whitespace detected.' }], |
| 43 | + }, |
| 44 | +]; |
| 45 | + |
| 46 | +function wrapTemplate(entry) { |
| 47 | + if (typeof entry === 'string') { |
| 48 | + return `<template>${entry}</template>`; |
| 49 | + } |
| 50 | + |
| 51 | + return { |
| 52 | + ...entry, |
| 53 | + code: `<template>${entry.code}</template>`, |
| 54 | + output: entry.output ? `<template>${entry.output}</template>` : entry.output, |
| 55 | + }; |
| 56 | +} |
| 57 | + |
| 58 | +const gjsRuleTester = new RuleTester({ |
| 59 | + parser: require.resolve('ember-eslint-parser'), |
| 60 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 61 | +}); |
| 62 | + |
| 63 | +gjsRuleTester.run('template-no-whitespace-for-layout', rule, { |
| 64 | + valid: validHbs.map(wrapTemplate), |
| 65 | + invalid: invalidHbs.map(wrapTemplate), |
| 66 | +}); |
| 67 | + |
| 68 | +const hbsRuleTester = new RuleTester({ |
| 69 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 70 | + parserOptions: { |
| 71 | + ecmaVersion: 2022, |
| 72 | + sourceType: 'module', |
| 73 | + }, |
| 74 | +}); |
| 75 | + |
| 76 | +hbsRuleTester.run('template-no-whitespace-for-layout', rule, { |
| 77 | + valid: validHbs, |
| 78 | + invalid: invalidHbs, |
| 79 | +}); |
0 commit comments