Skip to content

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

Merged
merged 16 commits into from
Jan 11, 2016
Merged

Lint with eslint #172

merged 16 commits into from
Jan 11, 2016

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Jan 8, 2016

@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.

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

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.

@mdtusz
Copy link
Contributor

mdtusz commented Jan 8, 2016

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

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) {
Copy link
Member

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)

Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

👍 @mdtusz

Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member

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

@cldougl
Copy link
Member

cldougl commented Jan 11, 2016

Looks good to me 💃

etpinard added a commit that referenced this pull request Jan 11, 2016
@etpinard etpinard merged commit dca7314 into master Jan 11, 2016
@etpinard etpinard deleted the eslint branch January 11, 2016 23:13
@etpinard etpinard mentioned this pull request Jan 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants