|
| 1 | +const rule = require('../../../lib/rules/template-no-jsx-attributes'); |
| 2 | +const RuleTester = require('eslint').RuleTester; |
| 3 | + |
| 4 | +const ruleTester = new RuleTester({ |
| 5 | + parser: require.resolve('ember-eslint-parser'), |
| 6 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 7 | +}); |
| 8 | + |
| 9 | +ruleTester.run('template-no-jsx-attributes', rule, { |
| 10 | + valid: [ |
| 11 | + '<template><div></div></template>', |
| 12 | + '<template><div class="foo"></div></template>', |
| 13 | + '<template><div class></div></template>', |
| 14 | + '<template><div autoplay></div></template>', |
| 15 | + '<template><div contenteditable="true"></div></template>', |
| 16 | + ], |
| 17 | + invalid: [ |
| 18 | + { |
| 19 | + code: '<template><div acceptCharset="utf-8"></div></template>', |
| 20 | + output: '<template><div accept-charset="utf-8"></div></template>', |
| 21 | + errors: [ |
| 22 | + { |
| 23 | + message: |
| 24 | + 'Incorrect html attribute name detected - "acceptCharset", is probably unintended. Attributes in HTML are kebeb case.', |
| 25 | + }, |
| 26 | + ], |
| 27 | + }, |
| 28 | + { |
| 29 | + code: '<template><div contentEditable="true"></div></template>', |
| 30 | + output: '<template><div contenteditable="true"></div></template>', |
| 31 | + errors: [ |
| 32 | + { |
| 33 | + message: |
| 34 | + 'Incorrect html attribute name detected - "contentEditable", is probably unintended. Attributes in HTML are kebeb case.', |
| 35 | + }, |
| 36 | + ], |
| 37 | + }, |
| 38 | + { |
| 39 | + code: '<template><div className></div></template>', |
| 40 | + output: '<template><div class></div></template>', |
| 41 | + errors: [ |
| 42 | + { |
| 43 | + message: |
| 44 | + "Attribute, className, does not assign the 'class' attribute as it would in JSX. To assign the 'class' attribute, set the 'class' attribute, instead of 'className'. In HTML, all attributes are valid, but 'className' doesn't do anything.", |
| 45 | + }, |
| 46 | + ], |
| 47 | + }, |
| 48 | + { |
| 49 | + code: '<template><div className="foo"></div></template>', |
| 50 | + output: '<template><div class="foo"></div></template>', |
| 51 | + errors: [ |
| 52 | + { |
| 53 | + message: |
| 54 | + "Attribute, className, does not assign the 'class' attribute as it would in JSX. To assign the 'class' attribute, set the 'class' attribute, instead of 'className'. In HTML, all attributes are valid, but 'className' doesn't do anything.", |
| 55 | + }, |
| 56 | + ], |
| 57 | + }, |
| 58 | + |
| 59 | + { |
| 60 | + code: '<template><div autoPlay></div></template>', |
| 61 | + output: '<template><div autoplay></div></template>', |
| 62 | + errors: [ |
| 63 | + { |
| 64 | + message: |
| 65 | + 'Incorrect html attribute name detected - "autoPlay", is probably unintended. Attributes in HTML are kebeb case.', |
| 66 | + }, |
| 67 | + ], |
| 68 | + }, |
| 69 | + { |
| 70 | + code: '<template><div contentEditable></div></template>', |
| 71 | + output: '<template><div contenteditable></div></template>', |
| 72 | + errors: [ |
| 73 | + { |
| 74 | + message: |
| 75 | + 'Incorrect html attribute name detected - "contentEditable", is probably unintended. Attributes in HTML are kebeb case.', |
| 76 | + }, |
| 77 | + ], |
| 78 | + }, |
| 79 | + ], |
| 80 | +}); |
| 81 | + |
| 82 | +const hbsRuleTester = new RuleTester({ |
| 83 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 84 | + parserOptions: { |
| 85 | + ecmaVersion: 2022, |
| 86 | + sourceType: 'module', |
| 87 | + }, |
| 88 | +}); |
| 89 | + |
| 90 | +hbsRuleTester.run('template-no-jsx-attributes', rule, { |
| 91 | + valid: [ |
| 92 | + '<div></div>', |
| 93 | + '<div class="foo"></div>', |
| 94 | + '<div class></div>', |
| 95 | + '<div autoplay></div>', |
| 96 | + '<div contenteditable="true"></div>', |
| 97 | + ], |
| 98 | + invalid: [ |
| 99 | + { |
| 100 | + code: '<div acceptCharset="utf-8"></div>', |
| 101 | + output: '<div accept-charset="utf-8"></div>', |
| 102 | + errors: [ |
| 103 | + { |
| 104 | + message: |
| 105 | + 'Incorrect html attribute name detected - "acceptCharset", is probably unintended. Attributes in HTML are kebeb case.', |
| 106 | + }, |
| 107 | + ], |
| 108 | + }, |
| 109 | + { |
| 110 | + code: '<div contentEditable="true"></div>', |
| 111 | + output: '<div contenteditable="true"></div>', |
| 112 | + errors: [ |
| 113 | + { |
| 114 | + message: |
| 115 | + 'Incorrect html attribute name detected - "contentEditable", is probably unintended. Attributes in HTML are kebeb case.', |
| 116 | + }, |
| 117 | + ], |
| 118 | + }, |
| 119 | + { |
| 120 | + code: '<div className></div>', |
| 121 | + output: '<div class></div>', |
| 122 | + errors: [ |
| 123 | + { |
| 124 | + message: |
| 125 | + "Attribute, className, does not assign the 'class' attribute as it would in JSX. To assign the 'class' attribute, set the 'class' attribute, instead of 'className'. In HTML, all attributes are valid, but 'className' doesn't do anything.", |
| 126 | + }, |
| 127 | + ], |
| 128 | + }, |
| 129 | + { |
| 130 | + code: '<div className="foo"></div>', |
| 131 | + output: '<div class="foo"></div>', |
| 132 | + errors: [ |
| 133 | + { |
| 134 | + message: |
| 135 | + "Attribute, className, does not assign the 'class' attribute as it would in JSX. To assign the 'class' attribute, set the 'class' attribute, instead of 'className'. In HTML, all attributes are valid, but 'className' doesn't do anything.", |
| 136 | + }, |
| 137 | + ], |
| 138 | + }, |
| 139 | + { |
| 140 | + code: '<div autoPlay></div>', |
| 141 | + output: '<div autoplay></div>', |
| 142 | + errors: [ |
| 143 | + { |
| 144 | + message: |
| 145 | + 'Incorrect html attribute name detected - "autoPlay", is probably unintended. Attributes in HTML are kebeb case.', |
| 146 | + }, |
| 147 | + ], |
| 148 | + }, |
| 149 | + { |
| 150 | + code: '<div contentEditable></div>', |
| 151 | + output: '<div contenteditable></div>', |
| 152 | + errors: [ |
| 153 | + { |
| 154 | + message: |
| 155 | + 'Incorrect html attribute name detected - "contentEditable", is probably unintended. Attributes in HTML are kebeb case.', |
| 156 | + }, |
| 157 | + ], |
| 158 | + }, |
| 159 | + ], |
| 160 | +}); |
0 commit comments