|
| 1 | +const rule = require('../../../lib/rules/template-no-args-paths'); |
| 2 | +const RuleTester = require('eslint').RuleTester; |
| 3 | + |
| 4 | +const ruleTester = new RuleTester({ |
| 5 | + parser: require.resolve('ember-eslint-parser'), |
| 6 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 7 | +}); |
| 8 | +ruleTester.run('template-no-args-paths', rule, { |
| 9 | + valid: [ |
| 10 | + '<template>{{@foo}}</template>', |
| 11 | + '<template><div @foo={{cleanup this.args}}></div></template>', |
| 12 | + '<template>{{foo (name this.args)}}</template>', |
| 13 | + '<template>{{foo name=this.args}}</template>', |
| 14 | + '<template>{{foo name=(extract this.args)}}</template>', |
| 15 | + '<template><Foo @params={{this.args}} /></template>', |
| 16 | + '<template><Foo {{mod this.args}} /></template>', |
| 17 | + '<template><Foo {{mod items=this.args}} /></template>', |
| 18 | + '<template><Foo {{mod items=(extract this.args)}} /></template>', |
| 19 | + ], |
| 20 | + invalid: [ |
| 21 | + { |
| 22 | + code: '<template>{{@args.foo}}</template>', |
| 23 | + output: null, |
| 24 | + errors: [{ messageId: 'argsPath' }], |
| 25 | + }, |
| 26 | + |
| 27 | + { |
| 28 | + code: '<template>{{hello (format value=args.foo)}}</template>', |
| 29 | + output: null, |
| 30 | + errors: [{ messageId: 'argsPath' }], |
| 31 | + }, |
| 32 | + { |
| 33 | + code: '<template>{{hello value=args.foo}}</template>', |
| 34 | + output: null, |
| 35 | + errors: [{ messageId: 'argsPath' }], |
| 36 | + }, |
| 37 | + { |
| 38 | + code: '<template>{{hello (format args.foo.bar)}}</template>', |
| 39 | + output: null, |
| 40 | + errors: [{ messageId: 'argsPath' }], |
| 41 | + }, |
| 42 | + { |
| 43 | + code: '<template><br {{hello args.foo.bar}}></template>', |
| 44 | + output: null, |
| 45 | + errors: [{ messageId: 'argsPath' }], |
| 46 | + }, |
| 47 | + { |
| 48 | + code: '<template>{{hello args.foo.bar}}</template>', |
| 49 | + output: null, |
| 50 | + errors: [{ messageId: 'argsPath' }], |
| 51 | + }, |
| 52 | + { |
| 53 | + code: '<template>{{args.foo.bar}}</template>', |
| 54 | + output: null, |
| 55 | + errors: [{ messageId: 'argsPath' }], |
| 56 | + }, |
| 57 | + { |
| 58 | + code: '<template>{{args.foo}}</template>', |
| 59 | + output: null, |
| 60 | + errors: [{ messageId: 'argsPath' }], |
| 61 | + }, |
| 62 | + { |
| 63 | + code: '<template>{{this.args.foo}}</template>', |
| 64 | + output: null, |
| 65 | + errors: [{ messageId: 'argsPath' }], |
| 66 | + }, |
| 67 | + ], |
| 68 | +}); |
| 69 | + |
| 70 | +const hbsRuleTester = new RuleTester({ |
| 71 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 72 | + parserOptions: { |
| 73 | + ecmaVersion: 2022, |
| 74 | + sourceType: 'module', |
| 75 | + }, |
| 76 | +}); |
| 77 | + |
| 78 | +hbsRuleTester.run('template-no-args-paths', rule, { |
| 79 | + valid: [ |
| 80 | + '<div @foo={{cleanup this.args}}></div>', |
| 81 | + '{{foo (name this.args)}}', |
| 82 | + '{{foo name=this.args}}', |
| 83 | + '{{foo name=(extract this.args)}}', |
| 84 | + '<Foo @params={{this.args}} />', |
| 85 | + '<Foo {{mod this.args}} />', |
| 86 | + '<Foo {{mod items=this.args}} />', |
| 87 | + '<Foo {{mod items=(extract this.args)}} />', |
| 88 | + ], |
| 89 | + invalid: [ |
| 90 | + { |
| 91 | + code: '{{hello (format value=args.foo)}}', |
| 92 | + output: null, |
| 93 | + errors: [{ message: 'Do not use paths with @args, use @argName directly instead.' }], |
| 94 | + }, |
| 95 | + { |
| 96 | + code: '{{hello value=args.foo}}', |
| 97 | + output: null, |
| 98 | + errors: [{ message: 'Do not use paths with @args, use @argName directly instead.' }], |
| 99 | + }, |
| 100 | + { |
| 101 | + code: '{{hello (format args.foo.bar)}}', |
| 102 | + output: null, |
| 103 | + errors: [{ message: 'Do not use paths with @args, use @argName directly instead.' }], |
| 104 | + }, |
| 105 | + { |
| 106 | + code: '<br {{hello args.foo.bar}}>', |
| 107 | + output: null, |
| 108 | + errors: [{ message: 'Do not use paths with @args, use @argName directly instead.' }], |
| 109 | + }, |
| 110 | + { |
| 111 | + code: '{{hello args.foo.bar}}', |
| 112 | + output: null, |
| 113 | + errors: [{ message: 'Do not use paths with @args, use @argName directly instead.' }], |
| 114 | + }, |
| 115 | + { |
| 116 | + code: '{{args.foo.bar}}', |
| 117 | + output: null, |
| 118 | + errors: [{ message: 'Do not use paths with @args, use @argName directly instead.' }], |
| 119 | + }, |
| 120 | + { |
| 121 | + code: '{{args.foo}}', |
| 122 | + output: null, |
| 123 | + errors: [{ message: 'Do not use paths with @args, use @argName directly instead.' }], |
| 124 | + }, |
| 125 | + { |
| 126 | + code: '{{this.args.foo}}', |
| 127 | + output: null, |
| 128 | + errors: [{ message: 'Do not use paths with @args, use @argName directly instead.' }], |
| 129 | + }, |
| 130 | + ], |
| 131 | +}); |
0 commit comments