tslint-eslint-rules icon indicating copy to clipboard operation
tslint-eslint-rules copied to clipboard

brace-style doesn't work for classes

Open cshaa opened this issue 7 years ago • 0 comments
trafficstars

The rule brace-style does not affect the braces around the class body – see the fixed bug at eslint/eslint#7608.

How to reproduce

/* tslint brace-style: ["error", "allman"] */

class Foo {
}

Expected

  • tslint throws an error
  • if I change the code to Allman, it should be ok

Actual

  • no error was thrown
  • if I change the code to Allman, tslint throws an error

I haven't done a PR because I couldn't find the Typescript API specs, but it should be relatively easy to fix. If I understand it correctly, we need to add something like this to the rule definition:

visitClassDeclaration(node: ts.ClassDeclaration) {
   let block = somehowGetTheBlock(node);
   this.visitBlock(block);
}

visitClassExpression(node: ts.ClassExpression) {
   let block = somehowGetTheBlock(node);
   this.visitBlock(block);
}

cshaa avatar Mar 08 '18 16:03 cshaa