About typescript:S107, dependency injection and non-property parameters

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 {
   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:

    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?

Hey there.

Can you please upgrade to SonarLint for VS v6.16 and see if the issue persists?

I can confirm the issue is reported with SonarLint
Then again it is a correct report. I was just wondering if, since the exception exists, it would make sense to be extended.

Just asking to make sure we didn’t already think about an exception ourselves :wink:

I will flag this for some experts.

Hello M Gallesio,

We planned to add an exception for this: Fix FP S107 (`sonar-max-params`): in TS, when mixing parameter properties with parameters, only count the parameters · Issue #4014 · SonarSource/SonarJS · GitHub