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

Feat: Enforce custom provider types #24

Closed
thiagomini opened this issue Feb 3, 2024 · 1 comment · Fixed by #25
Closed

Feat: Enforce custom provider types #24

thiagomini opened this issue Feb 3, 2024 · 1 comment · Fixed by #25
Assignees
Labels
enhancement New feature or request

Comments

@thiagomini
Copy link
Contributor

thiagomini commented Feb 3, 2024

Description

We want to allow users to prefer one type of custom provider over the others. For instance, factory providers over value providers can significantly increase performance.

Acceptance Criteria

Given the options below:

// ...
rules: {
  '@trilon/enforce-custom-provider-type': [ 
   'warn', {  
     prefer: 'factory'
   }
  ]
}

Then, the following code will be considered Invalid:

const customValueProvider: Provider = {
  provide: 'TOKEN',
  useValue: 'some-value' // ⚠️ provider is not of type "factory"
}

const customClassProvider: Provider = {
  provide: AbstractClass,
  useClass: SomeClass  // ⚠️ provider is not of type "factory"
}

And the following code is considered Valid:

const factoryProvider: Provider = {
  provide: 'TOKEN',
  useFactory: () => 'some-value'
}
@thiagomini thiagomini added the enhancement New feature or request label Feb 3, 2024
@thiagomini thiagomini self-assigned this Feb 3, 2024
@thiagomini
Copy link
Contributor Author

@tuxmachine I'm wondering what we could use to determine that an object is a provider, @tuxmachine 🤔 Maybe we should check for the explicit "Provider" type from Nest? Otherwise, I fear this might get some false-positives from other objects that are not providers

@thiagomini thiagomini changed the title Feat: Feat: Enforce custom provider types Feb 3, 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

Successfully merging a pull request may close this issue.

1 participant