From 805030a6675b11717bd7f10ed247203eddea3bd9 Mon Sep 17 00:00:00 2001 From: Kazimirkas Date: Tue, 27 Feb 2018 15:49:50 +0200 Subject: [PATCH 1/4] stripped console from production mode --- .eslintrc | 3 ++- src/index.js | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index e271786..9e8ad1c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -49,7 +49,8 @@ "globals": { "test": true, "expect": true, - "describe": true + "describe": true, + "NODE_ENV": true }, "parserOptions": { "ecmaVersion": 6, diff --git a/src/index.js b/src/index.js index 89f6e20..c4c4555 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,7 @@ // @flow +declare var NODE_ENV: string; +const developmentMode = NODE_ENV !== 'production'; + type Rule = (val: any, state: Object) => boolean; type RuleData = { @@ -232,7 +235,7 @@ class Validation { throw new Error('Invalid storage object, must be object'); } const fieldStatuses = storage[fieldName]; - if (!fieldStatuses) { + if (developmentMode && !fieldStatuses) { // TODO: how to disable warnings in production console.warn("Attempt to validate field that doesn't exist"); return false; From e0f7f9956a5b7f41fd2f0d96c6db7954ce735880 Mon Sep 17 00:00:00 2001 From: Kazimirkas Date: Tue, 27 Feb 2018 16:58:17 +0200 Subject: [PATCH 2/4] fixed errors and removed warning --- .eslintrc | 1 - src/index.js | 15 ++++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9e8ad1c..d7870cc 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,6 @@ "keyword-spacing": ["warn", {"after": true}], "jsx-quotes": ["warn", "prefer-double"], "no-extra-boolean-cast": "off", - "no-console": 0, "no-multi-spaces": "warn", "no-spaced-func": "warn", "no-unused-vars": "warn", diff --git a/src/index.js b/src/index.js index c4c4555..a0222a8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,4 @@ // @flow -declare var NODE_ENV: string; -const developmentMode = NODE_ENV !== 'production'; - type Rule = (val: any, state: Object) => boolean; type RuleData = { @@ -211,8 +208,11 @@ class Validation { isFormValid(state: Object): boolean { const storage = state[this.validationStorageName]; + if (typeof state !== 'object') { + throw new Error('Invalid state parameter, must be object'); + } if (typeof storage !== 'object') { - throw new Error('Invalid fieldsMappedToStatuses object, must be object'); + throw new Error('Invalid storage object, must be object'); } const keys = Object.keys(storage); @@ -231,13 +231,14 @@ class Validation { isFieldValid(state: Object, fieldName: string): boolean { const storage = state[this.validationStorageName]; + if (typeof state !== 'object') { + throw new Error('Invalid state parameter, must be object'); + } if (typeof storage !== 'object') { throw new Error('Invalid storage object, must be object'); } const fieldStatuses = storage[fieldName]; - if (developmentMode && !fieldStatuses) { - // TODO: how to disable warnings in production - console.warn("Attempt to validate field that doesn't exist"); + if (!fieldStatuses) { return false; } From 38d2218ee2f7fbff73be4583670eb0e76476a612 Mon Sep 17 00:00:00 2001 From: Kazimirkas Date: Tue, 27 Feb 2018 16:59:57 +0200 Subject: [PATCH 3/4] updated build --- build/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/build/index.js b/build/index.js index 8872926..ca63015 100644 --- a/build/index.js +++ b/build/index.js @@ -195,8 +195,11 @@ var Validation = function () { key: 'isFormValid', value: function isFormValid(state) { var storage = state[this.validationStorageName]; + if ((typeof state === 'undefined' ? 'undefined' : _typeof(state)) !== 'object') { + throw new Error('Invalid state parameter, must be object'); + } if ((typeof storage === 'undefined' ? 'undefined' : _typeof(storage)) !== 'object') { - throw new Error('Invalid fieldsMappedToStatuses object, must be object'); + throw new Error('Invalid storage object, must be object'); } var keys = Object.keys(storage); @@ -219,13 +222,14 @@ var Validation = function () { key: 'isFieldValid', value: function isFieldValid(state, fieldName) { var storage = state[this.validationStorageName]; + if ((typeof state === 'undefined' ? 'undefined' : _typeof(state)) !== 'object') { + throw new Error('Invalid state parameter, must be object'); + } if ((typeof storage === 'undefined' ? 'undefined' : _typeof(storage)) !== 'object') { throw new Error('Invalid storage object, must be object'); } var fieldStatuses = storage[fieldName]; if (!fieldStatuses) { - // TODO: how to disable warnings in production - console.warn("Attempt to validate field that doesn't exist"); return false; } From 606849529bb0297d34f37fb31f19d0f1caa2c8f5 Mon Sep 17 00:00:00 2001 From: Kazimirkas Date: Tue, 27 Feb 2018 17:01:39 +0200 Subject: [PATCH 4/4] eslintrc fix --- .eslintrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index d7870cc..82bfa38 100644 --- a/.eslintrc +++ b/.eslintrc @@ -48,8 +48,7 @@ "globals": { "test": true, "expect": true, - "describe": true, - "NODE_ENV": true + "describe": true }, "parserOptions": { "ecmaVersion": 6,