Skip to content

Commit 7128c23

Browse files
authored
Allow empty-but-decorated classes in no-empty-glimmer-component-classes rule (#1374)
1 parent f3627b4 commit 7128c23

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

docs/rules/no-empty-glimmer-component-classes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ const MyComponent = templateOnly();
4444
export default MyComponent;
4545
```
4646

47+
```js
48+
import Component from '@glimmer/component';
49+
import MyDecorator from 'my-decorator';
50+
51+
@MyDecorator
52+
class MyComponent extends Component {}
53+
```
54+
4755
## References
4856

4957
- [Glimmer Components - Octane Upgrade Guide](https://guides.emberjs.com/release/upgrading/current-edition/glimmer-components/)

lib/rules/no-empty-glimmer-component-classes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
create(context) {
2828
return {
2929
ClassDeclaration(node) {
30-
if (isGlimmerComponent(context, node) && node.body.body.length === 0) {
30+
if (isGlimmerComponent(context, node) && !node.decorators && node.body.body.length === 0) {
3131
context.report({ node, message: ERROR_MESSAGE });
3232
}
3333
},

tests/lib/rules/no-empty-glimmer-component-classes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { ERROR_MESSAGE } = rule;
1212
//------------------------------------------------------------------------------
1313

1414
const ruleTester = new RuleTester({
15+
parser: require.resolve('@babel/eslint-parser'),
1516
parserOptions: {
1617
ecmaVersion: 2020,
1718
sourceType: 'module',
@@ -28,6 +29,11 @@ ruleTester.run('no-empty-glimmer-component-classes', rule, {
2829
}
2930
}`,
3031
'class MyComponent extends NotAGlimmerComponent {}',
32+
`import Component from '@glimmer/component';
33+
import MyDecorator from 'my-decorator';
34+
35+
@MyDecorator
36+
class MyComponent extends Component {}`,
3137
],
3238
invalid: [
3339
{

0 commit comments

Comments
 (0)