From 3ff424b7eaa34f566c3c7d6dbb0b3005ffe4a093 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 29 Apr 2017 21:26:29 -0400 Subject: [PATCH 01/14] toTex function --- lib/toTex.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++ test/toTex_test.js | 20 ++++++++++ 2 files changed, 113 insertions(+) create mode 100644 lib/toTex.js create mode 100644 test/toTex_test.js diff --git a/lib/toTex.js b/lib/toTex.js new file mode 100644 index 0000000..f0be994 --- /dev/null +++ b/lib/toTex.js @@ -0,0 +1,93 @@ +/** + * toTex - return a string representation of the nodes in LaTeX + */ + +const isNeg = (node) => { + return node.type === 'Operation' && node.op === 'neg'; +}; + +const isAdd = (node) => { + return node.type === 'Operation' && node.op === 'add'; +}; + +const isMul = (node) => { + return node.type === 'Operation' && node.op === '*' && node.args.length > 1; +}; + +function toTexOperation(node, parent){ + let result; + + switch(node.op){ + case 'add': + //e.g a + (-a) => a - a + result = toTex(node.args[0], node); + for (let i = 1; i < node.args.length; i++){ + const arg = node.args[i]; + if (isNeg(arg) && arg.wasMinus){ + result += ` - ${toTex(arg.args[0], node)}`; + } else { + result += ` + ${toTex(arg, node)}`; + } + } + return parent ? `\left(${result}\right)` : result; + case 'neg': + return `-${toTex(node.args[0], node)}`; + case 'pos': + return `+${toTex(node.args[0], node)}`; + case 'pn': + throw new Error(`we don't handle 'pn' operations yet`); + case 'np': + throw new Error(`we don't handle 'np' operations yet`); + case 'mul': + if (node.implicit) { + //e.g 2 x + return node.args.map(arg => toTex(arg, node)).join(` `); + } else { + //e.g 2 * x + return node.args.map(arg => toTex(arg, node)).join(` \ast `); // ast for asterisk and \time for x + } + case 'div': + result = ''; + result += '\frac'; + //add parentheses when numerator or denominator has multiple terms + //e.g latex fractions: \frac{a}{b} => a/b + result += `{${toTex(node.args[1], node)}}`; + return result; + case 'pow': + // + return `${toTex(node.args[0], node)}^{${toTex(node.args[1], node)}}`; + case 'fact': + throw new Error(`we don't handle 'fact' operations yet`); + default: + throw new Error('unrecognized operation'); + } +} + +export default function toTex(node, parent = null){ + switch(node.type){ + // regular non-leaf nodes + case 'Relation': + // e.g a = b or ax^3 + bx^2 + cx + d = 0 + return node.args.map(arg => toTex(arg, node)).join(` ${node.rel} `); + case 'Operation': + return toTexOperation(node, parent); + case 'Function': + // e.g f(x, y, z) + return `${node.fn}(${node.args.map(arg => toTex(arg, node)).join(', ')})`; + + //leaf nodes + case 'Identifier': + return node.name; + case 'Number': + return node.value; + + //irregular node-leaf nodes + case 'Brackets': + //e.g [[2,3], [3,4]] + return `\lbrack${toTex(node.content, node)}\rbrack`; + + default: + console.log(node); // eslint-disable-line no-console + throw new Error('unrecognized node'); + } +} diff --git a/test/toTex_test.js b/test/toTex_test.js new file mode 100644 index 0000000..8b18a24 --- /dev/null +++ b/test/toTex_test.js @@ -0,0 +1,20 @@ +import assert from 'assert' + +import parse from '../lib/parse' +import toTex from '../lib/toTex.js' + +describe("toTex", () => { + it("handles wasMinus correctly", () => { + assert.equal(toTex(parse('1 - 2')), '1 - 2'); + assert.equal(toTex(parse('1 - -2')), '1 - -2'); + assert.equal(toTex(parse('a - b')), 'a - b'); + assert.equal(toTex(parse('a + -b')), 'a + -b'); + }); + + // TODO(kevinb) enable these tests after updating division parsing behavior + it.skip("handles fractions correctly", () => { + assert.equal(toTex(parse('1/2/3')), '1 / 2 / 3'); + assert.equal(parse('1*2/3'), '1 * (2 / 3)'); + // assert.equal(toTex(parser.parse('(1*2)/3')), '(1 * 2) / 3'); + }); +}); From 9eaf0baf637796758c988376045f5b3b057b1baf Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 29 Apr 2017 21:49:05 -0400 Subject: [PATCH 02/14] fixed toTex function --- test/toTex_test.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/toTex_test.js b/test/toTex_test.js index 8b18a24..062a7d5 100644 --- a/test/toTex_test.js +++ b/test/toTex_test.js @@ -5,16 +5,23 @@ import toTex from '../lib/toTex.js' describe("toTex", () => { it("handles wasMinus correctly", () => { - assert.equal(toTex(parse('1 - 2')), '1 - 2'); + // arithmetic + assert.equal(toTex(parse('1 + -2')), '1 + -2'); assert.equal(toTex(parse('1 - -2')), '1 - -2'); assert.equal(toTex(parse('a - b')), 'a - b'); assert.equal(toTex(parse('a + -b')), 'a + -b'); + assert.equal(toTex(parse('1 * 2')), '1 ast 2'); + // implicit multiplication + assert.equal(toTex(parse('x * 2x')), 'x ast 2 x'); + assert.equal(toTex(parse('-3')), '-3'); + // brackets + //assert.equal(toTex(parse('[2 , 3]')), ''); }); - // TODO(kevinb) enable these tests after updating division parsing behavior - it.skip("handles fractions correctly", () => { - assert.equal(toTex(parse('1/2/3')), '1 / 2 / 3'); - assert.equal(parse('1*2/3'), '1 * (2 / 3)'); - // assert.equal(toTex(parser.parse('(1*2)/3')), '(1 * 2) / 3'); + it("handles fractions correctly", () => { + assert.equal(toTex(parse('1/2')), '\\frac{1}{2}'); + assert.equal(toTex(parse('1/2/3')), '\\frac{\\frac{1}{2}}{3}'); + assert.equal(toTex(parse('x/2')), '\\frac{x}{2}'); + assert.equal(toTex(parse('(x+2)/(x+3)')), '\\frac{\\left(x + 2\\right)}{\\left(x + 3\\right)}'); }); }); From b1ea3d34822f39ee8f41c248f2e5627a3dcb9dff Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 29 Apr 2017 22:40:40 -0400 Subject: [PATCH 03/14] forgot a piece --- lib/toTex.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/toTex.js b/lib/toTex.js index f0be994..1b0ef0e 100644 --- a/lib/toTex.js +++ b/lib/toTex.js @@ -29,7 +29,7 @@ function toTexOperation(node, parent){ result += ` + ${toTex(arg, node)}`; } } - return parent ? `\left(${result}\right)` : result; + return parent ? `\\left(${result}\\right)` : result; case 'neg': return `-${toTex(node.args[0], node)}`; case 'pos': @@ -48,10 +48,11 @@ function toTexOperation(node, parent){ } case 'div': result = ''; - result += '\frac'; + result += '\\frac'; //add parentheses when numerator or denominator has multiple terms //e.g latex fractions: \frac{a}{b} => a/b - result += `{${toTex(node.args[1], node)}}`; + result += `{${toTex(node.args[0], node)}}`; + result += `{${toTex(node.args[1], node)}}`; return result; case 'pow': // From 2ec76c649e973ff37b720268fcacbf135150a31b Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 29 Apr 2017 22:59:36 -0400 Subject: [PATCH 04/14] fixed --- test/toTex_test.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/test/toTex_test.js b/test/toTex_test.js index 062a7d5..b46dd09 100644 --- a/test/toTex_test.js +++ b/test/toTex_test.js @@ -4,24 +4,24 @@ import parse from '../lib/parse' import toTex from '../lib/toTex.js' describe("toTex", () => { - it("handles wasMinus correctly", () => { - // arithmetic - assert.equal(toTex(parse('1 + -2')), '1 + -2'); - assert.equal(toTex(parse('1 - -2')), '1 - -2'); - assert.equal(toTex(parse('a - b')), 'a - b'); - assert.equal(toTex(parse('a + -b')), 'a + -b'); - assert.equal(toTex(parse('1 * 2')), '1 ast 2'); - // implicit multiplication - assert.equal(toTex(parse('x * 2x')), 'x ast 2 x'); - assert.equal(toTex(parse('-3')), '-3'); - // brackets - //assert.equal(toTex(parse('[2 , 3]')), ''); - }); + it("handles wasMinus correctly", () => { + // arithmetic + assert.equal(toTex(parse('1 + -2')), '1 + -2'); + assert.equal(toTex(parse('1 - -2')), '1 - -2'); + assert.equal(toTex(parse('a - b')), 'a - b'); + assert.equal(toTex(parse('a + -b')), 'a + -b'); + assert.equal(toTex(parse('1 * 2')), '1 ast 2'); + // implicit multiplication + assert.equal(toTex(parse('x * 2x')), 'x ast 2 x'); + assert.equal(toTex(parse('-3')), '-3'); + // brackets + //assert.equal(toTex(parse('[2 , 3]')), ''); + }); - it("handles fractions correctly", () => { - assert.equal(toTex(parse('1/2')), '\\frac{1}{2}'); - assert.equal(toTex(parse('1/2/3')), '\\frac{\\frac{1}{2}}{3}'); - assert.equal(toTex(parse('x/2')), '\\frac{x}{2}'); - assert.equal(toTex(parse('(x+2)/(x+3)')), '\\frac{\\left(x + 2\\right)}{\\left(x + 3\\right)}'); - }); + it("handles fractions correctly", () => { + assert.equal(toTex(parse('1/2')), '\\frac{1}{2}'); + assert.equal(toTex(parse('1/2/3')), '\\frac{\\frac{1}{2}}{3}'); + assert.equal(toTex(parse('x/2')), '\\frac{x}{2}'); + assert.equal(toTex(parse('(x+2)/(x+3)')), '\\frac{\\left(x + 2\\right)}{\\left(x + 3\\right)}'); + }); }); From 1583865ec1c1c379b38691f86e18bfb03993bfb9 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 29 Apr 2017 22:59:44 -0400 Subject: [PATCH 05/14] fixed --- lib/toTex.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/toTex.js b/lib/toTex.js index 1b0ef0e..9e68b8e 100644 --- a/lib/toTex.js +++ b/lib/toTex.js @@ -1,6 +1,6 @@ /** - * toTex - return a string representation of the nodes in LaTeX - */ + * toTex - return a string representation of the nodes in LaTeX + */ const isNeg = (node) => { return node.type === 'Operation' && node.op === 'neg'; @@ -10,10 +10,6 @@ const isAdd = (node) => { return node.type === 'Operation' && node.op === 'add'; }; -const isMul = (node) => { - return node.type === 'Operation' && node.op === '*' && node.args.length > 1; -}; - function toTexOperation(node, parent){ let result; @@ -44,7 +40,7 @@ function toTexOperation(node, parent){ return node.args.map(arg => toTex(arg, node)).join(` `); } else { //e.g 2 * x - return node.args.map(arg => toTex(arg, node)).join(` \ast `); // ast for asterisk and \time for x + return node.args.map(arg => toTex(arg, node)).join(` \times `); } case 'div': result = ''; From 5102e25d80df5dcf29fa8b18156f13475d08c9a1 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 29 Apr 2017 23:02:17 -0400 Subject: [PATCH 06/14] times --- lib/toTex.js | 2 +- test/toTex_test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/toTex.js b/lib/toTex.js index 9e68b8e..945099d 100644 --- a/lib/toTex.js +++ b/lib/toTex.js @@ -40,7 +40,7 @@ function toTexOperation(node, parent){ return node.args.map(arg => toTex(arg, node)).join(` `); } else { //e.g 2 * x - return node.args.map(arg => toTex(arg, node)).join(` \times `); + return node.args.map(arg => toTex(arg, node)).join(` \\times `); } case 'div': result = ''; diff --git a/test/toTex_test.js b/test/toTex_test.js index b46dd09..3d8d313 100644 --- a/test/toTex_test.js +++ b/test/toTex_test.js @@ -10,9 +10,9 @@ describe("toTex", () => { assert.equal(toTex(parse('1 - -2')), '1 - -2'); assert.equal(toTex(parse('a - b')), 'a - b'); assert.equal(toTex(parse('a + -b')), 'a + -b'); - assert.equal(toTex(parse('1 * 2')), '1 ast 2'); + assert.equal(toTex(parse('1 * 2')), '1 \\times 2'); // implicit multiplication - assert.equal(toTex(parse('x * 2x')), 'x ast 2 x'); + assert.equal(toTex(parse('x * 2x')), 'x \\times 2 x'); assert.equal(toTex(parse('-3')), '-3'); // brackets //assert.equal(toTex(parse('[2 , 3]')), ''); From d144dc5d42c359a3929c65d064c869a488db7446 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 29 Apr 2017 23:05:32 -0400 Subject: [PATCH 07/14] equations case --- test/toTex_test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/toTex_test.js b/test/toTex_test.js index 3d8d313..ba841c0 100644 --- a/test/toTex_test.js +++ b/test/toTex_test.js @@ -24,4 +24,10 @@ describe("toTex", () => { assert.equal(toTex(parse('x/2')), '\\frac{x}{2}'); assert.equal(toTex(parse('(x+2)/(x+3)')), '\\frac{\\left(x + 2\\right)}{\\left(x + 3\\right)}'); }); + + it("handles equations correctly", () => { + assert.equal(toTex(parse('x = 5/2')), 'x = \\frac{5}{2}'); + assert.equal(toTex(parse('x = 3 * (2/x)')), 'x = 3 \\times \\frac{2}{x}'); + assert.equal(toTex(parse('3 + x = 3/x')), '\\left(3 + x\\right) = \\frac{3}{x}'); + }); }); From 1ff204ac533793d89e58803699556f4a33ca6e38 Mon Sep 17 00:00:00 2001 From: Anthony Date: Fri, 5 May 2017 18:00:33 -0400 Subject: [PATCH 08/14] fixed print --- lib/print.js | 141 ++++++++++++++++++++++++++------------------- test/print_test.js | 66 ++++++++++++++++----- 2 files changed, 134 insertions(+), 73 deletions(-) diff --git a/lib/print.js b/lib/print.js index 3a3d4b1..f00e94b 100644 --- a/lib/print.js +++ b/lib/print.js @@ -3,78 +3,107 @@ */ const isNeg = (node) => { - return node.type === 'Operation' && node.op === 'neg'; + return node.type === 'Apply' && node.op === 'neg'; } const isAdd = (node) => { - return node.type === 'Operation' && node.op === 'add'; + return node.type === 'Apply' && node.op === 'add'; } const isMul = (node) => { - return node.type === 'Operation' && node.op === '*' && node.args.length > 1; + return node.type === 'Apply' && node.op === 'mul'; } -function printOperation(node, parent) { - let result; +const isDiv = (node) => { + return node.type === 'Apply' && node.op === 'div'; +} - switch (node.op) { - case 'add': - result = print(node.args[0], node); - for (let i = 1; i < node.args.length; i++) { - const arg = node.args[i]; - if (isNeg(arg) && arg.wasMinus) { - result += ` - ${print(arg.args[0], node)}`; - } else { - result += ` + ${print(arg, node)}`; - } - } - return parent ? `(${result})` : result; - case 'neg': - return `-${print(node.args[0], node)}`; - case 'pos': - return `+${print(node.args[0], node)}`; - case 'pn': - throw new Error(`we don't handle 'pn' operations yet`); - case 'np': - throw new Error(`we don't handle 'np' operations yet`); - case 'mul': - if (node.implicit) { - return node.args.map(arg => print(arg, node)).join(` `); +const relationIdentifierMap = { + 'eq': '=', + 'lt': '<', + 'le': '<=', + 'gt': '>', + 'ge': '>=', + 'ne': '!=', +} + +const printApply = (node, parent) => { + const {op, args} = node; + + if (op === 'add') { + let result = print(args[0], node); + for (let i = 1; i < args.length; i++) { + const arg = args[i]; + if (isNeg(arg) && arg.wasMinus) { + result += ` - ${print(arg.args[0], node)}`; } else { - return node.args.map(arg => print(arg, node)).join(` * `); + result += ` + ${print(arg, node)}`; } - case 'div': - result = ''; - if (isAdd(node.args[0]) || isMul(node.args[0])) { - result += `(${print(node.args[0], node)})`; - } else { - result += print(node.args[0], node); + } + return parent ? `(${result})` : result; + } else if (op === 'mul') { + if (node.implicit) { + return args.map(arg => print(arg, node)).join(` `); + } else { + return args.map(arg => print(arg, node)).join(` * `); + } + } else if (op === 'div') { + let result = ''; + if (isMul(args[0])) { + result += `(${print(args[0], node)})`; + } else { + result += print(args[0], node); + } + result += ' / '; + if (isMul(args[1]) || isDiv(args[1])) { + result += `(${print(args[1], node)})`; + } else { + result += print(args[1], node); + } + return result; + } else if (op === 'pow') { + const exponent = node.args[1]; + let bool = false; + // check if exponent has multiple terms and if the exponent + // contains a div/mul operation + // e.g x^((x + 1)/(2 + 2)) + if (exponent.args){ + if (exponent.op == 'div' || exponent.op == 'mul'){ + bool = true; } - result += ' / '; - if (isAdd(node.args[1]) || isMul(node.args[1])) { - result += `(${print(node.args[1], node)})`; - } else { - result += print(node.args[1], node); - } - return result; - case 'pow': - return `${print(node.args[0], node)}^${print(node.args[1], node)}`; - case 'fact': - throw new Error(`we don't handle 'fact' operations yet`); - default: - throw new Error('unrecognized operation'); + } + if (bool) { + return `${print(args[0], node)}^(${print(args[1], node)})`; + } else { + return `${print(args[0], node)}^${print(args[1], node)}`; + } + } else if (op === 'neg') { + return `-${print(args[0], node)}`; + } else if (op === 'pos') { + return `+${print(args[0], node)}`; + } else if (op === 'pn') { + throw new Error(`we don't handle 'pn' operations yet`); + } else if (op === 'np') { + throw new Error(`we don't handle 'np' operations yet`); + } else if (op === 'fact') { + throw new Error(`we don't handle 'fact' operations yet`); + } else if (op in relationIdentifierMap) { + const symbol = relationIdentifierMap[op]; + return args.map(arg => print(arg, node)).join(` ${symbol} `); + } else { + return `${op}(${args.map(arg => print(arg, node)).join(', ')})`; } } export default function print(node, parent = null) { switch (node.type) { // regular non-leaf nodes - case 'Relation': - return node.args.map(arg => print(arg, node)).join(` ${node.rel} `); - case 'Operation': - return printOperation(node, parent); - case 'Function': - return `${node.fn}(${node.args.map(arg => print(arg, node)).join(', ')})`; + case 'Apply': + return printApply(node, parent); + + // irregular non-leaf nodes + case 'Parentheses': + return `(${print(node.body, node)})`; // leaf nodes case 'Identifier': @@ -82,10 +111,6 @@ export default function print(node, parent = null) { case 'Number': return node.value; - // irregular non-leaf nodes - case 'Brackets': - return `(${print(node.content, node)})`; - default: console.log(node); // eslint-disable-line no-console throw new Error('unrecognized node'); diff --git a/test/print_test.js b/test/print_test.js index 2e6b038..d52334c 100644 --- a/test/print_test.js +++ b/test/print_test.js @@ -4,18 +4,54 @@ import parse from '../lib/parse' import print from '../lib/print' describe("print", () => { - it("handles wasMinus correctly", () => { - assert.equal(print(parse('1 + -2')), '1 + -2'); - assert.equal(print(parse('1 - 2')), '1 - 2'); - assert.equal(print(parse('1 - -2')), '1 - -2'); - assert.equal(print(parse('a - b')), 'a - b'); - assert.equal(print(parse('a + -b')), 'a + -b'); - }); - - // TODO(kevinb) enable these tests after updating division parsing behavior - it.skip("handles fractions correctly", () => { - assert.equal(print(parse('1/2/3')), '1 / 2 / 3'); - assert.equal(parse('1*2/3'), '1 * (2 / 3)'); - // assert.equal(print(parser.parse('(1*2)/3')), '(1 * 2) / 3'); - }); -}); + it("wasMinus", () => { + const tests = [ + '1 + -2', + '1 - 2', + '1 - -2', + 'a - b', + 'a + -b', + ] + + tests.forEach(test => assert.equal(print(parse(test)), test)) + }) + + it("relations", () => { + const tests = [ + 'a = b', + 'a > b', + 'a >= b', + 'a < b', + 'a <= b', + 'a != b', + ] + + tests.forEach(test => assert.equal(print(parse(test)), test)) + }) + + it("handles fractions correctly", () => { + const tests = [ + ['(x + 1) / 1', '(x + 1) / 1'], + ['1/2/3', '1 / 2 / 3'], // (1/2) / 3 + ['1*2/3', '1 * 2 / 3'], // 1 * (2/3) + ['(1*2)/3', '(1 * 2) / 3'], + ['a/(b/c)', 'a / (b / c)'], + ] + + tests.forEach(test => assert.equal(print(parse(test[0])), test[1])) + }) + + it("handles exponents correctly", () => { + const tests = [ + ['x^2', 'x^2'], + ['x^((x + 1)/(2 * 2))', 'x^((x + 1) / (2 * 2))'], + ['x^(y + 1)', 'x^(y + 1)'], + ['x^(x / 2)','x^(x / 2)'], + ['x^(x / (x + 2))', 'x^(x / (x + 2))'], + ['x^(x + x + (x + y))', 'x^(x + x + (x + y))'], + ['(y+1)^((x + 1) + 2)', '(y + 1)^((x + 1) + 2)'] + ] + + tests.forEach(test => assert.equal(print(parse(test[0])),test[1])) + }) +}) From b460f6f8b5720defe7cf590ea08d19f893f1c6cc Mon Sep 17 00:00:00 2001 From: Anthony Date: Fri, 5 May 2017 22:42:29 -0400 Subject: [PATCH 09/14] linter and print --- lib/print.js | 5 +---- package.json | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/print.js b/lib/print.js index f00e94b..db8dad1 100644 --- a/lib/print.js +++ b/lib/print.js @@ -64,11 +64,8 @@ const printApply = (node, parent) => { } else if (op === 'pow') { const exponent = node.args[1]; let bool = false; - // check if exponent has multiple terms and if the exponent - // contains a div/mul operation - // e.g x^((x + 1)/(2 + 2)) if (exponent.args){ - if (exponent.op == 'div' || exponent.op == 'mul'){ + if (isMul(exponent) || isDiv(exponent)){ bool = true; } } diff --git a/package.json b/package.json index 6d3829b..26f792c 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,8 @@ "babel-plugin-transform-object-rest-spread": "^6.22.0", "babel-preset-es2015": "^6.22.0", "eslint": "^3.15.0", + "eslint-config-google": "^0.7.0", + "eslint-plugin-sort-requires": "^2.1.0", "eslint-plugin-flowtype": "^2.30.0", "flow-bin": "^0.38.0", "mocha": "^3.2.0", From 142ab422d94f5ffa34691e566bdf3b6824af7543 Mon Sep 17 00:00:00 2001 From: Anthony Date: Fri, 5 May 2017 22:55:23 -0400 Subject: [PATCH 10/14] fixed --- .eslintrc | 18 ------------------ lib/print.js | 4 ++-- package.json | 4 ---- script/git-hooks/pre-commit.sh | 4 ++++ 4 files changed, 6 insertions(+), 24 deletions(-) delete mode 100644 .eslintrc create mode 100644 script/git-hooks/pre-commit.sh diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 10553e4..0000000 --- a/.eslintrc +++ /dev/null @@ -1,18 +0,0 @@ -{ - "extends": [ - "eslint:recommended", - "plugin:flowtype/recommended" - ], - "plugins": [ - "flowtype" - ], - "rules": { - "no-constant-condition": 0 - }, - "env": { - "browser": true, - "es6": true, - "node": true, - "mocha": true - } -} \ No newline at end of file diff --git a/lib/print.js b/lib/print.js index db8dad1..db52b41 100644 --- a/lib/print.js +++ b/lib/print.js @@ -64,8 +64,8 @@ const printApply = (node, parent) => { } else if (op === 'pow') { const exponent = node.args[1]; let bool = false; - if (exponent.args){ - if (isMul(exponent) || isDiv(exponent)){ + if (exponent.args) { + if (isMul(exponent) || isDiv(exponent)) { bool = true; } } diff --git a/package.json b/package.json index 26f792c..2813372 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,6 @@ "babel-plugin-transform-flow-strip-types": "^6.22.0", "babel-plugin-transform-object-rest-spread": "^6.22.0", "babel-preset-es2015": "^6.22.0", - "eslint": "^3.15.0", - "eslint-config-google": "^0.7.0", - "eslint-plugin-sort-requires": "^2.1.0", - "eslint-plugin-flowtype": "^2.30.0", "flow-bin": "^0.38.0", "mocha": "^3.2.0", "webpack": "^2.2.1" diff --git a/script/git-hooks/pre-commit.sh b/script/git-hooks/pre-commit.sh new file mode 100644 index 0000000..0c56671 --- /dev/null +++ b/script/git-hooks/pre-commit.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +npm test && +npm run lint From 348a9b1e2e458303128476311928d9381118d607 Mon Sep 17 00:00:00 2001 From: Anthony Date: Fri, 5 May 2017 22:56:46 -0400 Subject: [PATCH 11/14] removed script file --- script/git-hooks/pre-commit.sh | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 script/git-hooks/pre-commit.sh diff --git a/script/git-hooks/pre-commit.sh b/script/git-hooks/pre-commit.sh deleted file mode 100644 index 0c56671..0000000 --- a/script/git-hooks/pre-commit.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -npm test && -npm run lint From 0714ca16b50ac9e3135d9e6764d676a6114a41f9 Mon Sep 17 00:00:00 2001 From: Anthony Date: Fri, 5 May 2017 23:29:24 -0400 Subject: [PATCH 12/14] added eslintrc --- .eslintrc | 18 ++++++++++++++++++ test/print_test.js | 5 ++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..11bce1d --- /dev/null +++ b/.eslintrc @@ -0,0 +1,18 @@ +{ + "extends": [ + "eslint:recommended", + "plugin:flowtype/recommended" + ], + "plugins": [ + "flowtype" + ], + "rules": { + "no-constant-condition": 0 + }, + "env": { + "browser": true, + "es6": true, + "node": true, + "mocha": true + } +} diff --git a/test/print_test.js b/test/print_test.js index d52334c..5a4c90b 100644 --- a/test/print_test.js +++ b/test/print_test.js @@ -44,14 +44,13 @@ describe("print", () => { it("handles exponents correctly", () => { const tests = [ ['x^2', 'x^2'], - ['x^((x + 1)/(2 * 2))', 'x^((x + 1) / (2 * 2))'], - ['x^(y + 1)', 'x^(y + 1)'], ['x^(x / 2)','x^(x / 2)'], + ['x^(y + 1)', 'x^(y + 1)'], ['x^(x / (x + 2))', 'x^(x / (x + 2))'], + ['x^((x + 1)/(2 * 2))', 'x^((x + 1) / (2 * 2))'], ['x^(x + x + (x + y))', 'x^(x + x + (x + y))'], ['(y+1)^((x + 1) + 2)', '(y + 1)^((x + 1) + 2)'] ] - tests.forEach(test => assert.equal(print(parse(test[0])),test[1])) }) }) From 419714ce2471dfb4f4ee70dad4e4a4cac77aef50 Mon Sep 17 00:00:00 2001 From: Anthony Date: Fri, 5 May 2017 23:52:00 -0400 Subject: [PATCH 13/14] reverted package.json --- package.json | 2 ++ test/parser_test.js | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2813372..6d3829b 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,8 @@ "babel-plugin-transform-flow-strip-types": "^6.22.0", "babel-plugin-transform-object-rest-spread": "^6.22.0", "babel-preset-es2015": "^6.22.0", + "eslint": "^3.15.0", + "eslint-plugin-flowtype": "^2.30.0", "flow-bin": "^0.38.0", "mocha": "^3.2.0", "webpack": "^2.2.1" diff --git a/test/parser_test.js b/test/parser_test.js index 6926512..9a1f442 100644 --- a/test/parser_test.js +++ b/test/parser_test.js @@ -115,14 +115,14 @@ describe("Parser.parse", () => { // TODO: re-enable after changing parser to not produce a System (or eqns) // node. We should only be produce such a node for the following: // x + 2 = y, 3x - 5 = 2y, 2y - x = 10 - // suite("relations (n-ary)", [ - // 'a = b = c', + suite("relations (n-ary)", [ + 'a = b = c', // 'a > b > c', // 'a >= b >= c', // 'a < b < c', // 'a <= b <= c', // 'a != b != c', - // ]) + ]) }); // TODO: add tests verify different ways of writing the same thing, e.g. From f8fb1610175b46093f88d93a63e518dc57f62404 Mon Sep 17 00:00:00 2001 From: Anthony Date: Fri, 5 May 2017 23:55:02 -0400 Subject: [PATCH 14/14] oops --- test/parser_test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parser_test.js b/test/parser_test.js index 9a1f442..6926512 100644 --- a/test/parser_test.js +++ b/test/parser_test.js @@ -115,14 +115,14 @@ describe("Parser.parse", () => { // TODO: re-enable after changing parser to not produce a System (or eqns) // node. We should only be produce such a node for the following: // x + 2 = y, 3x - 5 = 2y, 2y - x = 10 - suite("relations (n-ary)", [ - 'a = b = c', + // suite("relations (n-ary)", [ + // 'a = b = c', // 'a > b > c', // 'a >= b >= c', // 'a < b < c', // 'a <= b <= c', // 'a != b != c', - ]) + // ]) }); // TODO: add tests verify different ways of writing the same thing, e.g.