|
| 1 | +/** |
| 2 | + * @author Yosuke Ota |
| 3 | + */ |
| 4 | +'use strict' |
| 5 | + |
| 6 | +const { RuleTester, CLIEngine } = require('eslint') |
| 7 | +const semver = require('semver') |
| 8 | +const rule = require('../../../lib/rules/func-call-spacing') |
| 9 | + |
| 10 | +const tester = new RuleTester({ |
| 11 | + parser: require.resolve('vue-eslint-parser'), |
| 12 | + parserOptions: { ecmaVersion: 2020 } |
| 13 | +}) |
| 14 | + |
| 15 | +tester.run('func-call-spacing', rule, { |
| 16 | + valid: [ |
| 17 | + ` |
| 18 | + <template> |
| 19 | + <div :foo="foo()" /> |
| 20 | + </template> |
| 21 | + `, |
| 22 | + { |
| 23 | + code: ` |
| 24 | + <template> |
| 25 | + <div :foo="foo ()" /> |
| 26 | + </template> |
| 27 | + `, |
| 28 | + options: ['always'] |
| 29 | + }, |
| 30 | + ` |
| 31 | + <template> |
| 32 | + <div :[foo()]="value" /> |
| 33 | + </template> |
| 34 | + `, |
| 35 | + { |
| 36 | + code: ` |
| 37 | + <template> |
| 38 | + <div :[foo()]="value" /> |
| 39 | + </template> |
| 40 | + `, |
| 41 | + options: ['always'] |
| 42 | + } |
| 43 | + ], |
| 44 | + invalid: [ |
| 45 | + { |
| 46 | + code: ` |
| 47 | + <template> |
| 48 | + <div :foo="foo ()" /> |
| 49 | + </template> |
| 50 | + `, |
| 51 | + output: ` |
| 52 | + <template> |
| 53 | + <div :foo="foo()" /> |
| 54 | + </template> |
| 55 | + `, |
| 56 | + errors: [ |
| 57 | + { |
| 58 | + message: semver.lt(CLIEngine.version, '7.0.0') |
| 59 | + ? 'Unexpected newline between function name and paren.' |
| 60 | + : 'Unexpected whitespace between function name and paren.', |
| 61 | + line: 3 |
| 62 | + } |
| 63 | + ] |
| 64 | + }, |
| 65 | + { |
| 66 | + code: ` |
| 67 | + <template> |
| 68 | + <div :foo="foo()" /> |
| 69 | + </template> |
| 70 | + `, |
| 71 | + options: ['always'], |
| 72 | + output: ` |
| 73 | + <template> |
| 74 | + <div :foo="foo ()" /> |
| 75 | + </template> |
| 76 | + `, |
| 77 | + errors: [ |
| 78 | + { |
| 79 | + message: 'Missing space between function name and paren.', |
| 80 | + line: 3 |
| 81 | + } |
| 82 | + ] |
| 83 | + } |
| 84 | + ] |
| 85 | +}) |
0 commit comments