Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 65c28f2

Browse files
committedMay 18, 2025
feat: add missing component decorator example
1 parent 1616d1d commit 65c28f2

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed
 

‎website/catalog/typescript/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ However, you can use the [`languageGlobs`](/reference/sgconfig.html#languageglob
1616
<!--@include: ./no-console-except-catch.md-->
1717
<!--@include: ./find-import-usage.md-->
1818
<!--@include: ./switch-from-should-to-expect.md-->
19-
<!--@include: ./speed-up-barrel-import.md-->
19+
<!--@include: ./speed-up-barrel-import.md-->
20+
<!--@include: ./missing-component-decorator.md-->
21+
<!--@include: ./find-import-identifiers.md-->
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## Missing Component Decorator
2+
3+
* [Playground Link](/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6ImphdmFzY3JpcHQiLCJxdWVyeSI6ImltcG9ydCAkQSBmcm9tICdhbmltZWpzJyIsInJld3JpdGUiOiJpbXBvcnQgeyBhbmltZSBhcyAkQSB9IGZyb20gJ2FuaW1lJyIsInN0cmljdG5lc3MiOiJzbWFydCIsInNlbGVjdG9yIjoiIiwiY29uZmlnIjoiaWQ6IG1pc3NpbmctY29tcG9uZW50LWRlY29yYXRvclxubWVzc2FnZTogWW91J3JlIHVzaW5nIGFuIEFuZ3VsYXIgbGlmZWN5Y2xlIG1ldGhvZCwgYnV0IG1pc3NpbmcgYW4gQW5ndWxhciBAQ29tcG9uZW50KCkgZGVjb3JhdG9yLlxubGFuZ3VhZ2U6IFR5cGVTY3JpcHRcbnNldmVyaXR5OiB3YXJuaW5nXG5ydWxlOlxuICBwYXR0ZXJuOlxuICAgIGNvbnRleHQ6ICdjbGFzcyBIaSB7ICRNRVRIT0QoKSB7ICQkJF99IH0nXG4gICAgc2VsZWN0b3I6IG1ldGhvZF9kZWZpbml0aW9uXG4gIGluc2lkZTpcbiAgICBwYXR0ZXJuOiAnY2xhc3MgJEtMQVNTICQkJF8geyAkJCRfIH0nXG4gICAgc3RvcEJ5OiBlbmRcbiAgICBub3Q6XG4gICAgICBoYXM6XG4gICAgICAgIHBhdHRlcm46ICdAQ29tcG9uZW50KCQkJF8pJ1xuY29uc3RyYWludHM6XG4gIE1FVEhPRDpcbiAgICByZWdleDogbmdPbkluaXR8bmdPbkRlc3Ryb3lcbmxhYmVsczpcbiAgS0xBU1M6XG4gICAgc3R5bGU6IHByaW1hcnlcbiAgICBtZXNzYWdlOiBcIlRoaXMgY2xhc3MgaXMgbWlzc2luZyB0aGUgZGVjb3JhdG9yLlwiXG4gIE1FVEhPRDpcbiAgICBzdHlsZTogc2Vjb25kYXJ5XG4gICAgbWVzc2FnZTogXCJUaGlzIGlzIGFuIEFuZ3VsYXIgbGlmZWN5Y2xlIG1ldGhvZC5cIlxubWV0YWRhdGE6XG4gIGNvbnRyaWJ1dGVkQnk6IHNhbXdpZ2h0dCIsInNvdXJjZSI6ImNsYXNzIE5vdENvbXBvbmVudCB7XG4gICAgbmdPbkluaXQoKSB7fVxufVxuXG5AQ29tcG9uZW50KClcbmNsYXNzIEtsYXNzIHtcbiAgICBuZ09uSW5pdCgpIHt9XG59In0=)
4+
5+
### Description
6+
7+
Angular lifecycle methods are a set of methods that allow you to hook into the lifecycle of an Angular component or directive.
8+
They must be used within a class that is decorated with the `@Component()` decorator.
9+
10+
### YAML
11+
12+
This rule illustrates how to use custom labels to highlight specific parts of the code.
13+
14+
15+
```yaml
16+
id: missing-component-decorator
17+
message: You're using an Angular lifecycle method, but missing an Angular @Component() decorator.
18+
language: TypeScript
19+
severity: warning
20+
rule:
21+
pattern:
22+
context: 'class Hi { $METHOD() { $$$_} }'
23+
selector: method_definition
24+
inside:
25+
pattern: 'class $KLASS $$$_ { $$$_ }'
26+
stopBy: end
27+
not:
28+
has:
29+
pattern: '@Component($$$_)'
30+
constraints:
31+
METHOD:
32+
regex: ngOnInit|ngOnDestroy
33+
labels:
34+
KLASS:
35+
style: primary
36+
message: "This class is missing the decorator."
37+
METHOD:
38+
style: secondary
39+
message: "This is an Angular lifecycle method."
40+
metadata:
41+
contributedBy: samwightt
42+
```
43+
44+
### Example
45+
46+
<!-- highlight matched code in curly-brace {lineNum} -->
47+
```ts {2}
48+
class NotComponent {
49+
ngOnInit() {}
50+
}
51+
52+
@Component()
53+
class Klass {
54+
ngOnInit() {}
55+
}
56+
```
57+
58+
### Contributed by
59+
[Sam Wight](https://github.com/samwightt).

0 commit comments

Comments
 (0)
Please sign in to comment.