- What language is this for?
TypeScript / JavaScript - Which rule?
S3854: “super()” should be invoked appropriately - Are you using
- SonarQube 10.4
- SonarLint 4.4.2 (Visual Studio Code) (not connected)
S3854 does not seem to understand class expressions which we use for mixins:
declare type ConstructorFunction<T> = new (...args: any[]) => T;
declare type AbstractConstructorFunction<T> = abstract new (...args: any[]) => T;
type SomeBaseClass = {};
interface IMyAddedProperties { someNewField: string; }
export function MyAddedPropertiesMixin<T extends SomeBaseClass>(Base: AbstractConstructorFunction<T>) {
class MyPartialClass extends (Base as AbstractConstructorFunction<SomeBaseClass>) implements IMyAddedProperties {
someNewField: string;
constructor(o?: any) {
super(o); // <-- Unexpected 'super()' because 'super' is not a constructor.sonarlint(typescript:S3854)
this.someNewField = "test";
}
}
return MyPartialClass as unknown as ConstructorFunction<T & IMyAddedProperties>;
}
Note that both Visual Studio and Visual Studio Code are able to navigate from the super
call to AbstractConstructorFunction<T>
.