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

ESLint plugin for i18n

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

eslint-plugin-i18next

ESLint plugin for i18n

Installation

$ npm install eslint-plugin-i18next --save-dev

Usage

Add i18next to the plugins section of your .eslintrc configuration file.

{
  "plugins": ["i18next"]
}

Then configure the rules you want to use under the rules section.

{
  "rules": {
    "i18next/no-literal-string": 2
  }
}

or

{
  "extends": ["plugin:i18next/recommended"]
}

Rule no-literal-string

This rule aims to avoid developers to display literal string to users in those projects which need to support multi-language.

The --fix option on the command line can automatically fix some of the problems reported by this rule.

Literay strings that are not constant string (all characters are UPPERCASE) are typically mistakes. For example:

const foo = 'foo';

They are frowned upon in favor of internationalization:

const foo = i18next.t('foo'); // wrapped by i18n translation function

Rule Details

It will find out all literal strings and validate them.

Examples of incorrect code for this rule:

/*eslint i18next/no-literal-string: "error"*/
const a = 'foo';

Examples of correct code for this rule:

/*eslint i18next/no-literal-string: "error"*/
// safe to assign string to const variables whose name are UPPER_CASE
var FOO = 'foo';

// UPPER_CASE properties are valid no matter if they are computed or not
var a = {
  BAR: 'bar',
  [FOO]: 'foo'
};

// also safe to use strings themselves are UPPCASE_CASE
var foo = 'FOO';
i18n

This rule allows to call i18next translate function.

Correct code:

/*eslint i18next/no-literal-string: "error"*/
var bar = i18next.t('bar');
var bar2 = i18n.t('bar');

Maybe you use other internationalization libraries not i18next. You can use like this:

/*eslint i18next/no-literal-string: ["error", { "ignoreCallee": ["yourI18n"] }]*/
const bar = yourI18n('bar');

// or

/*eslint i18next/no-literal-string: ["error", { "ignoreCallee": ["yourI18n.method"] }]*/
const bar = yourI18n.method('bar');
Redux/Vuex

This rule also works with those state managers like Redux and Vuex.

Correct code:

/*eslint i18next/no-literal-string: "error"*/
var bar = store.dispatch('bar');
var bar2 = store.commit('bar');

Options

ignore

The ignore option specifies exceptions not to check for literal strings that match one of regexp paterns.

Examples of correct code for the { "ignore": ['foo'] } option:

/*eslint i18next/no-literal-string: ["error", {"ignore": ["foo"]}]*/
const a = 'afoo';
ignoreCallee

THe ignoreCallee option speficies exceptions not check for function calls whose names match one of regexp patterns.

Examples of correct code for the { "ignoreCallee": ["foo"] } option:

/*eslint i18next/no-literal-string: ["error", { "ignoreCallee": ["foo"] }]*/
const bar = foo('bar');

Keywords

FAQs

Package last updated on 01 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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