Skip to content
This repository has been archived by the owner on Nov 27, 2019. It is now read-only.

chore: Add ESLint no-console and max-len rules #587

Merged
merged 2 commits into from
Sep 22, 2016

Conversation

pdehaan
Copy link
Contributor

@pdehaan pdehaan commented Sep 21, 2016

Ref #585

@pdehaan
Copy link
Contributor Author

pdehaan commented Sep 22, 2016

Unfortunately there isn't currently a great way to have ESLint ignore really long regular expressions, so I had to use // eslint-disable-line max-len.

Once a fix for eslint/eslint#3229 lands, we can remove those shameful eslint-disable-lines and use the new max-len options instead.

@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit weird since the console.log() is wrapped on 2 lines, but I had to put the comment on the same line as opening console.log().

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's one log change needed and maybe some regex line wrapping (if it works).

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be switched to the logger. You can set it up like this at the top of the module:

var utils = require("./utils");
var logger = utils.console;

And use it like either logger.info(...) or logger.error(...)

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be concatenated and broken into separate lines like /first/ + /second/ ? That might be harder to read, I'm not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you concatenate Regular Expressions?
Do half these even need to be regular expressions vs plain strings?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, well, it's legacy cruft for sure. I wouldn't worry about it too much, eslint disable comments are fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't feel like putting in TOO much effort on this, since it seems like ESLint has a fix in progress for ignoring long regular expressions.

@@ -57,11 +57,11 @@ function sign(options, config) {
}
});
if (missingOptions.length) {
console.error();
console.error(); // eslint-disable-line no-console
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all these do need to be direct console calls. I forget why exactly but there was some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only reason I can think of was to add some extra leading/trailing whitespace in the console.
I was trying to figure out how to wrap this in a single console.error() call, but it was a confusing mix of:

var errors = missingOptions.map(function(flag) {
  return `  error: missing required option '${flag}'`;
});
console.error(`\n${errors.join("\n")}\n`); // eslint-disable-line no-console

And I wasn't convinced that my theory would be any cleaner or clearer.

logger.error("Posting XPI to " + postURL + " failed");
} else {
logger.info("Posted XPI to " + postURL);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I guess I should also call out that I slightly changed the logic here, where I converted this to an if..else instead of a ternery statement, because it let me use logger.error() and logger.info() a bit more appropriately [said the guy with zero context].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that, looks good

@kumar303
Copy link
Contributor

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants