-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-plugin): [sort-lifecycle-methods] add rule (#1320)
- Loading branch information
1 parent
bb171d4
commit 47f7975
Showing
7 changed files
with
614 additions
and
1 deletion.
There are no files selected for viewing
381 changes: 381 additions & 0 deletions
381
packages/eslint-plugin/docs/rules/sort-lifecycle-methods.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,381 @@ | ||
<!-- | ||
DO NOT EDIT. | ||
This markdown file was autogenerated using a mixture of the following files as the source of truth for its data: | ||
- ../../src/rules/sort-lifecycle-methods.ts | ||
- ../../tests/rules/sort-lifecycle-methods/cases.ts | ||
In order to update this file, it is therefore those files which need to be updated, as well as potentially the generator script: | ||
- ../../../../tools/scripts/generate-rule-docs.ts | ||
--> | ||
|
||
<br> | ||
|
||
# `@angular-eslint/sort-lifecycle-methods` | ||
|
||
Ensures that lifecycle methods are declared in order of execution | ||
|
||
- Type: problem | ||
|
||
<br> | ||
|
||
## Rule Options | ||
|
||
The rule does not have any configuration options. | ||
|
||
<br> | ||
|
||
## Usage Examples | ||
|
||
> The following examples are generated automatically from the actual unit tests within the plugin, so you can be assured that their behavior is accurate based on the current commit. | ||
<br> | ||
|
||
<details> | ||
<summary>❌ - Toggle examples of <strong>incorrect</strong> code for this rule</summary> | ||
|
||
<br> | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@angular-eslint/sort-lifecycle-methods": [ | ||
"error" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
#### ❌ Invalid Code | ||
|
||
```ts | ||
@Component() | ||
class Test { | ||
ngOnInit(): void {} | ||
ngOnChanges(): void {} | ||
~~~~~~~~~~~ | ||
ngDoCheck(): void {} | ||
ngAfterContentInit(): void {} | ||
ngAfterContentChecked(): void {} | ||
ngAfterViewInit(): void {} | ||
ngAfterViewChecked(): void {} | ||
ngOnDestroy(): void {} | ||
doSomething(): void {} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
--- | ||
|
||
<br> | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@angular-eslint/sort-lifecycle-methods": [ | ||
"error" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
#### ❌ Invalid Code | ||
|
||
```ts | ||
@Component() | ||
class Test { | ||
ngOnChanges(): void {} | ||
ngOnInit(): void {} | ||
ngAfterContentInit(): void {} | ||
ngAfterContentChecked(): void {} | ||
ngOnDestroy(): void {} | ||
ngAfterViewChecked(): void {} | ||
~~~~~~~~~~~~~~~~~~ | ||
doSomething(): void {} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
--- | ||
|
||
<br> | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@angular-eslint/sort-lifecycle-methods": [ | ||
"error" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
#### ❌ Invalid Code | ||
|
||
```ts | ||
@Component() | ||
class Test { | ||
ngDoCheck(): void {} | ||
ngAfterContentInit(): void {} | ||
ngOnDestroy(): void {} | ||
ngAfterContentChecked(): void {} | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
ngAfterViewChecked(): void {} | ||
doSomething(): void {} | ||
doSomethingElse(): void {} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
--- | ||
|
||
<br> | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@angular-eslint/sort-lifecycle-methods": [ | ||
"error" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
#### ❌ Invalid Code | ||
|
||
```ts | ||
@Component() | ||
class Test { | ||
ngOnInit(): void {} | ||
ngOnChanges(): void {} | ||
~~~~~~~~~~~ | ||
} | ||
``` | ||
|
||
</details> | ||
|
||
<br> | ||
|
||
--- | ||
|
||
<br> | ||
|
||
<details> | ||
<summary>✅ - Toggle examples of <strong>correct</strong> code for this rule</summary> | ||
|
||
<br> | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@angular-eslint/sort-lifecycle-methods": [ | ||
"error" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
#### ✅ Valid Code | ||
|
||
```ts | ||
@Component() | ||
class Test { | ||
ngOnChanges(): void {} | ||
ngOnInit(): void {} | ||
ngDoCheck(): void {} | ||
ngAfterContentInit(): void {} | ||
ngAfterContentChecked(): void {} | ||
ngAfterViewInit(): void {} | ||
ngAfterViewChecked(): void {} | ||
ngOnDestroy(): void {} | ||
doSomething(): void {} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
--- | ||
|
||
<br> | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@angular-eslint/sort-lifecycle-methods": [ | ||
"error" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
#### ✅ Valid Code | ||
|
||
```ts | ||
@Component() | ||
class Test { | ||
ngOnChanges(): void {} | ||
ngOnInit(): void {} | ||
ngAfterContentInit(): void {} | ||
ngAfterContentChecked(): void {} | ||
ngAfterViewChecked(): void {} | ||
ngOnDestroy(): void {} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
--- | ||
|
||
<br> | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@angular-eslint/sort-lifecycle-methods": [ | ||
"error" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
#### ✅ Valid Code | ||
|
||
```ts | ||
@Component() | ||
class Test { | ||
ngOnChanges(): void {} | ||
ngOnInit(): void {} | ||
ngAfterContentInit(): void {} | ||
ngAfterContentChecked(): void {} | ||
ngAfterViewChecked(): void {} | ||
ngOnDestroy(): void {} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
--- | ||
|
||
<br> | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@angular-eslint/sort-lifecycle-methods": [ | ||
"error" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
#### ✅ Valid Code | ||
|
||
```ts | ||
@Component() | ||
class Test { | ||
ngDoCheck(): void {} | ||
ngAfterContentInit(): void {} | ||
ngAfterContentChecked(): void {} | ||
ngAfterViewChecked(): void {} | ||
doSomething(): void {} | ||
doSomethingElse(): void {} | ||
doSomethingElseAgain(): void {} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
--- | ||
|
||
<br> | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@angular-eslint/sort-lifecycle-methods": [ | ||
"error" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
#### ✅ Valid Code | ||
|
||
```ts | ||
@Component() | ||
class Test { | ||
ngOnInit(): void {} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
--- | ||
|
||
<br> | ||
|
||
#### Default Config | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"@angular-eslint/sort-lifecycle-methods": [ | ||
"error" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
<br> | ||
|
||
#### ✅ Valid Code | ||
|
||
```ts | ||
@Component() | ||
class Test {} | ||
``` | ||
|
||
</details> | ||
|
||
<br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.