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

@@ -1,3 +1,4 @@
/* eslint no-console:0, prefer-spread:0 */
"use strict";
var childProcess = require("child_process");
@@ -23,50 +24,50 @@ var opts = require("nomnom")
.option("browser", {
abbr: "b",
"default": "firefox",
help: "Name of the browser to use"
help: "Name of the browser to use",
})
.option("container", {
abbr: "c",
type: "string",
help: "Name or ID of a running docker container to contact"
help: "Name or ID of a running docker container to contact",
})
.option("seleniumURL", {
full: "selenium-url",
help: "Full URL of the Selenium web driver"
help: "Full URL of the Selenium web driver",
})
.option("seleniumIP", {
full: "selenium-ip",
help: "IP address of the Selenium web driver"
help: "IP address of the Selenium web driver",
})
.option("seleniumPort", {
full: "selenium-port",
"default": 4444,
help: "Port number of the Selenium web driver"
help: "Port number of the Selenium web driver",
})
.option("katexURL", {
full: "katex-url",
help: "Full URL of the KaTeX development server"
help: "Full URL of the KaTeX development server",
})
.option("katexIP", {
full: "katex-ip",
"default": "localhost",
help: "Full URL of the KaTeX development server"
help: "Full URL of the KaTeX development server",
})
.option("katexPort", {
full: "katex-port",
help: "Port number of the KaTeX development server"
help: "Port number of the KaTeX development server",
})
.option("include", {
abbr: "i",
help: "Comma-separated list of test cases to process"
help: "Comma-separated list of test cases to process",
})
.option("exclude", {
abbr: "x",
help: "Comma-separated list of test cases to exclude"
help: "Comma-separated list of test cases to exclude",
})
.option("verify", {
flag: true,
help: "Check whether screenshot matches current file content"
help: "Check whether screenshot matches current file content",
})
.parse();
@@ -121,7 +122,7 @@ if (!seleniumURL && opts.container) {
process.exit(2);
}
katexIP = config[1];
} catch(e) {
} catch (e) {
seleniumIP = katexIP = dockerCmd(
"inspect", "-f", "{{.NetworkSettings.Gateway}}", opts.container);
}
@@ -185,7 +186,7 @@ function tryConnect() {
}
var sock = net.connect({
host: seleniumIP,
port: +seleniumPort
port: +seleniumPort,
});
sock.on("connect", function() {
sock.end();
@@ -223,7 +224,8 @@ function buildDriver() {
//////////////////////////////////////////////////////////////////////
// Set the screen size
var targetW = 1024, targetH = 768;
var targetW = 1024;
var targetH = 768;
function setSize(reqW, reqH) {
return driver.manage().window().setSize(reqW, reqH).then(function() {
return driver.takeScreenshot();
@@ -247,7 +249,7 @@ function imageDimensions(img) {
return {
buf: buf,
width: buf.readUInt32BE(16),
height: buf.readUInt32BE(20)
height: buf.readUInt32BE(20),
};
}
@@ -310,7 +312,7 @@ function takeScreenshot(key) {
}
}
var opt = new jspngopt.Optimizer({
pako: pako
pako: pako,
});
var buf = opt.bufferSync(img.buf);
if (loadExpected) {

View File

@@ -1,3 +1,4 @@
/* eslint no-console:0 */
"use strict";
var childProcess = require("child_process");
@@ -47,7 +48,7 @@ Q.all([
readFile(path.join(ssDir, "test.tex"), "utf-8"),
ensureDir(tmpDir),
ensureDir(teximgDir),
ensureDir(diffDir)
ensureDir(diffDir),
]).spread(function(data) {
template = data;
// dirs have been created, template has been read, now rasterize.
@@ -78,14 +79,14 @@ function processTestCase(key) {
var fftLatex = writeFile(texFile, tex).then(function() {
// Step 2: call "pdflatex key" to create key.pdf
return execFile("pdflatex", [
"-interaction", "nonstopmode", key
"-interaction", "nonstopmode", key,
], {cwd: tmpDir});
}).then(function() {
console.log("Typeset " + key);
// Step 3: call "convert ... key.pdf key.png" to create key.png
return execFile("convert", [
"-density", dpi, "-units", "PixelsPerInch", "-flatten",
pdfFile, pngFile
pdfFile, pngFile,
]);
}).then(function() {
console.log("Rasterized " + key);
@@ -96,10 +97,11 @@ function processTestCase(key) {
var fftBrowser = readPNG(browserFile).then(fftImage);
return Q.all([fftBrowser, fftLatex]).spread(function(browser, latex) {
// Now we have the FFT result from both
// Now we have the FFT result from both
// Step 6: find alignment which maximizes overlap.
// This uses a FFT-based correlation computation.
var x, y;
var x;
var y;
var real = createMatrix();
var imag = createMatrix();
@@ -164,8 +166,8 @@ function processTestCase(key) {
"(", "-clone", "0-1", "-compose", "darken", "-composite", ")",
// First image is red, second green, third blue channel of result
"-channel", "RGB", "-combine",
"-trim", // remove everything that has the same color as the corners
diffFile // output file name
"-trim", // remove everything with the same color as the corners
diffFile, // output file name
]);
}).then(function() {
console.log("Compared " + key);
@@ -241,7 +243,7 @@ function fftImage(image) {
real: real,
imag: imag,
width: image.width,
height: image.height
height: image.height,
};
}