From c3beda884d95b80b971baf07ef05dfcc01e32fe8 Mon Sep 17 00:00:00 2001 From: rafaelgssa Date: Sun, 19 Jul 2020 09:24:39 -0300 Subject: [PATCH 1/5] Allow using glob ignore patterns --- package.json | 1 + src/util/deep-for-own.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index af7279d..fc163cc 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "lodash.isplainobject": "^4.0.6", "lodash.set": "^4.3.2", "log-symbols": "^2.2.0", + "micromatch": "^4.0.2", "plur": "^2.1.2", "pretty-format": "^22.0.3" } diff --git a/src/util/deep-for-own.js b/src/util/deep-for-own.js index 3fa16a0..359a388 100644 --- a/src/util/deep-for-own.js +++ b/src/util/deep-for-own.js @@ -1,4 +1,5 @@ const isPlainObject = require('lodash.isplainobject'); +const micromatch = require('micromatch'); /* deep level order traversal. @@ -9,7 +10,7 @@ const isPlainObject = require('lodash.isplainobject'); // calls iteratee with the path to the object. */ -const shouldIgnorePath = (ignoreList, keyPath) => ignoreList.includes(keyPath.join('.')); +const shouldIgnorePath = (ignoreList, keyPath) => micromatch.isMatch(keyPath.join('.'), ignoreList); const defaultTraversal = obj => Object.keys(obj); const deepForOwn = (obj, iteratee, { From c56824e2a462e375ba7b829e673e3c406f8d5734 Mon Sep 17 00:00:00 2001 From: rafaelgssa Date: Sun, 19 Jul 2020 09:28:20 -0300 Subject: [PATCH 2/5] Add test --- src/util/deep-for-own.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/util/deep-for-own.test.js b/src/util/deep-for-own.test.js index 6609c29..4e4f4f6 100644 --- a/src/util/deep-for-own.test.js +++ b/src/util/deep-for-own.test.js @@ -47,4 +47,32 @@ describe('deepForOwn', () => { }); expect(visited).toEqual(['a', 'd', 'j', 'e']); }); + it('will not traverse ignored paths using glob', () => { + const obj = { + a: { + b: { + c: 'value' + } + }, + d: { + e: { + f: 'value' + } + }, + g: { + h: { + i: 'value' + } + }, + j: 'value' + }; + const visited = []; + deepForOwn(obj, (value, key) => { + visited.push(key); + return true; + }, { + ignorePaths: ['*.b', 'd.*.f', 'g.*'] + }); + expect(visited).toEqual(['a', 'd', 'g', 'j', 'e']); + }); }); From 544a1722ee1e4ad3158c8b9c7394d6b58b0edbf5 Mon Sep 17 00:00:00 2001 From: rafaelgssa Date: Sun, 19 Jul 2020 09:37:45 -0300 Subject: [PATCH 3/5] Update README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 7095a0b..2747777 100644 --- a/README.md +++ b/README.md @@ -336,6 +336,21 @@ Check out the [Examples](examples/) folder to see different use cases. ### i18n-json/ignore-keys - list of key paths (case sensitive) to ignore when checking syntax and doing key structure comparisons. [Example](examples/ignore-keys/) +- you can also use glob patterns (this package uses [micromatch](https://github.com/micromatch/micromatch)) + - e.g. if the pattern `*.inProgress` was added to the `ignore-keys` list, then all of the `inProgress`keys below will be ignored. + ```json + { + "a": { + "inProgress": "translation" + }, + "b": { + "inProgress": "translation" + }, + "c": { + "inProgress": "translation" + } + } + ``` - this setting is used by the following rules: `i18n-json/identical-keys` and `i18n-json/valid-syntax` - if the key path points to an object, the nested paths are also ignored. - e.g. if the key `a` was added to the `ignore-keys` list, then `a.b` will also be ignored. From 03662f4b750e934054a74bd89271135a3867a533 Mon Sep 17 00:00:00 2001 From: rafaelgssa Date: Sun, 19 Jul 2020 09:39:42 -0300 Subject: [PATCH 4/5] Update example --- examples/ignore-keys/.eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ignore-keys/.eslintrc.js b/examples/ignore-keys/.eslintrc.js index cb6f29b..02997ac 100644 --- a/examples/ignore-keys/.eslintrc.js +++ b/examples/ignore-keys/.eslintrc.js @@ -14,7 +14,7 @@ module.exports = { */ 'i18n-json/ignore-keys': [ 'translationMetadata', - 'login.form.inProgressTranslationKey' + '*.inProgressTranslationKey' // No key path ending in `inProgressTranslationKey` will be checked. ] }, rules: { From d7db744419c310fd0c220a1a3ca851fd200b5c2a Mon Sep 17 00:00:00 2001 From: rafaelgomesxyz Date: Sat, 1 May 2021 21:17:57 -0300 Subject: [PATCH 5/5] Change micromatch version for compatibility with Node 6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 440293b..f488d0a 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "lodash.isplainobject": "^4.0.6", "lodash.set": "^4.3.2", "log-symbols": "^2.2.0", - "micromatch": "^4.0.2", + "micromatch": "^3.0.0", "plur": "^2.1.2", "pretty-format": "^22.0.3" }