New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More β†’
Socket
Sign inDemoInstall
Socket

eslint-plugin-i18n-json

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 2.1.0 to 2.2.0

CHANGELOG.md

2

package.json
{
"name": "eslint-plugin-i18n-json",
"version": "2.1.0",
"version": "2.2.0",
"description": "Fully extendable eslint plugin for JSON i18n translation files.",

@@ -5,0 +5,0 @@ "main": "index.js",

# eslint-plugin-i18n-json
[![Latest npm version](https://img.shields.io/npm/v/eslint-plugin-i18n-json.svg)](https://www.npmjs.com/package/eslint-plugin-i18n-json)
[![Build Status](https://travis-ci.org/godaddy/eslint-plugin-i18n-json.svg?branch=master)](https://travis-ci.org/godaddy/eslint-plugin-i18n-json)
> Fully extendable eslint plugin for JSON i18n translation files.
<p align="center">
<img src="assets/logo-transparent.png" width="400"/>
</p>
πŸŽ‰ [**Check out the introductory blog post!**](https://godaddy.github.io/2018/04/02/introducing-eslint-plugin-i18n-json/)
## Table of Contents
- [Features](#features)
- [Getting Started](#getting-started)
- [Features](#features-)
- [Getting started](#getting-started)
- [Examples](#examples)
- [Rules](#example)
- [Configuring your .eslintrc file](#configuring-your-eslintrc-file)
- [Rules](#rules)
- [i18n-json/valid-json](#i18n-jsonvalid-json)
- [i18n-json/valid-message-syntax](#i18n-jsonvalid-message-syntax)
- [i18n-json/identical-keys](#i18n-jsonidentical-keys)
- [Special Thanks](#special-thanks)
- [License](#license)
- [Special Thanks](#special-thanks-)
- [License](#license-)

@@ -77,7 +85,7 @@

```javascript
{
"extends": [
"plugin:i18n-json/recommended"
module.exports = {
extends: [
'plugin:i18n-json/recommended',
],
}
};
```

@@ -89,3 +97,3 @@ 4) add this npm script to your `package.json` file.

- the default eslint report formatter, `stylish`, doesn't handle lint messages of varying length well. Hence, we have also built a `custom report formatter` well suited for this plugin.
```JSON
```json
{

@@ -111,3 +119,3 @@ "scripts": {

## Configuring the rules
## Configuring your .eslintrc file
- Simply update your `.eslintrc.*` with overrides for the individual rules.

@@ -118,11 +126,11 @@ - Eslint severities: 2 = error, 1 = warning, 0 = off

```javascript
// eslintrc.json
```json
// .eslintrc.json
{
"rules": {
"i18n-json/valid-message-syntax": [2, {
syntax: 'icu',
"syntax": "icu"
}],
"i18n-json/valid-json": 2,
"i18n-json/identical-keys": 0,
"i18n-json/identical-keys": 0
}

@@ -134,10 +142,10 @@ }

module.exports = {
'rules': {
'i18n-json/valid-message-syntax': [2, {
syntax: 'icu',
}],
'i18n-json/valid-json': 2,
'i18n-json/identical-keys': 0,
}
}
rules: {
'i18n-json/valid-message-syntax': [2, {
syntax: 'icu',
}],
'i18n-json/valid-json': 2,
'i18n-json/identical-keys': 0,
},
};
```

@@ -160,15 +168,17 @@

// .eslintrc.js
rules: {
"i18n-json/valid-json": [2, {
linter: path.resolve('path/to/custom-linter.js')
}]
}
module.exports = {
rules: {
'i18n-json/valid-json': [2, {
linter: path.resolve('path/to/custom-linter.js'),
}],
},
};
```
```javascript
//custom-linter.js
// custom-linter.js
module.exports = (source) => {
if(isBad(source)){
if (isBad(source)) {
throw new SyntaxError('invalid syntax');
}
}
};
```

@@ -187,10 +197,11 @@

- **Can be a built in validator: `icu`, `non-empty-string`.**
```javascript
// .eslintrc.js
rules: {
"i18n-json/valid-message-syntax": [2, {
syntax: 'non-empty-string'
}]
}
module.exports = {
rules: {
'i18n-json/valid-message-syntax': [2, {
syntax: 'non-empty-string',
}],
},
};
```

@@ -205,16 +216,18 @@

// .eslintrc.js
rules: {
"i18n-json/valid-message-syntax": [2, {
syntax: path.resolve('path/to/custom-syntax-validator.js')
}]
}
module.exports = {
rules: {
'i18n-json/valid-message-syntax': [2, {
syntax: path.resolve('path/to/custom-syntax-validator.js'),
}],
},
};
```
```javascript
//custom-syntax-validator.js example
// custom-syntax-validator.js example
module.exports = (message, key) => {
// each message should be in all caps.
if(message !== message.toUppercase()){
throw new SyntaxError('MESSAGE MUST BE IN ALL CAPS!')
if (message !== message.toUpperCase()) {
throw new SyntaxError('MESSAGE MUST BE IN ALL CAPS!');
}
}
};
```

@@ -237,7 +250,9 @@ Output from the [custom-message-syntax](/examples/custom-message-syntax) example

// .eslintrc.js
rules: {
"i18n-json/identical-keys": [2, {
filePath: path.resolve('path/to/locale/en-US.json')
}]
}
module.exports = {
rules: {
'i18n-json/identical-keys': [2, {
filePath: path.resolve('path/to/locale/en-US.json'),
}],
},
};
```

@@ -248,11 +263,13 @@

// .eslintrc.js
rules: {
"i18n-json/identical-keys": [2, {
filePath: {
'login.json': path.resolve('./translations/en-US/login.json'),
'search-results.json': path.resolve('./translations/en-US/search-results.json'),
'todos.json': path.resolve('./translations/en-US/todos.json')
}
}]
}
module.exports = {
rules: {
'i18n-json/identical-keys': [2, {
filePath: {
'login.json': path.resolve('./translations/en-US/login.json'),
'search-results.json': path.resolve('./translations/en-US/search-results.json'),
'todos.json': path.resolve('./translations/en-US/todos.json'),
},
}],
},
};
```

@@ -267,7 +284,9 @@ - values in the path must be the absolute file path to the reference translation file.

// .eslintrc.js
rules: {
"i18n-json/identical-keys": [2, {
filePath: path.resolve('path/to/key-structure-generator.js')
}]
}
module.exports = {
rules: {
'i18n-json/identical-keys': [2, {
filePath: path.resolve('path/to/key-structure-generator.js'),
}],
},
};
```

@@ -293,7 +312,11 @@ ```javascript

- Jest platform packages
- intl-messageformat-parser
- report formatter ui heavily inspired from: https://github.com/sindresorhus/eslint-formatter-pretty
- ["Translate" icon](https://thenounproject.com/term/translate/1007332) created by BjΓΆrn Andersson, from [the Noun Project](https://thenounproject.com/). Used with attribution under Creative Commons.
## License πŸ“‹
MIT

@@ -37,2 +37,3 @@ const set = require('lodash.set');

return [{
message: 'Keys should be sorted, please use --fix',
fix: {

@@ -39,0 +40,0 @@ range: [0, source.length],

@@ -35,2 +35,3 @@ const sortTranslations = require('./sort-translations');

column: 0,
message: 'Keys should be sorted, please use --fix',
}]);

@@ -70,2 +71,3 @@ });

column: 0,
message: 'Keys should be sorted, please use --fix',
}]);

@@ -105,4 +107,5 @@ });

column: 0,
message: 'Keys should be sorted, please use --fix',
}]);
});
});

@@ -5,2 +5,7 @@ const set = require('lodash.set');

const DIFF_OPTIONS = {
expand: false,
contextLines: 1,
};
// we don't care what the actual values are.

@@ -19,5 +24,5 @@ // lodash.set will automatically convert a previous string value

});
return diff(augmentedTranslationsA, augmentedTranslationsB);
return diff(augmentedTranslationsA, augmentedTranslationsB, DIFF_OPTIONS);
};
module.exports = compareTranslationsStructure;

Sorry, the diff of this file is not supported yet

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