Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: (sort-classes) Add custom-groups to sorting capabilities #145

Open
2 tasks done
Bengejd opened this issue May 6, 2024 · 0 comments
Open
2 tasks done

Feature: (sort-classes) Add custom-groups to sorting capabilities #145

Bengejd opened this issue May 6, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Bengejd
Copy link

Bengejd commented May 6, 2024

What rule do you want to change?

perfectionist/sort-classes

Describe the problem

It would be nice if we could include custom groups similar to perfectionist/sort-objects. Mainly the issue that I am trying to solve is ensuring that Angular Dependency Injections are sorted to the top of the class they are being injected in.

Code example

Which used to look like this before the inject syntax came out:

export class ExampleComponent {
  public user = this.authService.user;

  constructor(private readonly authService: AuthService) {
  }
}

Becomes something like this:

export class ExampleComponent {
  public user = this.authService.user;
  private readonly authService = inject(AuthService);
}

However, this leads to an error similar to #118. If you are accessing the injected dependency before initialization (due to it's sorting order in the component).

Ideally, it would become this instead:

export class ExampleComponent {
  private readonly authService = inject(AuthService);
  public user = this.authService.user;

}

Additional comments

While this issue is Angular specific, I think the implications of being able to create a custom group would solve this issue, as well as other issues that users could potentially face down the line. This would also help prevent a growing complexity when it comes to adding additional groups to the sorter.

Validations

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@Bengejd Bengejd added the enhancement New feature or request label May 6, 2024
@Bengejd Bengejd changed the title Feature: (fill in) Feature: (sort-classes) Add custom-groups to sorting capabilities May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant