eslint-plugin-preact-i18n
This is an eslint plugin for applications using the preact-i18n library.
Installation
npm i -D eslint-plugin-preact-i18n
Rules
- preact-i18n/no-missing-template-field: Errors if
fields
attribute is not provided to <Text/>
or <MarkupText/>
component when the value of the key contains template fields in their values. Also shows an error when fields
is supplied but unneeded by the localized string. - preact-i18n/no-text-as-children: Verify that you have no text node children in your preact code.
- preact-i18n/no-text-as-attribute: Verify that you have no text in some attributes in your react components. List of attributes provided in the config.
- preact-i18n/no-unknown-key: Verify that all translation keys you use are present in your defined translation files.
Config
You have to add the following lines in your .eslintrc
file to configure this plugin:
"plugins": [
"preact-i18n"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"settings": {
"preact-i18n": {
"languageFiles": [
{
"name": "en",
"path": "i18n/en.json"
}
],
"scopes": ['', 'foo-component'],
"translationsCacheTTL": 300
"ignoreFiles": "**/*.spec.js",
"textComponents": [
{ "nameRegex": '^(?:Alt)?Text$' },
{ "nameRegex": '^Dialog$', "id": 'title', "plural": 'count', "fields": 'data' }
],
"markupTextComponents": [
{ "nameRegex": "^MarkupText$" },
{ "nameRegex": "^DialogMarkup$", "id": "title", "plural": "count", "fields": "data" }
],
"withTextRegex": "^withText(?:Alias)?$"
}
},
"rules": {
"preact-i18n/no-missing-template-field": "error",
"preact-i18n/no-text-as-attribute": "error",
"preact-i18n/no-text-as-children": "error",
"preact-i18n/no-unknown-key": "error"
}
License