Skip to content

Feat: Add lint rule to enforce modules to have register/registerAsync and/or forRoot/forRootAsync #28

@tolgap

Description

@tolgap

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: [/* ... */],
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions