| 
 | 1 | +'use strict';  | 
 | 2 | + | 
 | 3 | +const rule = require('../../../lib/rules/no-component-lifecycle-hooks');  | 
 | 4 | +const RuleTester = require('eslint').RuleTester;  | 
 | 5 | + | 
 | 6 | +const { ERROR_MESSAGE_NO_COMPONENT_LIFECYCLE_HOOKS: ERROR_MESSAGE } = rule;  | 
 | 7 | + | 
 | 8 | +const ruleTester = new RuleTester({  | 
 | 9 | +  parserOptions: { ecmaVersion: 6, sourceType: 'module' },  | 
 | 10 | +});  | 
 | 11 | + | 
 | 12 | +ruleTester.run('no-component-lifecycle-hooks', rule, {  | 
 | 13 | +  valid: [  | 
 | 14 | +    `  | 
 | 15 | +      import Component from '@glimmer/component';  | 
 | 16 | +      export default class MyComponent extends Component {  | 
 | 17 | +        willDestroy() {}  | 
 | 18 | +      }  | 
 | 19 | +    `,  | 
 | 20 | +    `  | 
 | 21 | +      import Component from '@glimmer/component';  | 
 | 22 | +      export default class MyClass {  | 
 | 23 | +        didUpdate() {}  | 
 | 24 | +      }  | 
 | 25 | +    `,  | 
 | 26 | +    `  | 
 | 27 | +      export default {  | 
 | 28 | +        didUpdate() {},  | 
 | 29 | +      }  | 
 | 30 | +    `,  | 
 | 31 | +    `  | 
 | 32 | +      import Component from '@ember/component';  | 
 | 33 | +      export default Component.extend({  | 
 | 34 | +        willDestroy() {},  | 
 | 35 | +      });  | 
 | 36 | +    `,  | 
 | 37 | +    `  | 
 | 38 | +      export default EmberObject.extend({  | 
 | 39 | +        didUpdate() {},  | 
 | 40 | +      });  | 
 | 41 | +    `,  | 
 | 42 | +    `  | 
 | 43 | +      import Component from '@ember/component';  | 
 | 44 | +      export const Component1 = Component.extend({  | 
 | 45 | +        willDestroy() {},  | 
 | 46 | +      });  | 
 | 47 | +      export const Component2 = Component.extend({  | 
 | 48 | +        willDestroy() {},  | 
 | 49 | +      });  | 
 | 50 | +    `,  | 
 | 51 | +    `  | 
 | 52 | +      import Component from '@ember/component';  | 
 | 53 | +      export default class MyComponent extends Component {}  | 
 | 54 | +
  | 
 | 55 | +      const someRandomClassOrObject = { didDestroyElement() { } };  | 
 | 56 | +    `,  | 
 | 57 | +    `  | 
 | 58 | +      import Component from '@ember/component';  | 
 | 59 | +      export default Component.extend({});  | 
 | 60 | +
  | 
 | 61 | +      const someRandomClassOrObject = { didDestroyElement() { } };  | 
 | 62 | +    `,  | 
 | 63 | +  ],  | 
 | 64 | + | 
 | 65 | +  invalid: [  | 
 | 66 | +    {  | 
 | 67 | +      code: `  | 
 | 68 | +        import Component from '@glimmer/component';  | 
 | 69 | +        export default class MyComponent extends Component {  | 
 | 70 | +          didDestroyElement() {}  | 
 | 71 | +        }  | 
 | 72 | +      `,  | 
 | 73 | +      output: null,  | 
 | 74 | +      errors: [  | 
 | 75 | +        {  | 
 | 76 | +          message: ERROR_MESSAGE,  | 
 | 77 | +          type: 'MethodDefinition',  | 
 | 78 | +        },  | 
 | 79 | +      ],  | 
 | 80 | +    },  | 
 | 81 | +    {  | 
 | 82 | +      code: `  | 
 | 83 | +        import Component from '@ember/component';  | 
 | 84 | +        export default class MyComponent extends Component {  | 
 | 85 | +          didDestroyElement() {}  | 
 | 86 | +        }  | 
 | 87 | +      `,  | 
 | 88 | +      output: null,  | 
 | 89 | +      errors: [  | 
 | 90 | +        {  | 
 | 91 | +          message: ERROR_MESSAGE,  | 
 | 92 | +          type: 'MethodDefinition',  | 
 | 93 | +        },  | 
 | 94 | +      ],  | 
 | 95 | +    },  | 
 | 96 | +    {  | 
 | 97 | +      code: `  | 
 | 98 | +        import Component from '@ember/component';  | 
 | 99 | +        export default Component.extend({  | 
 | 100 | +          didDestroyElement() {}  | 
 | 101 | +        })  | 
 | 102 | +      `,  | 
 | 103 | +      output: null,  | 
 | 104 | +      errors: [  | 
 | 105 | +        {  | 
 | 106 | +          message: ERROR_MESSAGE,  | 
 | 107 | +          type: 'Identifier',  | 
 | 108 | +        },  | 
 | 109 | +      ],  | 
 | 110 | +    },  | 
 | 111 | +    {  | 
 | 112 | +      code: `  | 
 | 113 | +        import Component from '@ember/component';  | 
 | 114 | +
  | 
 | 115 | +        export const Component2 = Component.extend({  | 
 | 116 | +          didDestroyElement() {},  | 
 | 117 | +        });  | 
 | 118 | +
  | 
 | 119 | +        export const Component1 = Component.extend({  | 
 | 120 | +          willDestroy() {},  | 
 | 121 | +        });  | 
 | 122 | +      `,  | 
 | 123 | +      output: null,  | 
 | 124 | +      errors: [  | 
 | 125 | +        {  | 
 | 126 | +          message: ERROR_MESSAGE,  | 
 | 127 | +          type: 'Identifier',  | 
 | 128 | +        },  | 
 | 129 | +      ],  | 
 | 130 | +    },  | 
 | 131 | +    {  | 
 | 132 | +      code: `  | 
 | 133 | +        import Component from "@ember/component";  | 
 | 134 | +
  | 
 | 135 | +        export const Component1 = Component.extend({  | 
 | 136 | +          test: computed('', function () {}),  | 
 | 137 | +          didDestroyElement() {},  | 
 | 138 | +        });  | 
 | 139 | +      `,  | 
 | 140 | +      output: null,  | 
 | 141 | +      errors: [  | 
 | 142 | +        {  | 
 | 143 | +          message: ERROR_MESSAGE,  | 
 | 144 | +          type: 'Identifier',  | 
 | 145 | +        },  | 
 | 146 | +      ],  | 
 | 147 | +    },  | 
 | 148 | +    {  | 
 | 149 | +      code: `  | 
 | 150 | +        import Component from "@glimmer/component";  | 
 | 151 | +
  | 
 | 152 | +        export default class MyComponent extends Component {  | 
 | 153 | +          myMethod() {  | 
 | 154 | +            class FooBarClass {}  | 
 | 155 | +          }  | 
 | 156 | +          didDestroyElement() {}  | 
 | 157 | +        }  | 
 | 158 | +      `,  | 
 | 159 | +      output: null,  | 
 | 160 | +      errors: [  | 
 | 161 | +        {  | 
 | 162 | +          message: ERROR_MESSAGE,  | 
 | 163 | +          type: 'MethodDefinition',  | 
 | 164 | +        },  | 
 | 165 | +      ],  | 
 | 166 | +    },  | 
 | 167 | +  ],  | 
 | 168 | +});  | 
0 commit comments