Gathering detailed insights and metrics for eslint-plugin-format-message
Gathering detailed insights and metrics for eslint-plugin-format-message
npm install eslint-plugin-format-message
Typescript
Module System
Node Version
NPM Version
77
Supply Chain
92.2
Quality
79.4
Maintenance
100
Vulnerability
98.9
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
1,631,717
Last Day
722
Last Week
4,148
Last Month
15,881
Last Year
159,170
MIT License
205 Stars
496 Commits
37 Forks
5 Watchers
24 Branches
18 Contributors
Updated on Sep 25, 2024
Minified
Minified + Gzipped
Latest Version
6.2.4
Package Id
eslint-plugin-format-message@6.2.4
Unpacked Size
64.47 kB
Size
10.79 kB
File Count
26
NPM Version
lerna/3.13.3/node@v16.9.1+arm64 (darwin)
Node Version
16.9.1
Cumulative downloads
Total Downloads
Last Day
11.2%
722
Compared to previous day
Last Week
17.4%
4,148
Compared to previous week
Last Month
75.7%
15,881
Compared to previous month
Last Year
8.7%
159,170
Compared to previous year
5
1
format-message i18n specific rules for ESLint
Install ESLint and this plugin.
1npm install --save eslint eslint-plugin-format-message
Then add plugins
section to your ESLint configuration.
1{ 2 "plugins": [ 3 "format-message" 4 ] 5}
Configure the rules you want to use. These are the defaults.
1{ 2 "rules": { 3 "format-message/literal-pattern": 1, 4 "format-message/literal-locale": 1, 5 "format-message/no-identical-translation": 1, 6 "format-message/no-invalid-pattern": 2, 7 "format-message/no-invalid-translation": 2, 8 "format-message/no-missing-params": [ 2, { "allowNonLiteral": true } ], 9 "format-message/no-missing-translation": 1, 10 "format-message/translation-match-params": 2 11 }, 12 "settings": { 13 "format-message": { 14 } 15 } 16}
Here is another example configuration.
1{ 2 "rules": { 3 "format-message/literal-pattern": 2, 4 "format-message/literal-locale": 2, 5 "format-message/no-identical-translation": 0, 6 "format-message/no-invalid-pattern": 2, 7 "format-message/no-invalid-translation": 2, 8 "format-message/no-missing-params": [ 2, { allowNonLiteral: false } ], 9 "format-message/no-missing-translation": 1, 10 "format-message/translation-match-params": 2 11 }, 12 "settings": { 13 "format-message": { 14 "generateId": "normalized", 15 "sourceLocale": "en-GB", 16 "translations": "./locales" 17 } 18 } 19}
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.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 5/10 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
123 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-17
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More