Skip to content
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

Merged
merged 27 commits into from Jul 8, 2015
Merged

Add eslint for source code #1070

merged 27 commits into from Jul 8, 2015

Conversation

IanVS
Copy link
Contributor

@IanVS IanVS commented Jun 28, 2015

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:

screenshot from 2015-06-27 22 28 28

(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:

screenshot from 2015-06-27 22 38 18

My suggestion would be to override the following rules to more closely align with the existing codebase:

"rules": {
  "space-before-function-paren":  [2, "never"],
  "space-after-keywords":         [2, "never"],
  "semi":                         [2, "always"]
}

The results of these three changes results in something pretty manageable:

modified-standard

What say ye?

@IanVS IanVS changed the title Add eslint for source code [WIP] Add eslint for source code Jun 28, 2015
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.
@IanVS
Copy link
Contributor Author

IanVS commented Jun 29, 2015

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.

@IanVS IanVS changed the title [WIP] Add eslint for source code Add eslint for source code Jun 29, 2015
@dmarcelino
Copy link
Member

👍

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?

@IanVS
Copy link
Contributor Author

IanVS commented Jun 29, 2015

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.

@IanVS
Copy link
Contributor Author

IanVS commented Jun 30, 2015

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.

@dmarcelino
Copy link
Member

I'm good with these changes.

But would like hear other people's opinions such as @devinivy, @tjwebb and @particlebanana.

@devinivy
Copy link
Contributor

I think it's great 👍

@IanVS
Copy link
Contributor Author

IanVS commented Jul 4, 2015

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;

```
Ian VanSchooten added 6 commits July 7, 2015 00:16
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.
@IanVS
Copy link
Contributor Author

IanVS commented Jul 7, 2015

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 }]
7 errors: no-proto: 1
13 errors: eqeqeq: [1, "allow-null"]
3 errors: no-new: 1

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.

@dmarcelino
Copy link
Member

@IanVS, the PR is good for now. Lets see if we can get some feedback from @particlebanana or @tjwebb.

@IanVS
Copy link
Contributor Author

IanVS commented Jul 8, 2015

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

@particlebanana
Copy link
Contributor

@IanVS I'm looking over this today, not familiar with ESLint so I'm looking over it and all the rules we have here.

@IanVS
Copy link
Contributor Author

IanVS commented Jul 8, 2015

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

@particlebanana
Copy link
Contributor

This is awesome! Thanks @IanVS and I'm ashamed of some of the stuff in there!

particlebanana added a commit that referenced this pull request Jul 8, 2015
Add eslint for source code
@particlebanana particlebanana merged commit 13b7935 into balderdashy:master Jul 8, 2015
@dmarcelino
Copy link
Member

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!

@IanVS
Copy link
Contributor Author

IanVS commented Jul 8, 2015

Great, glad this is useful. Here are what I see as the decisions to be made:

  • no-multiple-empty-lines
    • 1 empty line
    • 2 empty lines
  • space-after-keywords
    • Always
    • Never
  • space-before-function-paren
    • Always
    • Never
    • Always for anonymous, never for named

For now I can work on the other rules like one-var, no-unused-vars, and brace-style. Once decisions are reached on the above, I can work on those too. The following will need to be addressed by the Waterline team:

  • no-undef
  • new-cap
  • no-proto
  • eqeqeq
  • no-new

Now that this is merged, linting will occur on each test run, but it will look a little overwhelming. You can also use npm run nibble to see rule summaries and then focus in on a specific error.

@dmarcelino
Copy link
Member

  • no-multiple-empty-lines
    • 1 empty line
    • 2 empty lines

Given how abundantly empty lines are used in waterline I vote for allowing 2 lines (this will still allow just one line, right?).

@IanVS
Copy link
Contributor Author

IanVS commented Jul 9, 2015

Yes, it just means max of two sequential empty lines.

@IanVS IanVS deleted the linting branch July 10, 2015 04:34
@devinivy
Copy link
Contributor

I vote,

  • no-multiple-empty-lines
    • 1 empty line
    • 2 empty lines
  • space-after-keywords
    • Always
    • Never
  • space-before-function-paren
    • Always
    • Never
    • Always for anonymous, never for named

@particlebanana
Copy link
Contributor

I vote:

no-multiple-empty-lines: 2
space-after-keywords: always
space-before-function-paren: never
no-undef: true
new-cap: true
no-proto: true
eqeqeq: true - smart
no-new: true

@tjwebb
Copy link
Contributor

tjwebb commented Jul 13, 2015

I vote for one max empty line. We can split the different and make it 1.5? :)

@dmarcelino
Copy link
Member

I'm afraid your math is off:

@dmarcelino : 2
@devinivy: 2
@particlebanana: 2
@tjwebb: 1

Average: 1.75 😛

dmarcelino added a commit that referenced this pull request Jul 14, 2015
Lint Rule Cleanup (continuation of #1070)
ctartist621 pushed a commit to ctartist621/waterline that referenced this pull request Feb 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants