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

Rule Ideas #1

Open
16 of 25 tasks
WhosNickDoglio opened this issue Feb 18, 2023 · 2 comments
Open
16 of 25 tasks

Rule Ideas #1

WhosNickDoglio opened this issue Feb 18, 2023 · 2 comments

Comments

@WhosNickDoglio
Copy link
Owner

WhosNickDoglio commented Feb 18, 2023

Vanilla Dagger

  • Components must be abstract
  • Favor Constructor injection over member injection
  • Avoid unnecessary Provides methods and just constructor injection
  • Favor Binds over Provides
  • Methods annotated with @Binds must be abstract
  • @Provides method should be static
  • If a Factory or Builder is present in a Component make sure it's called.
  • If a class has @Provides or @Binds methods make sure it's annotated with @Module.
  • valid provision methods
  • val member injection methods
  • @Binds return type is super type of impl
  • Suggest using KSP over KAPT

Anvil

  • Use @MergeX or ContributesTo annotations on Component and Subcomponents
  • Use @ContributesTo annotations on each Module
  • Favor @ContributesBinding over @Binds
  • @ContributesBinding has a super class
  • Cant be used in Java
  • Warn not compatible with KSP Dagger yet

Hilt

  • Use @InstallIn annotations on each Module
  • Use @InstallBinding over @Binds (Add InstallBinding google/dagger#3516)
  • Don't forget hilt annotations (@HiltAndroidApp, @AndroidEntryPoint, @HiltViewModel)
  • use by hiltViewModel() for getting viewModels from DI Graph
  • @EntryPoint can only be applied to interfaces
  • Missing @InstallIn
  • Suggest using KSP over KAPT

Inspiration / Resources

@WhosNickDoglio
Copy link
Owner Author

WhosNickDoglio commented Oct 2, 2023

Block Impl from being injected if it used @ContributesBinding

Logic might look like something like this:

  • Check if class has an @Inject annotation
  • if it does, check if the constructor parameters are abstract
  • if a parameter is not abstract check if it has a super that's not Any or Object
  • Complain if it does

This might have a large amount of false positives but we'll see 🤷

Maybe this is better as SPI check?

@WhosNickDoglio
Copy link
Owner Author

flag incorrect usage of @BindsInstance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant