|
| 1 | +/** |
| 2 | + * @fileoverview Define a style for the props casing in templates. |
| 3 | + * @author Armano |
| 4 | + */ |
| 5 | +'use strict' |
| 6 | + |
| 7 | +// ------------------------------------------------------------------------------ |
| 8 | +// Requirements |
| 9 | +// ------------------------------------------------------------------------------ |
| 10 | + |
| 11 | +const rule = require('../../../lib/rules/attribute-hyphenation') |
| 12 | + |
| 13 | +const RuleTester = require('eslint').RuleTester |
| 14 | + |
| 15 | +// ------------------------------------------------------------------------------ |
| 16 | +// Tests |
| 17 | +// ------------------------------------------------------------------------------ |
| 18 | + |
| 19 | +const ruleTester = new RuleTester({ |
| 20 | + parser: 'vue-eslint-parser', |
| 21 | + parserOptions: { ecmaVersion: 2015 } |
| 22 | +}) |
| 23 | + |
| 24 | +ruleTester.run('attribute-hyphenation', rule, { |
| 25 | + |
| 26 | + valid: [ |
| 27 | + { |
| 28 | + filename: 'test.vue', |
| 29 | + code: '' |
| 30 | + }, |
| 31 | + { |
| 32 | + filename: 'test.vue', |
| 33 | + code: '<template><div><custom data-id="foo" aria-test="bar" my-prop="prop"></custom></div></template>', |
| 34 | + options: ['always'] |
| 35 | + }, |
| 36 | + { |
| 37 | + filename: 'test.vue', |
| 38 | + code: '<template><div><custom data-id="foo" aria-test="bar" myProp="prop"></custom></div></template>', |
| 39 | + options: ['never'] |
| 40 | + }, |
| 41 | + { |
| 42 | + filename: 'test.vue', |
| 43 | + code: '<template><div data-id="foo" aria-test="bar"><a onClick="" my-prop="prop"></a></div></template>', |
| 44 | + options: ['never'] |
| 45 | + } |
| 46 | + ], |
| 47 | + |
| 48 | + invalid: [ |
| 49 | + { |
| 50 | + filename: 'test.vue', |
| 51 | + code: '<template><div><custom my-prop="foo"></custom></div></template>', |
| 52 | + output: '<template><div><custom myProp="foo"></custom></div></template>', |
| 53 | + options: ['never'], |
| 54 | + errors: [{ |
| 55 | + message: "Attribute 'my-prop' cann't be hyphenated.", |
| 56 | + type: 'VIdentifier', |
| 57 | + line: 1 |
| 58 | + }] |
| 59 | + }, |
| 60 | + { |
| 61 | + filename: 'test.vue', |
| 62 | + code: '<template><div><custom MyProp="Bar"></custom></div></template>', |
| 63 | + output: '<template><div><custom my-prop="Bar"></custom></div></template>', |
| 64 | + options: ['always'], |
| 65 | + errors: [{ |
| 66 | + message: "Attribute 'MyProp' must be hyphenated.", |
| 67 | + type: 'VIdentifier', |
| 68 | + line: 1 |
| 69 | + }] |
| 70 | + }, |
| 71 | + { |
| 72 | + filename: 'test.vue', |
| 73 | + code: '<template><div><custom :my-prop="prop"></custom></div></template>', |
| 74 | + output: '<template><div><custom :myProp="prop"></custom></div></template>', |
| 75 | + options: ['never'], |
| 76 | + errors: [{ |
| 77 | + message: "Attribute ':my-prop' cann't be hyphenated.", |
| 78 | + type: 'VDirectiveKey', |
| 79 | + line: 1 |
| 80 | + }] |
| 81 | + }, |
| 82 | + { |
| 83 | + filename: 'test.vue', |
| 84 | + code: '<template><div><custom :MyProp="prop"></custom></div></template>', |
| 85 | + output: '<template><div><custom :my-prop="prop"></custom></div></template>', |
| 86 | + options: ['always'], |
| 87 | + errors: [{ |
| 88 | + message: "Attribute ':MyProp' must be hyphenated.", |
| 89 | + type: 'VDirectiveKey', |
| 90 | + line: 1 |
| 91 | + }] |
| 92 | + }, |
| 93 | + { |
| 94 | + filename: 'test.vue', |
| 95 | + code: '<template><div><custom v-bind:my-prop="prop"></custom></div></template>', |
| 96 | + output: '<template><div><custom v-bind:myProp="prop"></custom></div></template>', |
| 97 | + options: ['never'], |
| 98 | + errors: [{ |
| 99 | + message: "Attribute 'v-bind:my-prop' cann't be hyphenated.", |
| 100 | + type: 'VDirectiveKey', |
| 101 | + line: 1 |
| 102 | + }] |
| 103 | + }, |
| 104 | + { |
| 105 | + filename: 'test.vue', |
| 106 | + code: '<template><div><custom v-bind:MyProp="prop"></custom></div></template>', |
| 107 | + output: '<template><div><custom v-bind:my-prop="prop"></custom></div></template>', |
| 108 | + options: ['always'], |
| 109 | + errors: [{ |
| 110 | + message: "Attribute 'v-bind:MyProp' must be hyphenated.", |
| 111 | + type: 'VDirectiveKey', |
| 112 | + line: 1 |
| 113 | + }] |
| 114 | + } |
| 115 | + ] |
| 116 | +}) |
0 commit comments