Skip to content

Commit

Permalink
feat(eslint-plugin): [sort-lifecycle-methods] add rule (#1320)
Browse files Browse the repository at this point in the history
  • Loading branch information
Friendseeker committed Sep 16, 2023
1 parent bb171d4 commit 47f7975
Show file tree
Hide file tree
Showing 7 changed files with 614 additions and 1 deletion.
381 changes: 381 additions & 0 deletions packages/eslint-plugin/docs/rules/sort-lifecycle-methods.md
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>
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/configs/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@angular-eslint/prefer-standalone-component": "error",
"@angular-eslint/relative-url-prefix": "error",
"@angular-eslint/require-localize-metadata": "error",
"@angular-eslint/sort-lifecycle-methods": "error",
"@angular-eslint/sort-ngmodule-metadata-arrays": "error",
"@angular-eslint/use-component-selector": "error",
"@angular-eslint/use-component-view-encapsulation": "error",
Expand Down
Loading

0 comments on commit 47f7975

Please sign in to comment.