-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Lint with eslint #172
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
Lint with eslint #172
Conversation
- one root level file with all the rules - plus one per set of js environments
- so that eslint . from the root gives the desired results
"browser": true | ||
}, | ||
"rules": { | ||
"strict": [2, "global"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best part about eslint
for me:
We can lint the whole project with no config repetition. eslint
is smart enough to extend local and root config options.
Let's get some style in plotly.js! 💃 |
"no-spaced-func": [2], | ||
"space-in-parens": [2, "never"], | ||
"space-before-function-paren": [0, "never"], | ||
"no-multi-spaces": [0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bye bye
var someVar = 10;
var someOtherVar = 12;
@@ -11,7 +13,7 @@ anchor.style.width = '1000px'; | |||
|
|||
function plotButtons(plots, figDir) { | |||
|
|||
Object.keys(plots).forEach( function (plotname) { | |||
Object.keys(plots).forEach(function (plotname) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want the space between function
and (plotname)
(sorry I think I'm a little confused with the controversial spacing rule)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope! Parentheses for a function should always be butted up against a name, or function
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The major part of the plotly.js code has:
Object.keys(plots).forEach(function(plotname) {
// ...
});
eslint checks it using the space-before-function-paren
rule: https://github.com/plotly/plotly.js/blob/eslint/.eslintrc#L25
which isn't considered an error (yet).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok adding 1 commit fixing all function ()
instances? That should take me ~ 20 mins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 @mdtusz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@etpinard (for me) just wanted to make sure I was understanding that rule. I'm okay with or without the commit for all function ()
instances
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cldougl if you're using sublime text, you can edit your snippets to match that style using the Package Resource Viewer package - I had to change it for mine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh cool, I'll try that
Looks good to me 💃 |
@alexcjohnson @mdtusz @cldougl @bpostlethwaite
I wanted to try eslint, and I ended up spending the whole afternoon going through its extensive set of rules and options (see http://eslint.org/docs/rules/)
It has the potential to be our one-and-only auto style guide. Consistent, non-arbitrary style rules coming the plotly.js 🎉 !
eslint is noticeably slower than jshint, so it might not be ready for live linting inside a text editor, but it is certainly ready and very useful for some pre-commit checks using
npm run lint
.