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: Add lint rule to enforce modules to have register/registerAsync and/or forRoot/forRootAsync #28

Open
tolgap opened this issue Mar 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@tolgap
Copy link
Contributor

tolgap commented Mar 4, 2024

Description

We should detect whether module classes that return a DynamicModule are named register, registerAsync, forRoot or forRootAsync.

Acceptance Criteria

Incorrect:

@Module({})
export class ProductsModule {
  static create(options): DynamicModule { // ⚠️ `Dynamic module methods must be named `register/registerAsync` or `forRoot/forRootAsync`
    return {
      module: ProductsModule,
      imports: [TypeOrmModule.forFeature([Product]),
      providers: [/* ... */],
    }
  }

  static registerAsync(options): DynamicModule { // ✅ 
    return {
      module: ProductsModule,
      imports: [TypeOrmModule.forFeature([Product]),
      providers: [/* ... */],
    }
  }
}

Correct:

@Module({})
export class ProductsModule {
  static register(options): DynamicModule { // ✅ 
    return {
      module: ProductsModule,
      imports: [TypeOrmModule.forFeature([Product]),
      providers: [/* ... */],
    }
  }

  static registerAsync(options): DynamicModule { // ✅ 
    return {
      module: ProductsModule,
      imports: [TypeOrmModule.forFeature([Product]),
      providers: [/* ... */],
    }
  }
}
@tolgap tolgap added the enhancement New feature or request label Mar 4, 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