You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would this repository be open to having jshint / jscs added to it and following their tool-assisted guidelines? I'd love to submit a PR but I don't want to do it if it won't be accepted.
The code in this repository is currently being broken up into a variety of smaller modules for D3 4.0; see #2461. So, if and when we adopt jshint or other, it should be done in the new repos.
Historically I have not been in favor of using jshint; I find it generates too many false-positive warnings and is more of a distraction than a time-saver or quality-improver. However, I am receptive to arguments to the contrary if you can demonstrate that these hints will be useful and not a distraction. Please take a look at the new modules and let me know.
A brief listing of what they do here (in case you're not familiar):
esnext - turn on ES6 mode
eqeqeq - turn off strict type checking with ===
eqnull - turn on the lax setting to turn off == null warnings
laxbreak - turn on the lax setting to turn off warnings about putting operators at the beginning of the line instead of the end (more info here). this one I was hesitant to turn off, but in most cases it was fine. In the cases where you do string concat this way, it may make more sense to use ES6 template strings
-W058 - turns off errors for not invoking a constructor with () (see here). I understand this is a code style thing, so I didn't think it made sense to keep it in.
-W030 - turns off warnings about inline assignments (when expecting expressions), ie, var x = (y = z) == null ? a : b (more here) -- again, this appears to be a stylistic thing. However, this can be really, really confusing for people looking at your code, but it's not really so bad.
After this, I was left with this error log. Some of the smaller errors that didn't appear often, I just left in, otherwise I'd be turning off a bunch of flags that I'd have to explain later, haha.
Some of the common things I'm seeing:
Lots of numbers that could be prefaced with 0 (instead of .75, 0.75). This one, I understand, is a code style, but I personally think it's better to just put the 0 there. Of course, this can be disabled with -W008: false
Some missing semicolons
Some unnecessary semicolons
Returning with an assignment (this goes back to the "pulling vars out before using them" remark I made before)
Using variables out of scope (I think this is a good one to catch, because while JS allows this, it might make your transition to ES6 easier if you did not do this -- then you could change var to let).
Re-defining variables (it's just unnecessary, and doing this might cause some small issues down the line with refactoring or transitioning to ES6)
It really does not like the unary + operator. I dunno, I kinda like the quick coercion there, but I figured it merited a mention because it can be confusing in some cases (+var + +var2).
I think a lot of the noise you see with tools like JSHint is just due to your code style (which is neither good nor a bad thing), but I still think it can help catch some potentially bad things (semicolon, variable-related issues).
I haven't even thought about JSCS for a library like this, but that might also be something to consider down the line -- you can define a custom code style, and JSCS will fix all of the code so it matches (with no developer intervention necessary). That might help with some of the more style-related issues and help others adapt to your style when writing code for d3.
If we still want to consider using JSCS I can help with this or create a PR to do so. You can create a custom config .jscsrc (set of rules) to work across all repos as a another repo/npm module like this, and like @seiyria said the --autofix feature works on most rules so you shouldn't have to many fix many rules manually if you come across a huge amount of style issues initially.
d3 is moving towards ES6 everything, and eslint is the best choice to facilitate everything ES6. jshint and jscs are great for es5 but they're deprecated in favor of eslint for going forward.
What do you mean by "jshint and jscs" are being deprecated? They actually both support ES6 fine with the "esnext": true flag. JSCS/ESLint both use Esprima which supports ES6. The reason to not use the jshint/jscs shouldn't be because they don't support ES6 though.
However, If you mean ES6+, JSX, flow support then yes jshint won't support anything < stage 2. Both babel and jscs use babel to support ES6+ features (I'm maintaining babel-eslint). But they are all good!
Activity
mbostock commentedon Jun 10, 2015
The code in this repository is currently being broken up into a variety of smaller modules for D3 4.0; see #2461. So, if and when we adopt jshint or other, it should be done in the new repos.
Historically I have not been in favor of using jshint; I find it generates too many false-positive warnings and is more of a distraction than a time-saver or quality-improver. However, I am receptive to arguments to the contrary if you can demonstrate that these hints will be useful and not a distraction. Please take a look at the new modules and let me know.
seiyria commentedon Jun 10, 2015
I ran all of the tooling against the current master branch, as of a few hours ago.
Here was the jshint file I ended up with:
A brief listing of what they do here (in case you're not familiar):
esnext- turn on ES6 modeeqeqeq- turn off strict type checking with ===eqnull- turn on the lax setting to turn off== nullwarningslaxbreak- turn on the lax setting to turn off warnings about putting operators at the beginning of the line instead of the end (more info here). this one I was hesitant to turn off, but in most cases it was fine. In the cases where you do string concat this way, it may make more sense to use ES6 template strings-W058- turns off errors for not invoking a constructor with()(see here). I understand this is a code style thing, so I didn't think it made sense to keep it in.-W030- turns off warnings about inline assignments (when expecting expressions), ie,var x = (y = z) == null ? a : b(more here) -- again, this appears to be a stylistic thing. However, this can be really, really confusing for people looking at your code, but it's not really so bad.After this, I was left with this error log. Some of the smaller errors that didn't appear often, I just left in, otherwise I'd be turning off a bunch of flags that I'd have to explain later, haha.
Some of the common things I'm seeing:
.75,0.75). This one, I understand, is a code style, but I personally think it's better to just put the 0 there. Of course, this can be disabled with-W008: falsevartolet).I think a lot of the noise you see with tools like JSHint is just due to your code style (which is neither good nor a bad thing), but I still think it can help catch some potentially bad things (semicolon, variable-related issues).
I haven't even thought about JSCS for a library like this, but that might also be something to consider down the line -- you can define a custom code style, and JSCS will fix all of the code so it matches (with no developer intervention necessary). That might help with some of the more style-related issues and help others adapt to your style when writing code for d3.
hzoo commentedon Oct 18, 2015
If we still want to consider using JSCS I can help with this or create a PR to do so. You can create a custom config
.jscsrc(set of rules) to work across all repos as a another repo/npm module like this, and like @seiyria said the--autofixfeature works on most rules so you shouldn't have to many fix many rules manually if you come across a huge amount of style issues initially.seiyria commentedon Oct 18, 2015
To be honest, I would recommend eslint now, given the direction d3 is going. However, most of the rules are translateable relatively easily.
hzoo commentedon Oct 18, 2015
That's fine too - I'm involved with both (moreso with JSCS now) so either is cool. What do you mean by "the direction d3 is going"?
seiyria commentedon Oct 18, 2015
d3 is moving towards ES6 everything, and eslint is the best choice to facilitate everything ES6. jshint and jscs are great for es5 but they're deprecated in favor of eslint for going forward.
hzoo commentedon Oct 18, 2015
What do you mean by "jshint and jscs" are being deprecated? They actually both support ES6 fine with the
"esnext": trueflag. JSCS/ESLint both use Esprima which supports ES6. The reason to not use the jshint/jscs shouldn't be because they don't support ES6 though.However, If you mean ES6+, JSX, flow support then yes jshint won't support anything < stage 2. Both babel and jscs use babel to support ES6+ features (I'm maintaining babel-eslint). But they are all good!
Format small numbers with leading zero.
mbostock commentedon Mar 1, 2016
I’ve adopted ESLint for the new D3 modules, so closing this issue.
seiyria commentedon Mar 1, 2016
even better. +1
hzoo commentedon Mar 1, 2016
Cool, 👍 If you want to manage the style across all the repos maybe look into a shareable config http://eslint.org/docs/developer-guide/shareable-configs (so you don't have to make the same change in each repo)