From b793e4bf4d68f1ffe1579c804975c85bc994366f Mon Sep 17 00:00:00 2001 From: Callum Date: Fri, 3 May 2019 13:14:55 +0100 Subject: [PATCH] Added eslintignore file Added props to allow configuration of what datatypes are detected --- .eslintignore | 1 + .eslintrc.js | 8 +- src/js/components/VariableEditor.js | 50 +++++------ src/js/helpers/parseInput.js | 42 +++++----- src/js/index.js | 37 ++++++--- test/tests/js/Index-test.js | 18 ++-- .../js/components/VariableEditor-test.js | 82 ++++++++++++------- 7 files changed, 140 insertions(+), 98 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..30d74d25 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index 299d8020..e90de35f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,12 +19,10 @@ module.exports = { "rules": { "indent": [ "error", - 4 - ], - "linebreak-style": [ - "error", - "unix" + 4, + { "SwitchCase": 1 } ], + "linebreak-style": 0, "quotes": [ "error", "single" diff --git a/src/js/components/VariableEditor.js b/src/js/components/VariableEditor.js index 18c6f969..c92a6f90 100644 --- a/src/js/components/VariableEditor.js +++ b/src/js/components/VariableEditor.js @@ -75,21 +75,21 @@ class VariableEditor extends React.PureComponent {
:
) : ( - - - " - - {variable.name} - - " + + + " + + {variable.name} - : + " - )} + : + + )}
{ - const type = editMode ? false : variable.type; const { props } = this; + const type = editMode ? false : variable.type; + switch (type) { case false: return this.getEditInput(); @@ -314,12 +315,15 @@ class VariableEditor extends React.PureComponent { } showDetected = () => { - const { theme, variable, namespace, rjvId } = this.props; + const { theme, variable, namespace, rjvId, detectDatatypes } = this.props; const { type, value } = this.state.parsedInput; - const detected = this.getDetectedInput(); - if (detected) { - return ( -
+ + // check if props allow for detection parsed type + + if (detectDatatypes[type]) { + const detected = this.getDetectedInput(); + if (detected) { + return (
{detected}
-
- ); + ); + } } } @@ -365,7 +369,7 @@ class VariableEditor extends React.PureComponent { }} > ... - + ... - + ", function() { +describe("", function () { const rjvId = 1 - it("check data type labels from index", function() { + it("check data type labels from index", function () { const wrapper = render( ", function() { int: 5, nan: NaN, null: null, - func: test => {}, + func: test => { }, obj: { arrChild: [1, 2, "three"], objChild: { @@ -39,7 +39,7 @@ describe("", function() { expect(wrapper.find(".data-type-label")).to.have.length(14) }) - it("check object-size labels from index", function() { + it("check object-size labels from index", function () { const wrapper = mount( ", function() { int: 5, nan: NaN, null: null, - func: test => {}, + func: test => { }, obj: { arrChild: [1, 2, "three"], objChild: { @@ -70,14 +70,14 @@ describe("", function() { expect(wrapper.find(".object-size")).to.have.length(0) }) - it("src replaced with error message (ERROR OUTPUT EXPECTED)", function() { + it("src replaced with error message (ERROR OUTPUT EXPECTED)", function () { const wrapper = render( ) expect(wrapper.find(".data-type-label")).to.have.length(1) }) - it("make sure copy to clipboard is displayed all properties", function() { + it("make sure copy to clipboard is displayed all properties", function () { const wrapper = render( ", function() { expect(wrapper.find(".click-to-copy")).to.have.length(7) }) - it("index test getDerivedStateFromProps", function() { + it("index test getDerivedStateFromProps", function () { sinon.spy(Index, "getDerivedStateFromProps") // mount() will cause getDerivedStateFromProps to be called twice. // 1. before first render() @@ -107,7 +107,7 @@ describe("", function() { ) }) - it("index can have ArrayGroup root component", function() { + it("index can have ArrayGroup root component", function () { const wrapper = render( ", function() { +describe("", function () { const rjvId = 1 + const detectDatatypesTrue = { + object: true, + array: true, + string: true, + integer: true, + float: true, + boolean: true, + date: true, + function: true, + null: true, + nan: true, + undefined: true + } - it("VariableEditor click-to-edit should be visible", function() { + it("VariableEditor click-to-edit should be visible", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} singleIndent={1} variable={{ @@ -26,7 +39,7 @@ describe("", function() { expect(wrapper.find(".click-to-edit")).to.have.length(1) }) - it("VariableEditor click-to-edit should be hidden when onEdit disabled", function() { + it("VariableEditor click-to-edit should be hidden when onEdit disabled", function () { const wrapper = shallow( ", function() { expect(wrapper.find(".click-to-edit")).to.have.length(0) }) - it("VariableEditor click-to-edit should be hidden when editMode is active", function() { + it("VariableEditor click-to-edit should be hidden when editMode is active", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: 5, @@ -61,13 +75,14 @@ describe("", function() { expect(wrapper.find(".click-to-edit")).to.have.length(0) }) - it("VariableEditor test textarea and cancel icon", function() { + it("VariableEditor test textarea and cancel icon", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: 5, @@ -83,7 +98,7 @@ describe("", function() { expect(wrapper.find(".variable-editor").length).to.equal(0) }) - it("VariableEditor test textarea and submit icon", function() { + it("VariableEditor test textarea and submit icon", function () { const existing_value = "existing_value" const new_value = "new_value" const wrapper = shallow( @@ -95,6 +110,7 @@ describe("", function() { }} namespace={["test"]} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: existing_value, @@ -121,7 +137,7 @@ describe("", function() { expect(wrapper.state("editMode")).to.equal(false) }) - it("VariableEditor edit after src change should respect current src", function() { + it("VariableEditor edit after src change should respect current src", function () { const existing_value = "existing_value" const new_value = "new_value" const wrapper = shallow( @@ -133,6 +149,7 @@ describe("", function() { }} namespace={["test"]} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: existing_value, @@ -167,13 +184,14 @@ describe("", function() { ) }) - it("VariableEditor detected null", function() { + it("VariableEditor detected null", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: "null", @@ -187,13 +205,14 @@ describe("", function() { expect(wrapper.find(".variable-editor").props().value).to.equal("null") }) - it("VariableEditor detected undefined", function() { + it("VariableEditor detected undefined", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: "undefined", @@ -209,13 +228,14 @@ describe("", function() { ) }) - it("VariableEditor detected NaN", function() { + it("VariableEditor detected NaN", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: "NaN", @@ -229,13 +249,14 @@ describe("", function() { expect(wrapper.find(".variable-editor").props().value).to.equal("NaN") }) - it("VariableEditor detected string", function() { + it("VariableEditor detected string", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: "test", @@ -249,13 +270,14 @@ describe("", function() { expect(wrapper.find(".variable-editor").props().value).to.equal("test") }) - it("VariableEditor detected function", function() { + it("VariableEditor detected function", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: "function test() {}", @@ -271,13 +293,14 @@ describe("", function() { ) }) - it("VariableEditor detected object", function() { + it("VariableEditor detected object", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: "{}", @@ -291,13 +314,14 @@ describe("", function() { expect(wrapper.find(".variable-editor").props().value).to.equal("{}") }) - it("VariableEditor detected array", function() { + it("VariableEditor detected array", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: "[1,2,3]", @@ -313,13 +337,14 @@ describe("", function() { ) }) - it("VariableEditor detected float", function() { + it("VariableEditor detected float", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: "-5.2", @@ -333,13 +358,14 @@ describe("", function() { expect(wrapper.find(".variable-editor").props().value).to.equal("-5.2") }) - it("VariableEditor detected integer", function() { + it("VariableEditor detected integer", function () { const wrapper = shallow( {}} + onEdit={edit => { }} rjvId={rjvId} + detectDatatypes={detectDatatypesTrue} variable={{ name: "test", value: "5",