diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..40446ae --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1 @@ +extends: uphold diff --git a/package.json b/package.json index 07b2e26..43ff3c0 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "test": "test" }, "scripts": { + "lint": "uphold-scripts lint", "test": "uphold-scripts test" }, "dependencies": { @@ -22,6 +23,9 @@ "devDependencies": { "uphold-scripts": "^0.4.0" }, + "pre-commit": [ + "lint" + ], "publishConfig": { "registry": "https://npm.pkg.github.com/" } diff --git a/test/src/index.test.js b/test/src/index.test.js index cb95f57..ca64ddb 100644 --- a/test/src/index.test.js +++ b/test/src/index.test.js @@ -42,19 +42,21 @@ describe('Anonymizer', () => { expect(anonymize({ foo: 'foo' })).toEqual({ foo: '--REDACTED--' }); }); - + it('should not obfuscate recursively the keys of an object that are part of the whitelist', () => { const anonymize = anonymizer(whitelist); - expect(anonymize({ - foo: { - bar: { - baz: { bax: [2, 3, { bax: 4, [whitelist[1]]: '5' }] }, - [whitelist[0]]: 'foobar', - [whitelist[2]]: 'foobiz' + expect( + anonymize({ + foo: { + bar: { + baz: { bax: [2, 3, { bax: 4, [whitelist[1]]: '5' }] }, + [whitelist[0]]: 'foobar', + [whitelist[2]]: 'foobiz' + } } - } - })).toEqual({ + }) + ).toEqual({ foo: { bar: { baz: { bax: ['--REDACTED--', '--REDACTED--', { bax: '--REDACTED--', [whitelist[1]]: '--REDACTED--' }] }, @@ -74,17 +76,23 @@ describe('Anonymizer', () => { it('should not treat a `.` in the whitelist as a special character in the regexp', () => { const anonymize = anonymizer(['foo.bar']); - expect(anonymize({ foo: { bar: 'biz' }, fooabar: 'foobiz' })).toEqual({ foo: { bar: 'biz' }, fooabar: '--REDACTED--' }); + expect(anonymize({ foo: { bar: 'biz' }, fooabar: 'foobiz' })).toEqual({ + foo: { bar: 'biz' }, + fooabar: '--REDACTED--' + }); }); it('should allow using `*` in the whitelist path', () => { const anonymize = anonymizer(['*.foo', '*.foobar']); - expect(anonymize({ parent: { foo: 'bar', foobar: 'foobiz' } })).toEqual({ parent: { foo: 'bar', foobar: 'foobiz' } }); + expect(anonymize({ parent: { foo: 'bar', foobar: 'foobiz' } })).toEqual({ + parent: { foo: 'bar', foobar: 'foobiz' } + }); }); it('should allow circular references', () => { const object = {}; + object.reference = object; const anonymize = anonymizer(['*']);