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
Add eslint for source code #1070
Conversation
Rules configured mostly conform to [JavaScript Standard Style](https://github.com/feross/standard) Rules are set to warn, so that they can be added and worked on without breaking tests.
I've made sure that all linting rules are warnings, such that this could be merged at any time and will not break the tests. I still would recommend agreeing on the rules before going forward with updating the code. |
👍 I'm not too familiar with eslint rules, I've been using jshint and pretty much stick with the defaults. @IanVS do you have any opinions about which rules we should change in regards to the defaults? |
ESLint has pretty minimal "default" rules, and even those will be going away in the upcoming 1.0 release. It bills itself as unopinionated. The "JavaScript Standard Style" is a pretty good set of rules I think. Perhaps what I can do is make a sample commit for each of the rules, with one change, so you can see the diff and decide if you like it. I'm not too familiar with the waterline code base, so it's hard for me to say which rules make the most sense for you. |
The commits named "Fix ESLint Rule" are the easy ones (mechanical, not much thought needed, not an overwhelming number of them). For the rest of the changes, I'll do a few examples as a "preview" and ask for guidance before continuing. |
I'm good with these changes. But would like hear other people's opinions such as @devinivy, @tjwebb and @particlebanana. |
I think it's great 👍 |
Would you like me to squash these commits before proceeding to the slightly-more-difficult changes? Or, I'm happy to leave them separate, which I think makes it very clear to see what was done for each rule (both now and in the future). |
JS Standard Style wants initialized variables to have their own var statement. For example: ```js // Initialized variables var foo = bar; var baz = bang; // Uninitialized variables are okay to combine (but not required) var a, b, c; ```
This rule requires or prohibits spaces after keywords like for, if, else, etc. The waterline codebase is pretty inconsistent here, but leans towards no spaces: Errors when requiring spaces: 631 Errors when prohibiting spaces: 177
JS Standard Style wants a space before function parenthesis, but that results in *553 errors* Requiring a space after anonymous functions results in *466 errors* Prohibiting a space results in *83 errors*
Pretty straightforward here. Should not define variables which are not used.
JS Standard style prohibits more than 1 empty line. This results in *153 errors* If 2 empty lines are allowed, there are *32 errors*
JS Standard Style follows the "One True Brace Style" (1tbs) but allows single lines See http://eslint.org/docs/rules/brace-style for more details. There are currently *28 errors* following this style.
There are approximately 7 errors aside from the one fixed in this commit. It seems most of them are bugs, and should all be investigated by the waterline team.
Please take a look at the commit messages labeled "Example" and give your feedback on whether to proceed with fixing the code as I started, or whether we should tweak the rules more to your liking. There are a handful of other rules I did not attempt to fix. These are: 9 errors: new-cap: [1, { "newIsCap": true, "capIsNew": false }] I think these are all pretty reasonable, and they can be left in a warning state until the Waterline team can examine and fix them, or turn the rules off if they can't be fixed. I just don't have the knowledge of your code needed to fix those four rules. |
@IanVS, the PR is good for now. Lets see if we can get some feedback from @particlebanana or @tjwebb. |
Hopefully there can be a review soon, so I don't need to rebase with master and then make even more changes to fix new linting errors. 😉 |
@IanVS I'm looking over this today, not familiar with ESLint so I'm looking over it and all the rules we have here. |
@particlebanana Awesome, thanks. It can take a little time to research the rules, but I've found the docs to be quite good. The configuration I'm proposing here mostly follows https://github.com/feross/eslint-config-standard/blob/master/eslintrc.json, with a few exceptions as mentioned. If you have any questions, let me know and I'll be happy to try to answer. |
This is awesome! Thanks @IanVS and I'm ashamed of some of the stuff in there! |
Add eslint for source code
Haha, lets work on getting a nice set of rules that make sense to us, fix all issues and then make rules return errors when broken! :) Thanks @IanVS! |
Great, glad this is useful. Here are what I see as the decisions to be made:
For now I can work on the other rules like
Now that this is merged, linting will occur on each test run, but it will look a little overwhelming. You can also use |
Given how abundantly empty lines are used in waterline I vote for allowing 2 lines (this will still allow just one line, right?). |
Yes, it just means max of two sequential empty lines. |
I vote,
|
I vote: no-multiple-empty-lines: 2 |
I vote for one max empty line. We can split the different and make it 1.5? :) |
I'm afraid your math is off: @dmarcelino : 2 Average: 1.75 😛 |
Lint Rule Cleanup (continuation of #1070)
I think @Globegitter has been pretty busy lately, so this is an offer to implement just the linting part of #935. I am willing to go through and try to fix failing rules, but I would like to get consensus on what the rules should be prior to spending the effort. With the rules from #935 (currently in this PR), I get the following results:
(Note that all these screenshots are cropped on the right, a few bars are much longer)
Another strategy to avoid bikeshedding and arguing over rules, would be to use eslint-config-standard. With that set of rules, these are the results:
My suggestion would be to override the following rules to more closely align with the existing codebase:
The results of these three changes results in something pretty manageable:
What say ye?