-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f22c2f7
commit f5cd1da
Showing
9 changed files
with
211 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# no-expression-in-message | ||
|
||
Check that `` t` ` `` doesn't contain member or function expressions like `` t`Hello ${user.name}` `` or `` t`Hello ${getName()}` `` | ||
|
||
Such expressions would be transformed to its index position such as `Hello {0}` which gives zero to little context for translator. | ||
|
||
Use a variable identifier instead. | ||
|
||
```jsx | ||
// nope ⛔️ | ||
t`Hello ${user.name}` // => 'Hello {0}' | ||
|
||
// ok ✅ | ||
const userName = user.name | ||
t`Hello ${userName}` // => 'Hello {userName}' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# no-single-tag-to-translate | ||
|
||
> [!TIP] | ||
> This rule is included into the `lingui/recommended` config | ||
Ensures `<Trans></Trans>` isn't wrapping a single element unnecessarily | ||
|
||
```jsx | ||
// nope ⛔️ | ||
<Trans><strong>Foo bar</strong></Trans> | ||
|
||
// ok ✅ | ||
<strong><Trans>Foo bar</Trans></strong> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# no-single-variables-to-translate | ||
|
||
> [!TIP] | ||
> This rule is included into the `lingui/recommended` config | ||
Doesn't allow single variables without text to translate like `<Trans>{variable}</Trans>` or `` t`${variable}` `` | ||
|
||
Such expression would pollute message catalog with useless string which has nothing to translate. | ||
|
||
```jsx | ||
// nope ⛔️ | ||
<Trans>{user}</Trans> | ||
|
||
// ok ✅ | ||
<Trans>Hello {user}</Trans> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# no-trans-inside-trans | ||
|
||
> [!TIP] | ||
> This rule is included into the `lingui/recommended` config | ||
Check that no `Trans` inside `Trans` components. | ||
|
||
```jsx | ||
// nope ⛔️ | ||
<Trans>Hello <Trans>World!</Trans></Trans> | ||
|
||
// ok ✅ | ||
<Trans>Hello World!</Trans> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# no-unlocalized-strings | ||
|
||
Check that code doesn't contain strings/templates/jsxText what should be wrapped into `<Trans>` or `i18n` | ||
|
||
> [!IMPORTANT] | ||
> This rule might use type information. You can enable it with `{useTsTypes: true}` | ||
## Options | ||
|
||
### useTsTypes | ||
|
||
Use additional Typescript type information. Requires [typed linting](https://typescript-eslint.io/getting-started/typed-linting/) to be setup. | ||
|
||
### ignore | ||
|
||
The `ignore` option specifies exceptions not to check for | ||
literal strings that match one of regexp patterns. | ||
|
||
Examples of correct code for the `{ "ignore": ["rgba"] }` option: | ||
|
||
```jsx | ||
/*eslint lingui/no-unlocalized-strings ["error", {"ignore": ["rgba"]}]*/ | ||
const a = <div color="rgba(100, 100, 100, 0.4)"></div> | ||
``` | ||
|
||
### ignoreFunction | ||
|
||
The `ignoreFunction` option specifies exceptions not check for | ||
function calls whose names match one of regexp patterns. | ||
|
||
Examples of correct code for the `{ "ignoreFunction": ["showIntercomMessage"] }` option: | ||
|
||
```js | ||
/*eslint lingui/no-unlocalized-strings: ["error", { "ignoreFunction": ["showIntercomMessage"] }]*/ | ||
const bar = showIntercomMessage('Please, write me') | ||
``` | ||
|
||
### ignoreAttribute | ||
|
||
The `ignoreAttribute` option specifies exceptions not to check for JSX attributes that match one of ignored attributes. | ||
|
||
Examples of correct code for the `{ "ignoreAttribute": ["style"] }` option: | ||
|
||
```jsx | ||
/*eslint lingui/no-unlocalized-strings: ["error", { "ignoreAttribute": ["style"] }]*/ | ||
const element = <div style={{ margin: '1rem 2rem' }} /> | ||
``` | ||
|
||
By default, the following attributes are ignored: `className`, `styleName`, `type`, `id`, `width`, `height` | ||
|
||
### ignoreProperty | ||
|
||
The `ignoreProperty` option specifies property names not to check. | ||
|
||
Examples of correct code for the `{ "ignoreProperty": ["text"] }` option: | ||
|
||
```jsx | ||
/*eslint lingui/no-unlocalized-strings: ["error", { "ignoreProperty": ["text"] }]*/ | ||
const test = { text: 'This is ignored' } | ||
``` | ||
|
||
By default, the following properties are ignored: `className`, `styleName`, `type`, `id`, `width`, `height` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# t-call-in-function | ||
|
||
> [!TIP] | ||
> This rule is included into the `lingui/recommended` config | ||
Check that `t` calls are inside `function`. They should not be at the module level otherwise they will not react to language switching. | ||
|
||
```jsx | ||
import { t } from '@lingui/macro' | ||
|
||
// nope ⛔️ | ||
const msg = t`Hello world!` | ||
|
||
// ok ✅ | ||
function getGreeting() { | ||
return t`Hello world!` | ||
} | ||
``` | ||
|
||
Check the [Lingui Docs](https://lingui.dev/tutorials/react-patterns#translations-outside-react-components) for more info. |
Oops, something went wrong.