Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-hss-i18n

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-hss-i18n - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

docs/rules/require-gettext-literal.md

25

docs/rules/no-liternal-interpolate.md
# Prevent calling interpolate on string literals (no-liternal-interpolate)
Please describe the origin of the rule here.
`I18n.interpolate()` by itself does not actually translate a string. However
many people mistakenly think that it does. This rule prevents you from calling
`interpolate` on a literal string. You should instead pass `interpolate`
a string that has already been translated by `I18n.gettext`.
## Rule Details
This rule aims to...
The following patterns are considered warnings:

@@ -14,3 +14,3 @@

// fill me in
I18n.interpolate('Some string %(foo)s', {foo: 'bar'});

@@ -23,16 +23,5 @@ ```

// fill me in
var someString = I18n.gettext('Some string %(foo)s');
I18n.interpolate(someString, {foo: 'bar'});
```
### Options
If there are any options, describe them here. Otherwise, delete this section.
## When Not To Use It
Give a short description of when it would be appropriate to turn off this rule.
## Further Reading
If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.

@@ -7,2 +7,4 @@ /**

var utils = require('../utils');
//------------------------------------------------------------------------------

@@ -26,24 +28,3 @@ // Rule Definition

// variables should be defined here
//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------
function isI18nMethodCall(node, methodName) {
return node &&
node.type === 'CallExpression' &&
node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
node.callee.object.name.toLowerCase() === 'i18n' &&
node.callee.property.name === methodName;
}
function getFirstArgument(node) {
return node &&
node.arguments &&
node.arguments[0];
}
//----------------------------------------------------------------------
// Public

@@ -54,5 +35,5 @@ //----------------------------------------------------------------------

CallExpression: function(node) {
if (isI18nMethodCall(node, 'interpolate')) {
var firstArg = getFirstArgument(node);
if (firstArg && firstArg.type === 'Literal') {
if (utils.isI18nMethodCall(node, 'interpolate')) {
var firstArg = utils.getFirstArgument(node);
if (utils.isPossiblyConcatenatedString(firstArg)) {
context.report(firstArg, 'Avoid calling interpolate on untranslated literal strings.')

@@ -59,0 +40,0 @@ }

{
"name": "eslint-plugin-hss-i18n",
"version": "0.0.1",
"version": "0.0.2",
"description": "Detect common errors when using I18n",

@@ -5,0 +5,0 @@ "keywords": [

@@ -39,3 +39,4 @@ # eslint-plugin-hss-i18n

"rules": {
"hss-i18n/no-interpolate-literal": "error"
"hss-i18n/no-interpolate-literal": "error",
"hss-i18n/require-gettext-literal": "error"
}

@@ -47,3 +48,6 @@ }

* `hss-i18n/no-interpolate-literal`: Prevent calling I1in.interpolate on untranslated string literals
* [`hss-i18n/no-interpolate-literal`](docs/rules/no-interpolate-litera.md):
Prevent calling I18n.interpolate on untranslated string literals
* [`hss-i18n/require-gettext-literal`](docs/rules/require-gettext-literal.ms):
Prevent calling I18n.gettext with anything other than a literal string.

@@ -50,0 +54,0 @@

@@ -25,2 +25,3 @@ /**

"I18n.interpolate(someVar);",
"I18n.interpolate([someVar, someOtherVar].join(' '));",
"otherObject.interpolate('foo');",

@@ -44,4 +45,11 @@ "I18n.gettext('Hello Jordan');"

}]
}
},
{
code: "I18n.interpolate('Hello ' + '%(name)s', {name: 'Jordan'});",
errors: [{
message: "Avoid calling interpolate on untranslated literal strings.",
type: "BinaryExpression"
}]
},
]
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc