Migrate to eslint

Summary
We'd like contributors to use the same linter and lint rules that we use
internally.  This diff swaps out eslint for jshint and fixes all lint failures
except for the max-len failures in the test suites.

Test Plan:
- ka-lint src
- make lint
- make test

Reviewers: emily
This commit is contained in:
Kevin Barabash
2015-11-30 20:52:22 -08:00
parent 1a082e81d9
commit 14a58adb90
34 changed files with 2271 additions and 2206 deletions

View File

@@ -13,12 +13,13 @@ beforeEach(function() {
compare: function(actual, left, right, result) {
var message = {
pass: true,
message: "'" + actual + "' split correctly"
message: "'" + actual + "' split correctly",
};
var startData = [{type: "text", data: actual}];
var split = splitAtDelimiters(startData, left, right, false);
var split =
splitAtDelimiters(startData, left, right, false);
if (split.length !== result.length) {
message.pass = false;
@@ -58,9 +59,9 @@ beforeEach(function() {
}
return message;
}
},
};
}
},
});
});
@@ -69,12 +70,12 @@ describe("A delimiter splitter", function() {
expect("hello").toSplitInto("(", ")", [{type: "text", data: "hello"}]);
});
it("doesn't create a math node when there's only a left delimiter", function() {
it("doesn't create a math node with only one left delimiter", function() {
expect("hello ( world").toSplitInto(
"(", ")",
[
{type: "text", data: "hello "},
{type: "text", data: "( world"}
{type: "text", data: "( world"},
]);
});
@@ -82,7 +83,7 @@ describe("A delimiter splitter", function() {
expect("hello ) world").toSplitInto(
"(", ")",
[
{type: "text", data: "hello ) world"}
{type: "text", data: "hello ) world"},
]);
});
@@ -93,7 +94,7 @@ describe("A delimiter splitter", function() {
{type: "text", data: "hello "},
{type: "math", data: " world ",
rawData: "( world )", display: false},
{type: "text", data: " boo"}
{type: "text", data: " boo"},
]);
});
@@ -104,7 +105,7 @@ describe("A delimiter splitter", function() {
{type: "text", data: "hello "},
{type: "math", data: " world ",
rawData: "[[ world ]]", display: false},
{type: "text", data: " boo"}
{type: "text", data: " boo"},
]);
});
@@ -118,7 +119,7 @@ describe("A delimiter splitter", function() {
{type: "text", data: " boo "},
{type: "math", data: " more ",
rawData: "( more )", display: false},
{type: "text", data: " stuff"}
{type: "text", data: " stuff"},
]);
});
@@ -130,7 +131,7 @@ describe("A delimiter splitter", function() {
{type: "math", data: " world ",
rawData: "( world )", display: false},
{type: "text", data: " boo "},
{type: "text", data: "( left"}
{type: "text", data: "( left"},
]);
});
@@ -141,7 +142,7 @@ describe("A delimiter splitter", function() {
{type: "text", data: "hello "},
{type: "math", data: " world { ) } ",
rawData: "( world { ) } )", display: false},
{type: "text", data: " boo"}
{type: "text", data: " boo"},
]);
expect("hello ( world { { } ) } ) boo").toSplitInto(
@@ -150,7 +151,7 @@ describe("A delimiter splitter", function() {
{type: "text", data: "hello "},
{type: "math", data: " world { { } ) } ",
rawData: "( world { { } ) } )", display: false},
{type: "text", data: " boo"}
{type: "text", data: " boo"},
]);
});
@@ -161,7 +162,7 @@ describe("A delimiter splitter", function() {
{type: "text", data: "hello "},
{type: "math", data: " world \\) ",
rawData: "( world \\) )", display: false},
{type: "text", data: " boo"}
{type: "text", data: " boo"},
]);
/* TODO(emily): make this work maybe?
@@ -171,7 +172,7 @@ describe("A delimiter splitter", function() {
{type: "text", data: "hello \\( "},
{type: "math", data: " world ",
rawData: "( world )", display: false},
{type: "text", data: " boo"}
{type: "text", data: " boo"},
]);
*/
});
@@ -183,7 +184,7 @@ describe("A delimiter splitter", function() {
{type: "text", data: "hello "},
{type: "math", data: " world ",
rawData: "$ world $", display: false},
{type: "text", data: " boo"}
{type: "text", data: " boo"},
]);
});
@@ -195,7 +196,7 @@ describe("A delimiter splitter", function() {
{type: "text", data: "hello "},
{type: "math", data: " world ",
rawData: "( world )", display: true},
{type: "text", data: " boo"}
{type: "text", data: " boo"},
]);
});
@@ -203,7 +204,7 @@ describe("A delimiter splitter", function() {
var startData = [
{type: "text", data: "hello ( world ) boo"},
{type: "math", data: "math", rawData: "(math)", display: true},
{type: "text", data: "hello ( world ) boo"}
{type: "text", data: "hello ( world ) boo"},
];
expect(splitAtDelimiters(startData, "(", ")", false)).toEqual(
@@ -216,7 +217,7 @@ describe("A delimiter splitter", function() {
{type: "text", data: "hello "},
{type: "math", data: " world ",
rawData: "( world )", display: false},
{type: "text", data: " boo"}
{type: "text", data: " boo"},
]);
});
@@ -224,7 +225,7 @@ describe("A delimiter splitter", function() {
var startData = [
{type: "text", data: "hello ( world ) boo"},
{type: "math", data: "hello ( world ) boo",
rawData: "(hello ( world ) boo)", display: true}
rawData: "(hello ( world ) boo)", display: true},
];
expect(splitAtDelimiters(startData, "(", ")", false)).toEqual(
@@ -234,7 +235,7 @@ describe("A delimiter splitter", function() {
rawData: "( world )", display: false},
{type: "text", data: " boo"},
{type: "math", data: "hello ( world ) boo",
rawData: "(hello ( world ) boo)", display: true}
rawData: "(hello ( world ) boo)", display: true},
]);
});
});

View File

@@ -1,3 +1,4 @@
/* eslint no-console:0 */
/* global katex */
var splitAtDelimiters = require("./splitAtDelimiters");
@@ -26,7 +27,7 @@ var renderMathInText = function(text, delimiters) {
var math = data[i].data;
try {
katex.render(math, span, {
displayMode: data[i].display
displayMode: data[i].display,
});
} catch (e) {
if (!(e instanceof katex.ParseError)) {
@@ -72,19 +73,20 @@ var defaultOptions = {
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "\\[", right: "\\]", display: true},
{left: "\\(", right: "\\)", display: false}
{left: "\\(", right: "\\)", display: false},
// LaTeX uses this, but it ruins the display of normal `$` in text:
// {left: "$", right: "$", display: false}
// {left: "$", right: "$", display: false},
],
ignoredTags: [
"script", "noscript", "style", "textarea", "pre", "code"
]
"script", "noscript", "style", "textarea", "pre", "code",
],
};
var extend = function(obj) {
// Adapted from underscore.js' `_.extend`. See LICENSE.txt for license.
var source, prop;
var source;
var prop;
for (var i = 1, length = arguments.length; i < length; i++) {
source = arguments[i];
for (prop in source) {

View File

@@ -1,3 +1,4 @@
/* eslint no-constant-condition:0 */
var findEndOfMath = function(delimiter, text, startIndex) {
// Adapted from
// https://github.com/Khan/perseus/blob/master/src/perseus-markdown.jsx
@@ -42,7 +43,7 @@ var splitAtDelimiters = function(startData, leftDelim, rightDelim, display) {
currIndex = nextIndex;
finalData.push({
type: "text",
data: text.slice(0, currIndex)
data: text.slice(0, currIndex),
});
lookingForLeft = false;
}
@@ -56,7 +57,7 @@ var splitAtDelimiters = function(startData, leftDelim, rightDelim, display) {
finalData.push({
type: "text",
data: text.slice(currIndex, nextIndex)
data: text.slice(currIndex, nextIndex),
});
currIndex = nextIndex;
@@ -77,7 +78,7 @@ var splitAtDelimiters = function(startData, leftDelim, rightDelim, display) {
rawData: text.slice(
currIndex,
nextIndex + rightDelim.length),
display: display
display: display,
});
currIndex = nextIndex + rightDelim.length;
@@ -88,7 +89,7 @@ var splitAtDelimiters = function(startData, leftDelim, rightDelim, display) {
finalData.push({
type: "text",
data: text.slice(currIndex)
data: text.slice(currIndex),
});
} else {
finalData.push(startData[i]);