ni / ni/javascript-styleguide

Consider enabling @angluar-eslint/prefer-inject

Open
#190 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
JavaScript
Stars
9
Forks
11
PR merge metrics
No merged PRs in 30d

Description

This rule was added to angluar-eslint's recommended ruleset as of v20. We had to disable it in our configuration, due to required effort to update existing source, but we should revisit that descision.

Angular provides an automatic migration (ng generate @angular/core:inject) to replace constructor arguments with inject()-initialized class fields, but it's not smart. It puts new the fields immediately before the constructor, but they need to be declared/initialized before any other field initializers that depend on them. For automation purposes (and probably as general convention), that means we want them declared at the top of the class. @typescript-eslint/member-ordering doesn't have an automated fix-up, nor the ability to take initializers into acount . The Perfectionist sort-classes rule has both of those, and I made an attempt to use that rule instead. We can configure their rule to enforce (and automate) fields initialized with inject(... being put before all other fields. But I wasn't able to prevent it from auto-sorting getter/setter pairs with different access modifiers apart from each other (which violates the grouped-accessor-pairs rule).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing ESLint configuration, the @angular/core:inject migration, and the Perfectionist sort-classes and grouped-accessor-pairs rules mentioned in the issue. Determine whether the project can enable @angular-eslint/prefer-inject while keeping dependent inject fields ordered correctly and accessor pairs grouped; done means a documented configuration choice with the required source migration or a confirmed alternative.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, eslint, typescript
Domain
developer-experience, tooling
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.