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

eslint-plugin-i18next

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-i18next - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

63

lib/rules/no-literal-string.js

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

const {
parserServices,
options: [option]

@@ -54,3 +55,3 @@ } = context;

const calleeWhitelists = generateCalleeWhitelists(option);
const message = 'disallow literal string';
//----------------------------------------------------------------------

@@ -81,3 +82,3 @@ // Helpers

//----------------------------------------------------------------------
return {
const scriptVisitor = {
Literal(node) {

@@ -97,4 +98,8 @@ if (typeof node.value === 'string') {

case 'Property': {
// if node is key of property, skip
if (parent.key === node) return;
// name if key is Identifier; value if key is Literal
// dont care whether if this is computed or not
if (isUpperCase(parent.key.name)) return;
if (isUpperCase(parent.key.name || parent.key.value)) return;
break;

@@ -105,10 +110,7 @@ }

default:
const LOOK_UP_LIMIT = 3;
const ancestors = context.getAncestors(node);
for (
let i = ancestors.length - 1;
i > ancestors.length - 1 - LOOK_UP_LIMIT && i > -1;
i--
) {
const temp = ancestors[i];
let LOOK_UP_LIMIT = 3;
let temp = parent;
while (temp && LOOK_UP_LIMIT > 0) {
LOOK_UP_LIMIT--;
if (temp.type === 'CallExpression') {

@@ -118,2 +120,3 @@ if (isValidFunctionCall(temp)) return;

}
temp = temp.parent;
}

@@ -125,6 +128,42 @@ break;

if (match(trimed)) return;
context.report({ node, message: 'disallow literal string' });
context.report({
node,
message,
fix(fixer) {
return fixer.replaceText(node, `i18next.t('${node.value}')`);
}
});
}
}
};
return (
(parserServices.defineTemplateBodyVisitor &&
parserServices.defineTemplateBodyVisitor(
{
VText(node) {
const trimed = node.value.trim();
if (!trimed) return;
if (match(trimed)) return;
context.report({
node,
message,
fix(fixer) {
return fixer.replaceText(
node,
node.value.replace(
/^(\s*)(.+?)(\s*)$/, // keep spaces
"$1{{i18next.t('$2')}}$3"
)
);
}
});
},
'VExpressionContainer Literal'(node) {
scriptVisitor.Literal(node);
}
},
scriptVisitor
)) ||
scriptVisitor
);
}

@@ -131,0 +170,0 @@ };

2

package.json
{
"name": "eslint-plugin-i18next",
"version": "1.0.5",
"version": "1.1.0",
"description": "ESLint plugin for i18n",

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

@@ -41,4 +41,6 @@ /**

{ code: 'var A_B = "world";' },
{ code: 'var a = {["A_B"]: "hello world"};' },
{ code: 'var a = {[A_B]: "hello world"};' },
{ code: 'var a = {A_B: "hello world"};' }
{ code: 'var a = {A_B: "hello world"};' },
{ code: 'var a = {foo: "FOO"};' }
],

@@ -49,4 +51,5 @@

{ code: 'const a = call("Ffo");', errors },
{ code: 'var a = {foo: "bar"};', errors },
{ code: 'const a = "afoo";', options: [{ ignore: ['^foo'] }], errors }
]
});
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