darraghoriordan / eslint-plugin-nestjs-typed

Some eslint rules for working with NestJs projects
http://www.darraghoriordan.com
174 stars 34 forks source link

sort-module-metadata-arrays breaks factory provider injection #198

Open fpd007 opened 4 months ago

fpd007 commented 4 months ago

The sort-module-metadata-arrays rule break the factory provider injection.

The rule suggests (or auto-fixes) to change the order of the inject array, but it does not change the order of the useFactory arguments which need to be in the same order.

@Module({
    providers: [
        {
            provide: 'EXAMPLE_PROVIDER',
            useFactory: (bProvider: BProvider, aProvider: AProvider): unknown => {
                return new WhatEver();
            },
        // autofix would swap the order here but leave the useFactory above as is, which silently breaks code
        inject: [BProvider, AProvider],
        }
    ]
})
darraghoriordan commented 3 months ago

nice find. yea that would break things for sure.

feel free to submit a PR to fix or just disable the rule for now