|
| 1 | +// ------------------------------------------------------------------------------ |
| 2 | +// Requirements |
| 3 | +// ------------------------------------------------------------------------------ |
| 4 | + |
| 5 | +const rule = require('../../../lib/rules/no-mixins'); |
| 6 | +const RuleTester = require('eslint').RuleTester; |
| 7 | + |
| 8 | +// ------------------------------------------------------------------------------ |
| 9 | +// Tests |
| 10 | +// ------------------------------------------------------------------------------ |
| 11 | + |
| 12 | +const { ERROR_MESSAGE } = rule; |
| 13 | +const eslintTester = new RuleTester({ |
| 14 | + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, |
| 15 | +}); |
| 16 | +eslintTester.run('no-mixins', rule, { |
| 17 | + valid: [ |
| 18 | + ` |
| 19 | + import NoMixinRule from "some/addon/mixin"; |
| 20 | + export default mixin; |
| 21 | + `, |
| 22 | + ` |
| 23 | + import NameIsMixin from "some/addon"; |
| 24 | + export default Component.extend({}); |
| 25 | + `, |
| 26 | + ` |
| 27 | + import * as Mixins from "some/addon/mixins"; |
| 28 | + export default Component.extend({}); |
| 29 | + `, |
| 30 | + ` |
| 31 | + import Mixin from '@ember/object/mixin'; |
| 32 | + const newMixin = Mixin.create({}); |
| 33 | + `, |
| 34 | + ], |
| 35 | + invalid: [ |
| 36 | + { |
| 37 | + code: ` |
| 38 | + import BadCode from "my-addon/mixins/bad-code"; |
| 39 | +
|
| 40 | + export default Component.extend(BadCode, {}); |
| 41 | + `, |
| 42 | + output: null, |
| 43 | + errors: [{ message: ERROR_MESSAGE, type: 'ImportDeclaration' }], |
| 44 | + }, |
| 45 | + { |
| 46 | + code: ` |
| 47 | + import EmberObject from '@ember/object'; |
| 48 | + import EditableMixin from '../mixins/editable'; |
| 49 | +
|
| 50 | + const Comment = EmberObject.extend(EditableMixin, { |
| 51 | + post: null |
| 52 | + }); |
| 53 | + `, |
| 54 | + output: null, |
| 55 | + errors: [{ message: ERROR_MESSAGE, type: 'ImportDeclaration' }], |
| 56 | + }, |
| 57 | + { |
| 58 | + code: ` |
| 59 | + import Component from '@ember/component'; |
| 60 | + import FooMixin from '../utils/mixins/foo'; |
| 61 | +
|
| 62 | + export default class FooComponent extends Component.extend(FooMixin) { |
| 63 | + // ... |
| 64 | + } |
| 65 | + `, |
| 66 | + output: null, |
| 67 | + errors: [{ message: ERROR_MESSAGE, type: 'ImportDeclaration' }], |
| 68 | + }, |
| 69 | + ], |
| 70 | +}); |
0 commit comments