Skip to content

Commit 2c1b80e

Browse files
committed
Fix error when decorator is empty
1 parent 4695b3c commit 2c1b80e

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-ngx-eslint",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Custom ESLint rules for Angular projects",
55
"main": "lib/index.js",
66
"scripts": {

src/rules/destroy-service-provider.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ tester.run("destroy-service-provider", rule, {
2323
) {}
2424
}`,
2525
},
26+
{
27+
code: `
28+
@Component()
29+
export class WelcomeComponent implements OnInit {
30+
constructor(
31+
private destroy$: DestroyService,
32+
) {}
33+
}`,
34+
},
35+
{
36+
code: `
37+
@Component({})
38+
export class WelcomeComponent implements OnInit {
39+
constructor(
40+
private destroy$: DestroyService,
41+
) {}
42+
}`,
43+
},
2644
{
2745
code: `
2846
@Directive({
@@ -35,6 +53,24 @@ tester.run("destroy-service-provider", rule, {
3553
) {}
3654
}`,
3755
},
56+
{
57+
code: `
58+
@Directive()
59+
export class MyDirective implements OnInit {
60+
constructor(
61+
private destroy$: DestroyService,
62+
) {}
63+
}`,
64+
},
65+
{
66+
code: `
67+
@Directive({})
68+
export class MyDirective implements OnInit {
69+
constructor(
70+
private destroy$: DestroyService,
71+
) {}
72+
}`,
73+
},
3874
],
3975
invalid: [
4076
{

src/rules/destroy-service-provider.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ const rule: Rule.RuleModule = {
55
return {
66
"ClassDeclaration > Decorator[expression.callee.name=/^(Component|Directive)$/]":
77
(node: any) => {
8+
const isDecoratorEmpty =
9+
!node.expression.arguments.length ||
10+
!node.expression.arguments[0].properties.length;
11+
12+
if (isDecoratorEmpty) {
13+
return;
14+
}
15+
816
// whether component has providers decorator property
917
const providersProperty =
1018
node.expression.arguments[0].properties.find((property: any) => {

0 commit comments

Comments
 (0)