Search code examples
javascriptangulartypescripttslintcode-standards

How do I enforce the opposite of whitespace check-branch in TSLint?


I would like to enforce the opposite of what whitespace check-branch does. So instead of having this:

if (condition) {
    return true;
} else {
    return false;
}

I would like to enforce this:

if(condition) {
    return true;
} else {
    return false;
}

This may seem strange to most people but this is how our team likes to code.

I tried doing this:

"whitespace": [
    false,
    "check-branch"
]

But doesn't give me the desired result. Does anyone know if it is possible to enforce our way of coding?


Solution

  • This is not supported AFAIK. I'd suggest looking into creating a rule for your company yourself.

    See https://palantir.github.io/tslint/develop/custom-rules/ for an article on how to add rules. Here's whitespace rule implementation as a reference: https://github.com/palantir/tslint/blob/master/src/rules/whitespaceRule.ts