|  | 
|  | 1 | +/** | 
|  | 2 | + * @author *****your name***** | 
|  | 3 | + * See LICENSE file in root directory for full license. | 
|  | 4 | + */ | 
|  | 5 | +'use strict' | 
|  | 6 | + | 
|  | 7 | +const RuleTester = require('eslint').RuleTester | 
|  | 8 | +const rule = require('../../../lib/rules/no-invalid-attribute-name') | 
|  | 9 | + | 
|  | 10 | +const tester = new RuleTester({ | 
|  | 11 | +  parser: require.resolve('vue-eslint-parser'), | 
|  | 12 | +  parserOptions: { | 
|  | 13 | +    ecmaVersion: 2020, | 
|  | 14 | +    sourceType: 'module' | 
|  | 15 | +  } | 
|  | 16 | +}) | 
|  | 17 | + | 
|  | 18 | +tester.run('no-invalid-attribute-name', rule, { | 
|  | 19 | +  valid: [ | 
|  | 20 | +    { | 
|  | 21 | +      filename: 'test.vue', | 
|  | 22 | +      code: '<template><p foo /></template>' | 
|  | 23 | +    }, | 
|  | 24 | +    { | 
|  | 25 | +      filename: 'test.vue', | 
|  | 26 | +      code: `<template><p foo="bar" /></template>` | 
|  | 27 | +    }, | 
|  | 28 | +    { | 
|  | 29 | +      filename: 'test.vue', | 
|  | 30 | +      code: `<template><p foo-bar /></template>` | 
|  | 31 | +    }, | 
|  | 32 | +    { | 
|  | 33 | +      filename: 'test.vue', | 
|  | 34 | +      code: `<template><p _foo-bar /></template>` | 
|  | 35 | +    }, | 
|  | 36 | +    { | 
|  | 37 | +      filename: 'test.vue', | 
|  | 38 | +      code: `<template><p :foo-bar /></template>` | 
|  | 39 | +    }, | 
|  | 40 | +    { | 
|  | 41 | +      filename: 'test.vue', | 
|  | 42 | +      code: `<template><p foo.bar /></template>` | 
|  | 43 | +    }, | 
|  | 44 | +    { | 
|  | 45 | +      filename: 'test.vue', | 
|  | 46 | +      code: `<template><p quux-.9 /></template>` | 
|  | 47 | +    }, | 
|  | 48 | +    { | 
|  | 49 | +      filename: 'test.vue', | 
|  | 50 | +      code: `<template><MyComponent 0abc="foo" /></template>` | 
|  | 51 | +    }, | 
|  | 52 | +    { | 
|  | 53 | +      filename: 'test.vue', | 
|  | 54 | +      code: `<template><MyComponent :0abc="foo" /></template>` | 
|  | 55 | +    }, | 
|  | 56 | +    { | 
|  | 57 | +      filename: 'test.vue', | 
|  | 58 | +      code: `<template><a :href="url"> ... </a></template>` | 
|  | 59 | +    }, | 
|  | 60 | +    { | 
|  | 61 | +      filename: 'test.vue', | 
|  | 62 | +      code: `<template><div v-bind:class="{ active: isActive }"></div></template>` | 
|  | 63 | +    }, | 
|  | 64 | +    { | 
|  | 65 | +      filename: 'test.vue', | 
|  | 66 | +      code: `<template><p v-if="seen">Now you see me</p></template>` | 
|  | 67 | +    }, | 
|  | 68 | +    { | 
|  | 69 | +      filename: 'test.vue', | 
|  | 70 | +      code: `<a v-on:[eventName]="doSomething"> ... </a>` | 
|  | 71 | +    }, | 
|  | 72 | +    { | 
|  | 73 | +      filename: 'test.vue', | 
|  | 74 | +      code: `<form v-on:submit.prevent="onSubmit"> ... </form>` | 
|  | 75 | +    }, | 
|  | 76 | +    { | 
|  | 77 | +      filename: 'test.vue', | 
|  | 78 | +      code: `<a @[event]="doSomething"> ... </a>` | 
|  | 79 | +    }, | 
|  | 80 | +    { | 
|  | 81 | +      filename: 'test.vue', | 
|  | 82 | +      code: `<template><div v-bind="..."></div></template>` | 
|  | 83 | +    }, | 
|  | 84 | +    { | 
|  | 85 | +      filename: 'test.vue', | 
|  | 86 | +      code: `<template><div v-0abc="..."></div></template>` | 
|  | 87 | +    } | 
|  | 88 | +  ], | 
|  | 89 | +  invalid: [ | 
|  | 90 | +    { | 
|  | 91 | +      filename: 'test.vue', | 
|  | 92 | +      code: `<template><p 0abc /></template>`, | 
|  | 93 | +      errors: [ | 
|  | 94 | +        { | 
|  | 95 | +          message: 'Attribute name 0abc is not valid.', | 
|  | 96 | +          line: 1, | 
|  | 97 | +          column: 14 | 
|  | 98 | +        } | 
|  | 99 | +      ] | 
|  | 100 | +    }, | 
|  | 101 | +    { | 
|  | 102 | +      filename: 'test.vue', | 
|  | 103 | +      code: `<template><p -def></template>`, | 
|  | 104 | +      errors: [ | 
|  | 105 | +        { | 
|  | 106 | +          message: 'Attribute name -def is not valid.', | 
|  | 107 | +          line: 1, | 
|  | 108 | +          column: 14 | 
|  | 109 | +        } | 
|  | 110 | +      ] | 
|  | 111 | +    }, | 
|  | 112 | +    { | 
|  | 113 | +      filename: 'test.vue', | 
|  | 114 | +      code: `<template><p !ghi /></template>`, | 
|  | 115 | +      errors: [ | 
|  | 116 | +        { | 
|  | 117 | +          message: 'Attribute name !ghi is not valid.', | 
|  | 118 | +          line: 1, | 
|  | 119 | +          column: 14 | 
|  | 120 | +        } | 
|  | 121 | +      ] | 
|  | 122 | +    }, | 
|  | 123 | +    { | 
|  | 124 | +      filename: 'test.vue', | 
|  | 125 | +      code: `<template><p v-bind:0abc=""></template>`, | 
|  | 126 | +      errors: [ | 
|  | 127 | +        { | 
|  | 128 | +          message: 'Attribute name 0abc is not valid.', | 
|  | 129 | +          line: 1, | 
|  | 130 | +          column: 14 | 
|  | 131 | +        } | 
|  | 132 | +      ] | 
|  | 133 | +    }, | 
|  | 134 | +    { | 
|  | 135 | +      filename: 'test.vue', | 
|  | 136 | +      code: `<template><p :0abc="..." /></template>`, | 
|  | 137 | +      errors: [ | 
|  | 138 | +        { | 
|  | 139 | +          message: 'Attribute name 0abc is not valid.', | 
|  | 140 | +          line: 1, | 
|  | 141 | +          column: 14 | 
|  | 142 | +        } | 
|  | 143 | +      ] | 
|  | 144 | +    } | 
|  | 145 | +  ] | 
|  | 146 | +}) | 
0 commit comments