palantir / tslint-react

:orange_book: Lint rules related to React & JSX for TSLint.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jsx-use-translation-function overlooks ternary expressions

karol-majewski opened this issue · comments

Hello and thank you for your work. I believe the jsx-use-translation-function rule should look into what an expression evaluates to, not only for string literals alone.

Linted code

<div>{true ? 'Told ya' : 'Not really'}</div>

Expected result

String literals are disallowed as JSX. Use a translation function (jsx-use-translation-function)

Actual result

No error.

Configuration

{
  "extends": [
    "tslint-react"
  ],
  "rules": {
    "jsx-use-translation-function": true
  }
}
  • tslint: 5.9.1
  • tslint-react: 3.5.1

Static code analysis tools like TSLint avoid evaluating code for good reason: it is expensive and error-prone. I think this is out of scope.