Socket
Socket
Sign inDemoInstall

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 3.8.0 to 4.0.0

test.js

11

CHANGELOG.md

@@ -5,2 +5,13 @@ # Changelog

## [4.0.0](https://github.com/edvardchen/eslint-plugin-i18next/compare/v3.8.0...v4.0.0) (2020-06-28)
### ⚠ BREAKING CHANGES
* all patterns in ignoreCallee would be treated as regular expression
### Features
* allow regex in ignore and ignoreCallee ([0cfe340](https://github.com/edvardchen/eslint-plugin-i18next/commit/0cfe340)), closes [#19](https://github.com/edvardchen/eslint-plugin-i18next/issues/19)
## [3.8.0](https://github.com/edvardchen/eslint-plugin-i18next/compare/v3.7.0...v3.8.0) (2020-06-03)

@@ -7,0 +18,0 @@

92

lib/rules/no-literal-string.js

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

ignore: {
type: 'array',
items: {
type: 'string'
}
type: 'array'
// string or regexp
},

@@ -39,6 +37,4 @@ ignoreAttribute: {

ignoreCallee: {
type: 'array',
items: {
type: 'string'
}
type: 'array'
// string or regexp
},

@@ -71,3 +67,2 @@ ignoreProperty: {

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

@@ -81,2 +76,34 @@ //----------------------------------------------------------------------

const popularCallee = [
/^i18n(ext)?$/,
't',
'require',
'addEventListener',
'removeEventListener',
'postMessage',
'getElementById',
//
// ─── VUEX CALLEE ────────────────────────────────────────────────────────────────
//
'dispatch',
'commit',
// ────────────────────────────────────────────────────────────────────────────────
'includes',
'indexOf',
'endsWith',
'startsWith'
];
const validCalleeList = [
...popularCallee,
...((option && option.ignoreCallee) || [])
].map(item => {
if (item instanceof RegExp) {
return item;
}
// allow dot ahead
return new RegExp(`(^|\\.)${item}${item.endsWith('$') ? '' : '$'}`);
});
function isValidFunctionCall({ callee }) {

@@ -86,13 +113,7 @@ let calleeName = callee.name;

if (callee.type === 'MemberExpression') {
if (calleeWhitelists.simple.indexOf(callee.property.name) !== -1)
return true;
const sourceText = context.getSourceCode().getText(callee);
calleeName = `${callee.object.name}.${callee.property.name}`;
return calleeWhitelists.complex.indexOf(calleeName) !== -1;
}
if (calleeName === 'require') return true;
return calleeWhitelists.simple.indexOf(calleeName) !== -1;
return validCalleeList.some(item => {
return item.test(sourceText);
});
}

@@ -388,34 +409,1 @@

};
const popularCallee = [
'addEventListener',
'removeEventListener',
'postMessage',
'getElementById',
//
// ─── VUEX CALLEE ────────────────────────────────────────────────────────────────
//
'dispatch',
'commit',
// ────────────────────────────────────────────────────────────────────────────────
'includes',
'indexOf',
'endsWith',
'startsWith'
];
function generateCalleeWhitelists(option) {
const ignoreCallee = (option && option.ignoreCallee) || [];
const result = {
simple: ['i18n', 'i18next', ...popularCallee],
complex: ['i18n.t', 'i18next.t']
};
ignoreCallee.forEach(item => {
if (item.indexOf('.') !== -1) {
result.complex.push(item);
} else {
result.simple.push(item);
}
});
return result;
}
{
"name": "eslint-plugin-i18next",
"version": "3.8.0",
"version": "4.0.0",
"description": "ESLint plugin for i18n",

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

@@ -64,3 +64,11 @@ /**

{ code: 'const a = "absfoo";', options: [{ ignore: ['foo'] }] },
{ code: 'const a = "fooabc";', options: [{ ignore: ['^foo'] }] },
{ code: 'const a = "fooabc";', options: [{ ignore: [/^foo/] }] },
{
code: 'foo.bar("taa");',
options: [
{
ignoreCallee: [/foo.+/]
}
]
},
{ code: 'const a = "FOO";' },

@@ -114,2 +122,3 @@ { code: 'var A_B = "world";' },

invalid: [
{ code: 'i18nextXt("taa");', errors },
{ code: 'a + "b"', errors },

@@ -116,0 +125,0 @@ {

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