jonaskello/tslint-immutable

readonly-keyword does not support parameter properties

ulrichb opened this issue · 2 comments

Parameter properties: https://www.typescriptlang.org/docs/handbook/classes.html#parameter-properties

Example:

export class SomeClass {

    prop1: string | undefined; // Here it works ("A readonly modifier is required")
    public prop2: string | undefined; // Here it works ("A readonly modifier is required")
    readonly prop3: string | undefined;

    private constructor(
        public propA: string, // <- False negative
        readonly propB: string,
        private propC: string, // <- False negative
        private readonly propD: string,
    ) {
        // suppress unused private warnings:
        console.info(this.propC, this.propD);
    }
}

I guess the places marked with "False negative" is where you expect to get a warning about readonly but do not get one? I agree that it would make sense if we had warnings there too. A PR to fix this would certainly be accepted. (For me this has relatively low priority as I use the no-class rule).

Btw, we are porting all rules here to eslint in the eslint-plugin-ts-immutable repo. The readonly-keyword rule is already ported so you might want to file the same issue over there in order to get it fixed in the eslint version. There is an experimental 0.1.0 version on npm that you can test but expect breaking changes to come.

@jonaskello Implemented it in the eslint repo (see PR).