-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure our specific needs for JavaScript style checking #8
Comments
I think it would be good to configure all settings explicitly, even when we use the same value as the implicit default.
|
I suggest we try to use an eslint rule for overwriting the |
…pressions` during development but not in the testing pipeline. #8
I'm leaning towards single quotes for JavaScript and CSS, double quotes for HTML. Reasons:
var href = explicit ? "" : ".";
var snippet = '<a href="?q=test">hello world</a>'; var href = explicit ? '' : '.';
var snippet = '<a href="?q=test">hello world</a>';
@Yolijn Decision day! |
Just found out I can convert the entire codebase to single quotes with this oneliner on the command line: eslint --fix --no-eslintrc --rule "quotes: ['error', 'single', { 'avoidEscape': true }]" src/ |
Single quotes it is! Jay. |
Curly braces on the same line or the next line? function (a) {
if (a) {
return 1;
}
else {
return -1;
}
} Or: function (a)
{
if (a)
{
return 1;
}
else
{
return -1;
}
} Or: function (a)
{
if (a) {
return 1;
} else {
return -1;
}
} Or: function (a)
{
if (a) {
return 1;
}
else {
return -1;
}
} Or: function (a) {
if (a) {
return 1;
}
else {
return -1;
}
} Example scripts: Observations:
|
Regarding the
// Before implementing `valueOf`:
if (xslTemplate.qName.namespaceURI === "http://www.w3.org/1999/xhtml" &&
xslTemplate.qName.name === "script") {
}
// After implementing `valueOf`:
if (xslTemplate.qName == "{http://www.w3.org/1999/xhtml}script") {
}
Regarding the option
|
I've forked and tweaked eslint to support configuring custom types in When you use {
"rules": {
"valid-typeof": ["error", { "allow": ["unknown"] }]
}
} This way
|
I have disabled the Character.NON_LOWER_ASCII = /[^\x00-\x7f]/g The use case for this test is of course accidental uses of control characters, and it seems that it is all too easy to put an escape slash in front of a zero:
|
With great power comes great responsibility: I'm moving the For example:
Also, because we need to prevent minifying of properties sometimes:
|
I guess we should have the setup for the
|
These are best left to Closure Compiler:
The following are ES6 rules and need to be defined when we start using ES6. Currently set to off:
Some rules are disabled because they are taken care off by other rules:
|
Regarding Bad: var index, length, obj,
array = [];
index = 0;
length = array.length;
if (enabled) {
obj = {};
} Good: var obj,
index = 0,
length = array.length,
array = [];
if (enabled) {
obj = {};
} This is not possible with eslint currently, but we could implement it. |
The should be warnings in
Of course we shouldn't allow this in the high-quality repository, but we should enable warnings for this in the meantime. |
regexp.replace(function ()_, firstName, _, _, lastName) {
}); |
|
|
|
foo == null
forfoo === null || foo === undefined
. (Although ultimately, I prefer the explicit version when the Closure Compiler optimizes this and combines the two===
comparisons into one.)typeof foo == "string"
. This might require writing aneslint
plugin.There are a couple of eslint rules I initally wanted to use but prove problematic:
no-multi-spaces
results in a lot of warnings, because I like to align similar equals statements and variable assignments. For example:no-unused-expressions
results in many, many errors because I use empty property reference to annotate them for the Closure Compiler. For example:Fortunately the Closure Compiler also supports detection of unused expressions, so it isn't a blocking issue, but during development it would still be great to have eslint errors for unused code inside Sublime.
no-magic-numbers
results in an incredible amount of warnings, especially for references to array and string indexes, which are completely valid. For example:arr[arr.length - 1]
no-unsafe-finally
results in the errorDefinition for rule 'no-unsafe-finally' was not found
-- perhaps it is a feature that hasn't been released yet.no-implicit-globals
results in warnings forvar
declarations in Node.js scripts. This rule should only apply to AMD modules and browser scripts.no-extra-parens
warns for "Gratuitous parentheses around expression" for JSDoc type casting workarounds for the Closure Compiler, and of course rightfully so, it is a strange and undesirable workaround... For example:no-self-assign
is also causing problems with these JSDoc type casting workarounds...no-inline-comments
is also triggered for type cast annotations:I would like to tweak the implementation of this rule to recognize JSDoc comments.
no-unmodified-loop-condition
is causing warnings for this situation becausel
is unmodified, but this is a perfectly valid use case (in unit tests).valid-typeof
doesn't allowtypeof arg === 'unknown'
, which is returned by Internet Explorer 6-8. Guess we need to fix eslint to support'unknown'
.var undefined = null;
andfunction undefined() {}
should not be allowed. Comments by @Yolijn pointed out this wasn't being checked for by eslint currently. Must prevent variable assignmentsThe text was updated successfully, but these errors were encountered: