Language: TypeScript
Rule: S107 (Functions should not have too many parameters)
SonarQube: Version 10.1 (build 73491)
SonarLint: 6.10.69538 on Visual Studio 2022 (NOT connected mode)
The rule’s description states the following:
The rule ignores constructors where parameters are all parameter properties:
class C { constructor( private param1: number, private param2: boolean, private param3: string, private param4: string[], private param5: number | string ) {} }
This seems to be tailored to dependency injection scenarios, which indeed is our use case (for reference, we use Aurelia 1.
This code (anonymized) triggers the rule:
constructor(
protected readonly propertyService1: PropertyService1,
protected readonly propertyService2: PropertyService2,
protected readonly propertyService3: PropertyService3,
protected readonly propertyService4: PropertyService4,
protected readonly propertyService5: PropertyService5,
protected readonly propertyService6: PropertyService6,
protected readonly propertyService7: PropertyService7,
protected readonly propertyService8: PropertyService8,
protected readonly propertyService9: PropertyService9,
transientService1: TransientService1,
transientService2: TransientService2
) {
this.initProperty1 = process1(transientService1);
this.initProperty2 = process2(transientService2);
}
We obtain every service via dependency injection, but the last 2 instead of being stored as properties are used to initialize other properties.
Since the exception esists, would there be any contraindications to extend it to cases when any or most (for some definition of most, obviously hard to quantify) parameters are properties?