|
| 1 | +/** |
| 2 | + * @author Yosuke Ota |
| 3 | + */ |
| 4 | +'use strict' |
| 5 | + |
| 6 | +const RuleTester = require('eslint').RuleTester |
| 7 | +const rule = require('../../../lib/rules/array-bracket-newline') |
| 8 | + |
| 9 | +const tester = new RuleTester({ |
| 10 | + parser: require.resolve('vue-eslint-parser'), |
| 11 | + parserOptions: { ecmaVersion: 2015 } |
| 12 | +}) |
| 13 | + |
| 14 | +tester.run('array-bracket-newline', rule, { |
| 15 | + valid: [ |
| 16 | + '<template><div :attr="[a]" /></template>', |
| 17 | + '<template><div :attr="[\na,\nb,\nc\n]" /></template>', |
| 18 | + { |
| 19 | + code: '<template><div :attr="[a]" /></template>', |
| 20 | + options: ['never'] |
| 21 | + }, |
| 22 | + { |
| 23 | + code: '<template><div :attr="[\na\n]" /></template>', |
| 24 | + options: ['always'] |
| 25 | + }, |
| 26 | + '<template><div :[attr]="a" /></template>', |
| 27 | + { |
| 28 | + code: '<template><div :[attr]="a" /></template>', |
| 29 | + options: ['always'] |
| 30 | + }, |
| 31 | + '<template><div :[[attr]]="a" /></template>', |
| 32 | + { |
| 33 | + code: '<template><div :[[attr]]="a" /></template>', |
| 34 | + options: ['always'] |
| 35 | + } |
| 36 | + ], |
| 37 | + invalid: [ |
| 38 | + { |
| 39 | + code: '<template><div :attr="[\na]" /></template>', |
| 40 | + output: '<template><div :attr="[a]" /></template>', |
| 41 | + errors: ["There should be no linebreak after '['."] |
| 42 | + }, |
| 43 | + { |
| 44 | + code: '<template><div :attr="[a\n]" /></template>', |
| 45 | + output: '<template><div :attr="[a]" /></template>', |
| 46 | + errors: ["There should be no linebreak before ']'."] |
| 47 | + }, |
| 48 | + { |
| 49 | + code: '<template><div :attr="[\na\n]" /></template>', |
| 50 | + output: '<template><div :attr="[a]" /></template>', |
| 51 | + errors: [ |
| 52 | + "There should be no linebreak after '['.", |
| 53 | + "There should be no linebreak before ']'." |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + code: '<template><div :attr="[\na]" /></template>', |
| 58 | + options: ['never'], |
| 59 | + output: '<template><div :attr="[a]" /></template>', |
| 60 | + errors: ["There should be no linebreak after '['."] |
| 61 | + }, |
| 62 | + { |
| 63 | + code: '<template><div :attr="[a\n]" /></template>', |
| 64 | + options: ['never'], |
| 65 | + output: '<template><div :attr="[a]" /></template>', |
| 66 | + errors: ["There should be no linebreak before ']'."] |
| 67 | + }, |
| 68 | + { |
| 69 | + code: '<template><div :attr="[\na\n]" /></template>', |
| 70 | + options: ['never'], |
| 71 | + output: '<template><div :attr="[a]" /></template>', |
| 72 | + errors: [ |
| 73 | + "There should be no linebreak after '['.", |
| 74 | + "There should be no linebreak before ']'." |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + code: '<template><div :attr="[\na]" /></template>', |
| 79 | + options: ['always'], |
| 80 | + output: '<template><div :attr="[\na\n]" /></template>', |
| 81 | + errors: ["A linebreak is required before ']'."] |
| 82 | + }, |
| 83 | + { |
| 84 | + code: '<template><div :attr="[a\n]" /></template>', |
| 85 | + options: ['always'], |
| 86 | + output: '<template><div :attr="[\na\n]" /></template>', |
| 87 | + errors: ["A linebreak is required after '['."] |
| 88 | + }, |
| 89 | + { |
| 90 | + code: '<template><div :attr="[a]" /></template>', |
| 91 | + options: ['always'], |
| 92 | + output: '<template><div :attr="[\na\n]" /></template>', |
| 93 | + errors: [ |
| 94 | + "A linebreak is required after '['.", |
| 95 | + "A linebreak is required before ']'." |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + code: '<template><div :[[attr]]="[a]" /></template>', |
| 100 | + options: ['always'], |
| 101 | + output: '<template><div :[[attr]]="[\na\n]" /></template>', |
| 102 | + errors: [ |
| 103 | + "A linebreak is required after '['.", |
| 104 | + "A linebreak is required before ']'." |
| 105 | + ] |
| 106 | + } |
| 107 | + ] |
| 108 | +}) |
0 commit comments