|
| 1 | +/** |
| 2 | + * @fileoverview enforce usage of `exact` modifier on `v-on`. |
| 3 | + * @author Armano |
| 4 | + */ |
| 5 | +'use strict' |
| 6 | + |
| 7 | +// ------------------------------------------------------------------------------ |
| 8 | +// Requirements |
| 9 | +// ------------------------------------------------------------------------------ |
| 10 | + |
| 11 | +const rule = require('../../../lib/rules/use-v-on-exact') |
| 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('use-v-on-exact', rule, { |
| 25 | + |
| 26 | + valid: [ |
| 27 | + { |
| 28 | + code: `<template><button @click="foo"/></template>` |
| 29 | + }, |
| 30 | + { |
| 31 | + code: `<template><button @click="foo" :click="foo"/></template>` |
| 32 | + }, |
| 33 | + { |
| 34 | + code: `<template><button @click.ctrl="foo"/></template>` |
| 35 | + }, |
| 36 | + { |
| 37 | + code: `<template><button @click.exact="foo"/></template>` |
| 38 | + }, |
| 39 | + { |
| 40 | + code: `<template><button @click.exact="foo" @click.ctrl="foo"/></template>` |
| 41 | + }, |
| 42 | + { |
| 43 | + code: `<template><button v-on:click="foo"/></template>` |
| 44 | + }, |
| 45 | + { |
| 46 | + code: `<template><button v-on:click.ctrl="foo"/></template>` |
| 47 | + }, |
| 48 | + { |
| 49 | + code: `<template><button v-on:click.exact="foo"/></template>` |
| 50 | + }, |
| 51 | + { |
| 52 | + code: `<template><button v-on:click.exact="foo" v-on:click.ctrl="foo"/></template>` |
| 53 | + }, |
| 54 | + { |
| 55 | + code: `<template><button @click="foo" @focus="foo"/></template>` |
| 56 | + }, |
| 57 | + { |
| 58 | + code: `<template><button @click="foo" @click="foo"/></template>` |
| 59 | + }, |
| 60 | + { |
| 61 | + code: `<template><button @click="foo"/><button @click.ctrl="foo"/></template>` |
| 62 | + } |
| 63 | + ], |
| 64 | + |
| 65 | + invalid: [ |
| 66 | + { |
| 67 | + code: `<template><button @click="foo" @click.ctrl="foo"/></template>`, |
| 68 | + errors: ["Consider to use '.exact' modifier."] |
| 69 | + }, |
| 70 | + { |
| 71 | + code: `<template><button @click="foo" @focus="foo" @click.ctrl="foo"/></template>`, |
| 72 | + errors: ["Consider to use '.exact' modifier."] |
| 73 | + } |
| 74 | + ] |
| 75 | +}) |
0 commit comments