From 437708df1ecd726e9396fd9aadc4f9fa8337b32c Mon Sep 17 00:00:00 2001 From: Niko Muukkonen <37067069+laveez@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:45:13 +0200 Subject: [PATCH] Update Lodash, remove usage of deprecated per-function Lodash packages, update readme (#66) * Update lodash, do some linting, add note about flat config to readme * Add /.idea to gitignore * Fix README.md links * Revert some unwanted code styling changes * Update Changelog --- .gitignore | 3 +- CHANGELOG.md | 5 ++++ README.md | 32 +++++++++++++++++++--- package.json | 10 +++---- src/identical-placeholders.js | 3 +- src/sorted-keys.js | 6 ++-- src/util/compare-translations-structure.js | 2 +- src/util/deep-for-own.js | 2 +- src/valid-json.js | 2 +- src/valid-message-syntax.js | 3 +- 10 files changed, 46 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 4179adc..f4c75bf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ coverage/ .DS_Store .vscode package-lock.json -*.lock \ No newline at end of file +*.lock +/.idea diff --git a/CHANGELOG.md b/CHANGELOG.md index 121ca99..b5d9de2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [4.0.1] + +- **security:** Bump Lodash due to [CVE-2020-8203](https://github.com/advisories/GHSA-p6mc-m468-83gw) +- Update readme with instructions on how to use this package with npm `>= 9.0.0` as described in https://github.com/godaddy/eslint-plugin-i18n-json/issues/62 + ## [4.0.0] - 2021-04-13 - MAJOR BUMP - Switch to `@formatjs/icu-messageformat-parser` as `intl-messageformat-parser` is now deprecated. This is a breaking change, the new parser uses icu4j implementation and has stricter validations. diff --git a/README.md b/README.md index 2ea3a3b..8447f62 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ > Fully extendable eslint plugin for JSON i18n translation files.

- + logo

🎉 [**Check out the introductory blog post!**](https://godaddy.github.io/2018/04/02/introducing-eslint-plugin-i18n-json/) @@ -16,7 +16,8 @@ - [Features](#features-) - [Getting started](#getting-started) - [Examples](#examples) -- [Configuring your .eslintrc file](#configuring-your-eslintrc-file) +- [Configuring your .eslintrc file (ESLint version `< 9.0.0`)](#configuring-your-eslintrc-file-eslint-version--900) +- [EsLint version `>= 9.0.0`](#eslint-version--900) - [Rules](#rules) - [i18n-json/valid-json](#i18n-jsonvalid-json) - [i18n-json/valid-message-syntax](#i18n-jsonvalid-message-syntax) @@ -106,7 +107,7 @@ simple **In this project directory, do the following:** 1) >npm install --save-dev eslint-plugin-i18n-json -2) Create a `.eslintrc.js` file in the root dir of your project. For this example: `/simple/.eslintrc.js`. +2) If you are using eslint `< 9.0.0` Create a `.eslintrc.js` file in the root dir of your project. For this example: `/simple/.eslintrc.js`. 3) paste in the following: ```javascript module.exports = { @@ -138,7 +139,7 @@ simple ![](assets/invalid-icu-syntax-screenshot.png) -## Configuring your .eslintrc file +## Configuring your .eslintrc file (ESLint version `< 9.0.0`) - Simply update your `.eslintrc.*` with overrides for the individual rules. - Eslint severities: 2 = error, 1 = warning, 0 = off - Example of the module's default rule configuration: @@ -177,6 +178,29 @@ simple }, }; ``` + +## ESLint version `>= 9.0.0` + +- ESLint version `>= 9.0.0` uses flat configuration + +```javascript +// eslint.config.(m)js +import i18nJsonPlugin from 'eslint-plugin-i18n-json'; + +export default { + files: ['**/*.json'], + plugins: { 'i18n-json': i18nJsonPlugin }, + processor: { + meta: { name: '.json' }, + ...i18nJsonPlugin.processors['.json'], + }, + rules: { + ...i18nJsonPlugin.configs.recommended.rules, + 'i18n-json/valid-message-syntax': 'off', + }, +}; + +``` ## Rules diff --git a/package.json b/package.json index a7e1774..c9bf40b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-i18n-json", - "version": "4.0.0", + "version": "4.0.1", "description": "Fully extendable eslint plugin for JSON i18n translation files.", "main": "index.js", "scripts": { @@ -27,7 +27,8 @@ ], "author": "GoDaddy Operating Company, LLC", "contributors": [ - "Mayank Jethva " + "Mayank Jethva ", + "Niko Muukkonen " ], "jest": { "roots": [ @@ -60,10 +61,7 @@ "chalk": "^2.3.2", "indent-string": "^3.2.0", "jest-diff": "^22.0.3", - "lodash.get": "^4.4.2", - "lodash.isequal": "^4.5.0", - "lodash.isplainobject": "^4.0.6", - "lodash.set": "^4.3.2", + "lodash": "^4.17.21", "log-symbols": "^2.2.0", "parse-json": "^5.2.0", "plur": "^2.1.2", diff --git a/src/identical-placeholders.js b/src/identical-placeholders.js index 6767be1..ef9bc87 100644 --- a/src/identical-placeholders.js +++ b/src/identical-placeholders.js @@ -1,6 +1,5 @@ const { parse, TYPE } = require('@formatjs/icu-messageformat-parser'); -const set = require('lodash.set'); -const get = require('lodash.get'); +const { set, get } = require('lodash'); const diff = require('jest-diff'); const requireNoCache = require('./util/require-no-cache'); const getTranslationFileSource = require('./util/get-translation-file-source'); diff --git a/src/sorted-keys.js b/src/sorted-keys.js index 6d99389..863def5 100644 --- a/src/sorted-keys.js +++ b/src/sorted-keys.js @@ -1,6 +1,4 @@ -const set = require('lodash.set'); -const equal = require('lodash.isequal'); -const isPlainObject = require('lodash.isplainobject'); +const { set, isEqual, isPlainObject } = require('lodash'); const deepForOwn = require('./util/deep-for-own'); const keyTraversals = require('./util/key-traversals'); const getTranslationFileSource = require('./util/get-translation-file-source'); @@ -48,7 +46,7 @@ const sortedKeys = ([{ order = 'asc', sortFunctionPath, indentSpaces = 2 } = {}] originalTranslationPaths.push(path); }); - if (!equal(originalTranslationPaths, sortedTranslationPaths)) { + if (!isEqual(originalTranslationPaths, sortedTranslationPaths)) { const sortedWithIndent = JSON.stringify( sortedTranslations, null, diff --git a/src/util/compare-translations-structure.js b/src/util/compare-translations-structure.js index c4b5a68..e0d7ae3 100644 --- a/src/util/compare-translations-structure.js +++ b/src/util/compare-translations-structure.js @@ -1,4 +1,4 @@ -const set = require('lodash.set'); +const { set } = require('lodash'); const diff = require('jest-diff'); const deepForOwn = require('./deep-for-own'); diff --git a/src/util/deep-for-own.js b/src/util/deep-for-own.js index 3fa16a0..cee035b 100644 --- a/src/util/deep-for-own.js +++ b/src/util/deep-for-own.js @@ -1,4 +1,4 @@ -const isPlainObject = require('lodash.isplainobject'); +const { isPlainObject } = require('lodash'); /* deep level order traversal. diff --git a/src/valid-json.js b/src/valid-json.js index 07ea162..cb0d53e 100644 --- a/src/valid-json.js +++ b/src/valid-json.js @@ -1,5 +1,5 @@ const parseJson = require('parse-json'); -const isPlainObject = require('lodash.isplainobject'); +const { isPlainObject } = require('lodash'); const chalk = require('chalk'); const requireNoCache = require('./util/require-no-cache'); const getTranslationFileSource = require('./util/get-translation-file-source'); diff --git a/src/valid-message-syntax.js b/src/valid-message-syntax.js index 061c8eb..006946e 100644 --- a/src/valid-message-syntax.js +++ b/src/valid-message-syntax.js @@ -1,6 +1,5 @@ -const set = require('lodash.set'); +const { set, isPlainObject } = require('lodash'); const diff = require('jest-diff'); -const isPlainObject = require('lodash.isplainobject'); const prettyFormat = require('pretty-format'); const icuValidator = require('./message-validators/icu'); const notEmpty = require('./message-validators/not-empty');