I18n: Add lint rule to enforce correct i18n imports (#56487)

* I18n: Add lint rule to enforce correct i18n imports

* ignore in gui wrapper
This commit is contained in:
Josh Hunt 2022-10-07 11:46:28 +01:00 committed by GitHub
parent 74c809f544
commit 891f9c00a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 5 deletions

View File

@ -20,13 +20,18 @@
}
],
"no-restricted-imports": [
"warn",
"error",
{
"paths": [
{
"name": "react-redux",
"importNames": ["useDispatch", "useSelector"],
"message": "Please import from app/types instead."
},
{
"name": "react-i18next",
"importNames": ["Trans", "t"],
"message": "Please import from app/core/internationalization instead"
}
]
}

View File

@ -1,6 +1,18 @@
{
"rules": {
"no-restricted-imports": ["error", { "patterns": ["@grafana/runtime", "@grafana/data/*", "@grafana/ui", "@grafana/e2e"] }]
"no-restricted-imports": [
"error",
{
"patterns": ["@grafana/runtime", "@grafana/data/*", "@grafana/ui", "@grafana/e2e"],
"paths": [
{
"name": "react-i18next",
"importNames": ["Trans", "t"],
"message": "Please import from grafana-ui/src/utils/i18n instead"
}
]
}
]
},
"overrides": [
{

View File

@ -1,6 +1,6 @@
import i18next from 'i18next';
import React from 'react';
import { Trans as I18NextTrans, initReactI18next } from 'react-i18next';
import { Trans as I18NextTrans, initReactI18next } from 'react-i18next'; // eslint-disable-line no-restricted-imports
// We want to translate grafana-ui without introducing any breaking changes for consumers
// who use grafana-ui outside of grafana (such as grafana.com self serve). The other struggle

View File

@ -1,6 +1,6 @@
import i18n, { BackendModule, ResourceKey } from 'i18next';
import React from 'react';
import { Trans as I18NextTrans, initReactI18next } from 'react-i18next';
import { Trans as I18NextTrans, initReactI18next } from 'react-i18next'; // eslint-disable-line no-restricted-imports
import { DEFAULT_LOCALE, ENGLISH_US, FRENCH_FRANCE, SPANISH_SPAIN, PSEUDO_LOCALE, VALID_LOCALES } from './constants';
@ -21,7 +21,6 @@ const loadTranslations: BackendModule = {
return callback(new Error('No message loader available for ' + language), null);
}
// TODO: namespace??
const messages = await loader();
callback(null, messages);
},