Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
eslint-plugin-format-message
Advanced tools
format-message i18n specific rules for ESLint
Install ESLint and this plugin.
npm install --save eslint eslint-plugin-format-message
Then add plugins
section to your ESLint configuration.
{
"plugins": [
"format-message"
]
}
Configure the rules you want to use. These are the defaults.
{
"rules": {
"format-message/literal-pattern": 1,
"format-message/literal-locale": 1,
"format-message/no-identical-translation": 1,
"format-message/no-invalid-pattern": 2,
"format-message/no-invalid-translation": 2,
"format-message/no-missing-params": [ 2, { "allowNonLiteral": true } ],
"format-message/no-missing-translation": 1,
"format-message/translation-match-params": 2
},
"settings": {
"format-message": {
}
}
}
Here is another example configuration.
{
"rules": {
"format-message/literal-pattern": 2,
"format-message/literal-locale": 2,
"format-message/no-identical-translation": 0,
"format-message/no-invalid-pattern": 2,
"format-message/no-invalid-translation": 2,
"format-message/no-missing-params": [ 2, { allowNonLiteral: false } ],
"format-message/no-missing-translation": 1,
"format-message/translation-match-params": 2
},
"settings": {
"format-message": {
"generateId": "normalized",
"sourceLocale": "en-GB",
"translations": "./locales"
}
}
}
For the format-message
tools to replace messages with their translations at build time, as well as optimize runtime performance, the message pattern must be a string literal.
By default this is a warning, since the message can still be translated at run time, if you have configured properly with formatMessage.setup(options)
.
If a locale is specified in formatMessage
calls, it must be a literal string so that the translation can be replaced at build time. Most of the time, no locale should be specified, and the current locale is used.
By default this is a warning, since the message can still be translated at run time, if you have configured properly with formatMessage.setup(options)
.
If translation settings are provided, the translation of each messages should be distinct from the default message in the source code. The exception is if the translation locale matches the source locale, then identical translation is allowed. (For example "en-US" and "en-AU" are allowed to be identical to a source in "en-US".)
By default this is a warning, since it often means the message wasn't actually translated.
The message patterns must be valid ICU Message Format syntax, or the call to formatMessage
will throw an error. This rule allows you to fix these errors early.
Since these problems will cause an error to be thrown at run time, by default this rule reports an error.
If translation settings are provided, the translations must be valid ICU Message Format syntax, or the call to formatMessage
will throw an error. This rule allows you to fix these errors early.
Since these problems will cause an error to be thrown at run time, by default this rule reports an error.
If a message pattern requires parameters, missing those parameters will cause an error or malformed message at run time. This rule helps you to quickly find and fix these problems.
Since these problems can cause errors, by default this rule reports an error.
This rule takes an object for an argument. If the object has a truthy allowNonLiteral
property, then passing a variable instead of an object literal is assumed to have all the necessary parameters.
Parameters support nested data objects. To prevent any issues, it's recommended that you avoid using object keys with .
if you're using nested data.
If translation settings are provided, each locale must have a translation for each message.
By default this is a warning, serving as a reminder to ensure all messages get translated.
If translation settings are provided, each translation must include the same placeholders found in the default message pattern found in the source code.
Since these problems can cause errors, by default this rule reports an error.
If a pattern or translation has a sub-message for a plural keyword that doesn't apply to the locale is used, the sub-message will never be displayed.
By default this is a warning, since no errors will occur when the message is used.
If a pattern or translation is missing a plural sub-message for a keyword that applies to the locale, the "other" sub-message will be used instead. Missing the "other" sub-message makes the message invalid, which is handled by other rules.
This recommended as a warning, since the "other" sub-message will be displayed, but by default is disabled.
You can configure settings for this plugin in a "format-message"
object in the "settings"
section of your eslint config. These settings inform the plugin where you store translations, how inferred keys are generated from default patterns, and what locale the default patterns are written in.
As in the example above, the following settings can be provided:
sourceLocale
specifies what locale the default patterns use in the source code.generateId
is one of literal
, normalized
, underscored
, or underscored_crc32
. This determines how to translate a default pattern to the key to lookup the translation.translations
is an object containing a property per locale. Each locale property is a object mapping keys to translations.
translations
may also string path, relative to the current working directory, indicating a module to require that matches the above description.
"translations": "./locales"
{ "en-US": { "course_8a63b4a3": "Course" }, "pt-BR": { "course_8a63b4a3": "Curso" } }
"course_8a63b4a3": { "message": "Course", "description": "An educational course." }
translations
may also be a string path to a module that matches the above description.
"translations": { "en-US": "./en.json", "pt-BR": "./pt-BR.json" }
{ "en-US": { "course_8a63b4a3": "Course", "quiz_e0dcce8f": "Quiz" } }
{ "pt-BR": { "course_8a63b4a3": "Curso", "quiz_e0dcce8f": "Questionário" } }
This software is free to use under the MIT license. See the LICENSE-MIT file for license text and copyright information.
FAQs
format-message i18n specific rules for ESLint
The npm package eslint-plugin-format-message receives a total of 1,713 weekly downloads. As such, eslint-plugin-format-message popularity was classified as popular.
We found that eslint-plugin-format-message demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.