Skip to content

Commit

Permalink
Allow empty-but-decorated classes in `no-empty-glimmer-component-clas…
Browse files Browse the repository at this point in the history
…ses` rule (#1374)
  • Loading branch information
adrigzr authored Nov 23, 2021
1 parent f3627b4 commit 7128c23
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/rules/no-empty-glimmer-component-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ const MyComponent = templateOnly();
export default MyComponent;
```

```js
import Component from '@glimmer/component';
import MyDecorator from 'my-decorator';

@MyDecorator
class MyComponent extends Component {}
```

## References

- [Glimmer Components - Octane Upgrade Guide](https://guides.emberjs.com/release/upgrading/current-edition/glimmer-components/)
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-empty-glimmer-component-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
create(context) {
return {
ClassDeclaration(node) {
if (isGlimmerComponent(context, node) && node.body.body.length === 0) {
if (isGlimmerComponent(context, node) && !node.decorators && node.body.body.length === 0) {
context.report({ node, message: ERROR_MESSAGE });
}
},
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-empty-glimmer-component-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const { ERROR_MESSAGE } = rule;
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({
parser: require.resolve('@babel/eslint-parser'),
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
Expand All @@ -28,6 +29,11 @@ ruleTester.run('no-empty-glimmer-component-classes', rule, {
}
}`,
'class MyComponent extends NotAGlimmerComponent {}',
`import Component from '@glimmer/component';
import MyDecorator from 'my-decorator';
@MyDecorator
class MyComponent extends Component {}`,
],
invalid: [
{
Expand Down

0 comments on commit 7128c23

Please sign in to comment.