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 4.2.0 to 4.3.0

7

CHANGELOG.md

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

## [4.3.0](https://github.com/edvardchen/eslint-plugin-i18next/compare/v4.2.0...v4.3.0) (2020-07-21)
### Features
* add onlyAttribute option ([7ebf98b](https://github.com/edvardchen/eslint-plugin-i18next/commit/7ebf98b)), closes [#25](https://github.com/edvardchen/eslint-plugin-i18next/issues/25)
## [4.2.0](https://github.com/edvardchen/eslint-plugin-i18next/compare/v4.1.0...v4.2.0) (2020-07-01)

@@ -7,0 +14,0 @@

@@ -24,3 +24,16 @@ const { DOM_TAGS, SVG_TAGS } = require('./constants');

function generateFullMatchRegExp(source) {
if (source instanceof RegExp) {
return source;
}
if (typeof source !== 'string') {
console.error('generateFullMatchRegExp: expect string but get', source);
return new RegExp();
}
// allow dot ahead
return new RegExp(`(^|\\.)${source}${source.endsWith('$') ? '' : '$'}`);
}
exports.isUpperCase = isUpperCase;
exports.isAllowedDOMAttr = isAllowedDOMAttr;
exports.generateFullMatchRegExp = generateFullMatchRegExp;

37

lib/rules/no-literal-string.js

@@ -7,3 +7,8 @@ /**

const { isUpperCase, isAllowedDOMAttr } = require('../helper');
const {
isUpperCase,
generateFullMatchRegExp,
isAllowedDOMAttr
} = require('../helper');
const { createOptimisticUniqueName } = require('typescript');
// const { TypeFlags, SyntaxKind } = require('typescript');

@@ -54,2 +59,8 @@

type: 'boolean'
},
onlyAttribute: {
type: 'array',
items: {
type: 'string'
}
}

@@ -105,9 +116,3 @@ },

...((option && option.ignoreCallee) || [])
].map(item => {
if (item instanceof RegExp) {
return item;
}
// allow dot ahead
return new RegExp(`(^|\\.)${item}${item.endsWith('$') ? '' : '$'}`);
});
].map(generateFullMatchRegExp);

@@ -143,2 +148,6 @@ function isValidFunctionCall({ callee }) {

function isValidAttrName(name) {
if (option && option.onlyAttribute) {
// only validate those attributes in onlyAttribute option
return !option.onlyAttribute.includes(name);
}
return userJSXAttrs.includes(name);

@@ -238,2 +247,5 @@ }

// onlyAttribute would turn on markOnly
const markupOnly = option && (option.markupOnly || !!option.onlyAttribute);
const scriptVisitor = {

@@ -274,3 +286,3 @@ //

'JSXExpressionContainer > Literal:exit'(node) {
if (option && option.markupOnly) {
if (markupOnly) {
validateLiteral(node);

@@ -281,3 +293,6 @@ }

'JSXAttribute > Literal:exit'(node) {
if (option && option.markupOnly) {
if (markupOnly) {
const {
name: { name: attrName }
} = getNearestAncestor(node, 'JSXAttribute');
validateLiteral(node);

@@ -384,3 +399,3 @@ }

'Literal:exit'(node) {
if (option && option.markupOnly) {
if (markupOnly) {
return;

@@ -387,0 +402,0 @@ }

{
"name": "eslint-plugin-i18next",
"version": "4.2.0",
"version": "4.3.0",
"description": "ESLint plugin for i18n",

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

@@ -273,2 +273,19 @@ # eslint-plugin-i18next

### onlyAttribute
Only check the `JSX` attributes that listed in this option. **This option would turn on `markupOnly`.**
```jsx
// correct
const foo = 'bar';
<div foo="foo"></div>
// incorrect
<div>foo</div>
/*eslint i18next/no-literal-string: ["error", {"onlyAttribute": ["foo"]}]*/
// incorrect
<div foo="foo"></div>
```
#### ignore

@@ -275,0 +292,0 @@

@@ -119,3 +119,6 @@ /**

options: [{ markupOnly: true, ignoreAttribute: ['foo'] }]
}
},
// when onlyAttribute was configured, the markOnly would be treated as true
{ code: 'const a = "foo";', options: [{ onlyAttribute: ['bar'] }] },
{ code: '<DIV foo="bar" />', options: [{ onlyAttribute: ['bar'] }] }
],

@@ -122,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