From 29b0ea269ac291d478f34af61c5a56b7d6a10ea5 Mon Sep 17 00:00:00 2001 From: Peter deHaan Date: Wed, 21 Sep 2016 16:38:41 -0700 Subject: [PATCH 1/2] chore: Add ESLint no-console and max-len rules --- .eslintrc.yml | 5 +++-- lib/firefox.js | 2 +- lib/post.js | 6 +++--- lib/rdf.js | 2 +- lib/sign.js | 8 ++++---- lib/utils.js | 2 +- test/documentation/test.docs.js | 2 +- test/functional/test.run.js | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 1f4557a..581e775 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -24,15 +24,16 @@ rules: eqeqeq: error indent: [error, 2, {SwitchCase: 1}] key-spacing: [error, {beforeColon: false, afterColon: true}] - max-len: [off, 80] # TODO: Set to warn|error? + max-len: [error, 80, {ignoreComments: true}] new-cap: error - no-console: off # TODO: Set to warn|error? + no-console: error no-mixed-spaces-and-tabs: error no-multi-str: error no-multiple-empty-lines: error no-spaced-func: error no-trailing-spaces: error no-unused-vars: [warn, {vars: all, args: none}] + no-warning-comments: warn no-with: error one-var: [error, never] operator-linebreak: [error, after] diff --git a/lib/firefox.js b/lib/firefox.js index 7e70bf1..1b05b9c 100644 --- a/lib/firefox.js +++ b/lib/firefox.js @@ -13,7 +13,7 @@ var GARBAGE = [ /\[JavaScript Warning: "TypeError: "[\w\d]+" is read-only"\]/, /JavaScript strict warning: /, /\#\#\#\!\!\! \[Child\]\[DispatchAsyncMessage\]/, - /JavaScript strict warning: resource:\/\/\/modules\/sessionstore\/SessionStore\.jsm/, + /JavaScript strict warning: resource:\/\/\/modules\/sessionstore\/SessionStore\.jsm/, // eslint-disable-line max-len /JavaScript strict warning: resource:\/\/gre\/components\/nsSearchService\.js/ ]; diff --git a/lib/post.js b/lib/post.js index 12a6994..3502cd3 100644 --- a/lib/post.js +++ b/lib/post.js @@ -40,16 +40,16 @@ function postXPI(manifest, options) { reject(e); }); client.on("close", function(hadError) { - console.log(hadError ? "Posting XPI to %s failed" : + console.log(hadError ? "Posting XPI to %s failed" : // eslint-disable-line no-console "Posted XPI to %s", postURL); fs.unlink(xpiPath); - console.log("Removed XPI from " + xpiPath); + console.log("Removed XPI from " + xpiPath); // eslint-disable-line no-console resolve(); }); }); }); }).then(null, function(err) { - console.error(err); + console.error(err); // eslint-disable-line no-console }); } module.exports = postXPI; diff --git a/lib/rdf.js b/lib/rdf.js index cfcdb05..4692b6d 100644 --- a/lib/rdf.js +++ b/lib/rdf.js @@ -10,7 +10,7 @@ var GUIDS = require("./settings").ids; var MIN_VERSION = require("./settings").MIN_VERSION; var MAX_VERSION = require("./settings").MAX_VERSION; -var UUID_PATTERN = /^\{([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\}$/; +var UUID_PATTERN = /^\{([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\}$/; // eslint-disable-line max-len // Copied from mozilla-central/addon-sdk/source/lib/sdk/bootstrap.js function realDomain(id) { diff --git a/lib/sign.js b/lib/sign.js index 81667d3..beebd57 100644 --- a/lib/sign.js +++ b/lib/sign.js @@ -57,11 +57,11 @@ function sign(options, config) { } }); if (missingOptions.length) { - console.error(); + console.error(); // eslint-disable-line no-console missingOptions.forEach(function(flag) { - console.error(" error: missing required option `%s'", flag); + console.error(" error: missing required option `%s'", flag); // eslint-disable-line no-console }); - console.error(); + console.error(); // eslint-disable-line no-console return reject(); } @@ -145,7 +145,7 @@ function signCmd(program, options, config) { }).catch(function(err) { logger.error("FAIL"); if (err) { - console.error(err.stack); + console.error(err.stack); // eslint-disable-line no-console } config.systemProcess.exit(1); }); diff --git a/lib/utils.js b/lib/utils.js index 62e8624..06f2fd0 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -70,7 +70,7 @@ function log(type) { var first = "JPM [" + type + "] " + (messages.shift() + ""); if (process.env.NODE_ENV !== "test") { - console.log.apply(console, [first].concat(messages)); + console.log.apply(console, [first].concat(messages)); // eslint-disable-line no-console } } diff --git a/test/documentation/test.docs.js b/test/documentation/test.docs.js index 0247035..4910a92 100644 --- a/test/documentation/test.docs.js +++ b/test/documentation/test.docs.js @@ -52,7 +52,7 @@ describe("Spell Checking", function() { if (results.length > 0) { // prints all the teacher results (even the ignored suggestions) - console.log(JSON.stringify(results, null, 2)); + console.log(JSON.stringify(results, null, 2)); // eslint-disable-line no-console } // filter out results with descriptions which we do not want to consider as errors diff --git a/test/functional/test.run.js b/test/functional/test.run.js index 7462ce3..fb81b1f 100644 --- a/test/functional/test.run.js +++ b/test/functional/test.run.js @@ -254,7 +254,7 @@ describe("jpm run", function() { json = JSON.parse(data); } catch (e) { - console.log("Something is wrong with output:\n" + output); + console.log("Something is wrong with output:\n" + output); // eslint-disable-line no-console } return json; } From 518ec3a331bd461083fbfbdd79092a37a74a635d Mon Sep 17 00:00:00 2001 From: Peter deHaan Date: Thu, 22 Sep 2016 11:06:49 -0700 Subject: [PATCH 2/2] chore: Switch from console.log to logger.info --- lib/post.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/post.js b/lib/post.js index 3502cd3..74a6d3c 100644 --- a/lib/post.js +++ b/lib/post.js @@ -9,6 +9,8 @@ var fs = require("fs"); var url = require("url"); var net = require("net"); var when = require("when"); +var utils = require("./utils"); +var logger = utils.console; function postXPI(manifest, options) { var postURL = options.postUrl; @@ -40,10 +42,13 @@ function postXPI(manifest, options) { reject(e); }); client.on("close", function(hadError) { - console.log(hadError ? "Posting XPI to %s failed" : // eslint-disable-line no-console - "Posted XPI to %s", postURL); + if (hadError) { + logger.error("Posting XPI to " + postURL + " failed"); + } else { + logger.info("Posted XPI to " + postURL); + } fs.unlink(xpiPath); - console.log("Removed XPI from " + xpiPath); // eslint-disable-line no-console + logger.info("Removed XPI from " + xpiPath); resolve(); }); });