palantir / tslint-react

:orange_book: Lint rules related to React & JSX for TSLint.
Apache License 2.0
749 stars 76 forks source link

jsx-use-translation-function overlooks ternary expressions #155

Closed karol-majewski closed 5 years ago

karol-majewski commented 6 years ago

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
  }
}
adidahiya commented 5 years ago

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.