jonaskello / tslint-immutable

TSLint rules to disable mutation in TypeScript.
MIT License
417 stars 14 forks source link

"no-expression-statement" should allow super() call in constructors #147

Open karol-majewski opened 5 years ago

karol-majewski commented 5 years ago

Offending code

export class NullDereferenced extends Error {
  constructor(readonly message: string = 'This value was promised to never be undefined.') {
    super(message);

    Object.setPrototypeOf(this, NullDereferenced.prototype);

    if ('captureStackTrace' in Error) { // wotan-disable-line no-useless-predicate
      Error.captureStackTrace(this, NullDereferenced);
    }
  }
}

Actual behavior

The super() call causes an error.

Using expressions to cause side-effects not allowed. (no-expression-statement)

Expected bahavior

No error. There is no way around that.

Possible heuristic

If the offending node is a CallExpression, and the inner expression is of type SuperKeyword, then the error should not be raised.

jonaskello commented 5 years ago

Yes, that seems reasonable to me and a PR could be accepted.

Btw, you may want to switch to eslint as tslint is being deprecated. See the new eslint-plugin-functional project which is a port of the rules in this repo to eslint. You should probably open the same issue over there too.