Permalink
Browse files

Run ESLint on test files, and fix lint errors in test files (#4732)

  • Loading branch information...
1 parent fd218ab commit c0038221d70459cf2c1115e8ff31f0791be53fa5 @DrewML DrewML committed with hzoo Oct 15, 2016
View
@@ -3,7 +3,6 @@ scripts
lib
packages/babel-runtime
packages/*/node_modules
-packages/*/test
packages/*/dist
vendor
_babel.github.io
View
@@ -4,6 +4,7 @@
"max-len": 0
},
"env": {
- "node": true
+ "node": true,
+ "mocha": true
}
}
View
@@ -18,10 +18,10 @@ watch: clean
./node_modules/.bin/gulp watch
lint:
- ./node_modules/.bin/eslint packages/*/src
+ ./node_modules/.bin/eslint packages/*/{src,test}/*.js
fix:
- ./node_modules/.bin/eslint packages/*/src --fix
+ ./node_modules/.bin/eslint packages/*/{src,test}/*.js --fix
clean: test-clean
rm -rf packages/*/lib
@@ -1,30 +1,30 @@
-var readdir = require("fs-readdir-recursive");
-var helper = require("babel-helper-fixtures");
-var assert = require("assert");
-var rimraf = require("rimraf");
-var outputFileSync = require("output-file-sync");
-var child = require("child_process");
-var path = require("path");
-var chai = require("chai");
-var fs = require("fs");
-var pathExists = require("path-exists");
-var _ = require("lodash");
-
-var fixtureLoc = path.join(__dirname, "fixtures");
-var tmpLoc = path.join(__dirname, "tmp");
-
-var presetLocs = [
+let readdir = require("fs-readdir-recursive");
+let helper = require("babel-helper-fixtures");
+let assert = require("assert");
+let rimraf = require("rimraf");
+let outputFileSync = require("output-file-sync");
+let child = require("child_process");
+let path = require("path");
+let chai = require("chai");
+let fs = require("fs");
+let pathExists = require("path-exists");
+let _ = require("lodash");
+
+let fixtureLoc = path.join(__dirname, "fixtures");
+let tmpLoc = path.join(__dirname, "tmp");
+
+let presetLocs = [
path.join(__dirname, "../../babel-preset-es2015"),
path.join(__dirname, "../../babel-preset-react")
].join(",");
-var pluginLocs = [
+let pluginLocs = [
path.join(__dirname, "/../../babel-plugin-transform-strict-mode"),
path.join(__dirname, "/../../babel-plugin-transform-es2015-modules-commonjs"),
].join(",");
-var readDir = function (loc) {
- var files = {};
+let readDir = function (loc) {
+ let files = {};
if (pathExists.sync(loc)) {
_.each(readdir(loc), function (filename) {
files[filename] = helper.readFile(path.join(loc, filename));
@@ -33,14 +33,14 @@ var readDir = function (loc) {
return files;
};
-var saveInFiles = function (files) {
+let saveInFiles = function (files) {
_.each(files, function (content, filename) {
outputFileSync(filename, content);
});
};
-var assertTest = function (stdout, stderr, opts) {
- var expectStderr = opts.stderr.trim();
+let assertTest = function (stdout, stderr, opts) {
+ let expectStderr = opts.stderr.trim();
stderr = stderr.trim();
if (opts.stderr) {
@@ -53,7 +53,7 @@ var assertTest = function (stdout, stderr, opts) {
throw new Error("stderr:\n" + stderr);
}
- var expectStdout = opts.stdout.trim();
+ let expectStdout = opts.stdout.trim();
stdout = stdout.trim();
stdout = stdout.replace(/\\/g, "/");
@@ -68,19 +68,19 @@ var assertTest = function (stdout, stderr, opts) {
}
_.each(opts.outFiles, function (expect, filename) {
- var actual = helper.readFile(filename);
+ let actual = helper.readFile(filename);
chai.expect(actual).to.equal(expect, "out-file " + filename);
});
};
-var buildTest = function (binName, testName, opts) {
- var binLoc = path.join(__dirname, "../lib", binName);
+let buildTest = function (binName, testName, opts) {
+ let binLoc = path.join(__dirname, "../lib", binName);
return function (callback) {
clear();
saveInFiles(opts.inFiles);
- var args = [binLoc];
+ let args = [binLoc];
if (binName !== "babel-external-helpers") {
args.push("--presets", presetLocs, "--plugins", pluginLocs);
@@ -92,10 +92,10 @@ var buildTest = function (binName, testName, opts) {
args = args.concat(opts.args);
- var spawn = child.spawn(process.execPath, args);
+ let spawn = child.spawn(process.execPath, args);
- var stderr = "";
- var stdout = "";
+ let stderr = "";
+ let stdout = "";
spawn.stderr.on("data", function (chunk) {
stderr += chunk;
@@ -106,7 +106,7 @@ var buildTest = function (binName, testName, opts) {
});
spawn.on("close", function () {
- var err;
+ let err;
try {
assertTest(stdout, stderr, opts);
@@ -128,7 +128,7 @@ var buildTest = function (binName, testName, opts) {
};
};
-var clear = function () {
+let clear = function () {
process.chdir(__dirname);
if (pathExists.sync(tmpLoc)) rimraf.sync(tmpLoc);
fs.mkdirSync(tmpLoc);
@@ -138,22 +138,22 @@ var clear = function () {
_.each(fs.readdirSync(fixtureLoc), function (binName) {
if (binName[0] === ".") return;
- var suiteLoc = path.join(fixtureLoc, binName);
+ let suiteLoc = path.join(fixtureLoc, binName);
suite("bin/" + binName, function () {
_.each(fs.readdirSync(suiteLoc), function (testName) {
if (testName[0] === ".") return;
- var testLoc = path.join(suiteLoc, testName);
+ let testLoc = path.join(suiteLoc, testName);
- var opts = {
+ let opts = {
args: []
};
- var optionsLoc = path.join(testLoc, "options.json");
+ let optionsLoc = path.join(testLoc, "options.json");
if (pathExists.sync(optionsLoc)) _.merge(opts, require(optionsLoc));
_.each(["stdout", "stdin", "stderr"], function (key) {
- var loc = path.join(testLoc, key + ".txt");
+ let loc = path.join(testLoc, key + ".txt");
if (pathExists.sync(loc)) {
opts[key] = helper.readFile(loc);
} else {
@@ -164,10 +164,10 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
opts.outFiles = readDir(path.join(testLoc, "out-files"));
opts.inFiles = readDir(path.join(testLoc, "in-files"));
- var babelrcLoc = path.join(testLoc, ".babelrc");
+ let babelrcLoc = path.join(testLoc, ".babelrc");
if (pathExists.sync(babelrcLoc)) {
// copy .babelrc file to tmp directory
- opts.inFiles['.babelrc'] = helper.readFile(babelrcLoc);
+ opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc);
}
test(testName, buildTest(binName, testName, opts));
@@ -1,6 +1,6 @@
-var assert = require("assert");
-var chalk = require("chalk");
-var codeFrame = require("..");
+let assert = require("assert");
+let chalk = require("chalk");
+let codeFrame = require("..");
suite("babel-code-frame", function () {
test("basic usage", function () {
@@ -98,7 +98,7 @@ suite("babel-code-frame", function () {
"\tclass Foo {",
"\t \t\t constructor\t(\t)",
"\t};",
- ].join('\n');
+ ].join("\n");
assert.equal(codeFrame(rawLines, 2, 25), [
" 1 | \tclass Foo {",
"> 2 | \t \t\t constructor\t(\t)",
@@ -119,7 +119,7 @@ suite("babel-code-frame", function () {
});
test("opts.linesAbove", function () {
- var rawLines = [
+ let rawLines = [
"/**",
" * Sums two numbers.",
" *",
@@ -143,7 +143,7 @@ suite("babel-code-frame", function () {
});
test("opts.linesBelow", function () {
- var rawLines = [
+ let rawLines = [
"/**",
" * Sums two numbers.",
" *",
@@ -166,7 +166,7 @@ suite("babel-code-frame", function () {
});
test("opts.linesAbove and opts.linesBelow", function () {
- var rawLines = [
+ let rawLines = [
"/**",
" * Sums two numbers.",
" *",
Oops, something went wrong.

0 comments on commit c003822

Please sign in to comment.