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 rubocop #1125

Merged
merged 52 commits into from
Jul 2, 2018
Merged

Add rubocop #1125

merged 52 commits into from
Jul 2, 2018

Conversation

Evan-M
Copy link
Collaborator

@Evan-M Evan-M commented Mar 24, 2018

Taking a stab at adding rubocop to the repo, as suggested in #1124

I've already addressed some of the simpler Cops that can utilize the --auto-correct option.

Each correction for a given cop was made in a separate commit, so to make reviewing easier (I hope).

The flow I've used was as follows:

  1. Pick a Cop / set of violations in the .rubocop_todo.yml
  2. Create a local branch with the Cop name
  3. Make 1 or more updates to code, or move a todo item into the main .rubocop.yml config.
  4. Merge the Cop branch back onto the add_rubocop branch with the --no-ff option.

This PR gets the offenses down to 652, but there is still more work to do!

 - Add `.rubocop.yml` + `.rubocop_todo.yml` following instructions in
   https://rubocop.readthedocs.io/en/latest/configuration/#automatically-generated-configuration

 - Add rake task for rubocop
 - Rubocop complained about invalid ruby; since the file is technically
   erb and _not_ ruby, the extension should reflect that anyway.
 - Remove empty lines per `Layout/EmptyLines` Cop.
 - Remove empty lines per `Layout/EmptyLines` Cop from test-dummy rails app.
 - Remove `Layout/EmptyLines` Cop from todo list.
 - Fix quotes in string literals per `Style/StringLiterals` Cop.
 - Fix quotes in string literals per rubocop for test-dummy rails app.
 - Remove `Style/StringLiterals` Cop from todo list.
 - This Cop is for future Ruby. Skip it for now; it works with the
   `--auto-correct` option, making future application trivial.
 - This Cop forces either nested or compact module declarations.
   While nested may be considered best practice, changing these up may
   lead to all kinds of merge conflicts on open PRs.
 - Move `Style/HashSyntax` from todos to main config, and
   set enforced style to `ruby19`--i.e. `{foo: :bar}`.

 - Update hash syntax from hash-rockets to ruby 1.9 style.

 - Update hash syntax to ruby 1.9 style in test-dummy rails app.
 - Move `Style/SymbolArray` from todos to main config:
    * Set enforced style to 'percent' -- i.e. `%i[]`.
    * Don't enforce on arrays with < 3 elements.

 - Use percent array literals for large arrays of symbols.

 - Use percent array literals for large arrays of symbols.
@Evan-M
Copy link
Collaborator Author

Evan-M commented Mar 24, 2018

Hold off on review for the moment.

@Evan-M Evan-M added the on hold label Mar 24, 2018
@dks17 dks17 mentioned this pull request Mar 25, 2018
@Evan-M Evan-M force-pushed the add_rubocop branch 2 times, most recently from 5a48229 to a3c6ea0 Compare March 26, 2018 18:13
Evan-M and others added 2 commits March 26, 2018 13:41
When `rubocop` was added, the `parser` gem was added as a dependency.
Unfortunately, the version of parser specified in the `Gemfile.lock`
was unpublished; must update to the newly released parser dependency.
@MaicolBen
Copy link
Collaborator

This looks good! I saw that you split the work with @dks17, great because this doesn't have it done at once. I hope in the future, we can add it to travis. When this is ready, just remove the "on hold" label.

I would squash the commits at the end because they are a lot, but we can do it at merge time.

Thanks @Evan-M !!

@Evan-M
Copy link
Collaborator Author

Evan-M commented Mar 27, 2018

Yeah, 👍@dks17 for helping out with this!

I tried local 'feature/cop' branches with merge commits for each cop, but it doesn't look like the ref hierarchy made it up to github. In any event, I think I'll try @dks17's approach with the rest of this PR, and have a single commit for each cop fix.

Also, I know I've seen travis running the rubocop code, but it always feels like it blocks test from running. I know that codeclimate can utilize rubocop, so maybe that would work better? https://docs.codeclimate.com/docs/advanced-configuration

And I agree that squashing these commits at the end makes sense, but lets get all the commits reviewed beforehand!

@Evan-M
Copy link
Collaborator Author

Evan-M commented Mar 27, 2018

I merged #1126, but then ran into all kinds of rebase and/or merge duplicates and other silliness.

If an attempt to make sure that this PR ends up in a reviewable and mergeable state, I cherry-picked the commits that @dks17 made in #1126 back to this branch, squashed all my previous merge commits (such that there is one commit per set of cop violation fixes), and did some --fixup commits + git filter-branch revisionist history magic.

This of course required a force-push. So if anyone else has checked-out or forked this branch, I apologize in advance! To get back to valid state, rename your existing checkout/fork, re-checkout or re-fork a clean copy of the updated branch, and rebase your changes against the new copy.

@dks17
Copy link
Contributor

dks17 commented Apr 26, 2018

I have just pull master into rubocop branch.
Almost each new PR in master branch brings some conflicts and offences. With every PR it seems we will never overtake master branch.
Should be better merge rubocop branch into master now?

@MaicolBen
Copy link
Collaborator

@dks17 Agreed, we don't have frequent PRs merged lately, but this could take a while to be finished.

Rebase it, we make sure Travis passes and we will merge it (squashing)

@dks17 dks17 mentioned this pull request Apr 27, 2018
@dks17
Copy link
Contributor

dks17 commented Apr 28, 2018

@Evan-M
I have got many warnings in console like these:

Warning: unrecognized parameter Metrics/BlockLength:inherit_mode found in .rubocop.yml
Warning: unrecognized parameter Metrics/LineLength:inherit_mode found in .rubocop.yml

Do you thing these configuration parameters were set properly?

Metrics/BlockLength:
  inherit_mode:
    merge:
      - Exclude
      - ExcludedMethod

Metrics/LineLength:
  inherit_mode:
    merge:
      - Exclude

It seems there is no effect if these properties are commented.

@Evan-M
Copy link
Collaborator Author

Evan-M commented Apr 28, 2018

That happens when there are no inherited settings to merge with from an
included file (in this case, there are no Excludes for the
Metrics/BlockLength nor the
Metrics/LineLength cops inherited from .rubocop_todo.yml).

If you comment out the inherit_from: .rubocop_todo.yml at the top of the
.rubocop.yml file, you will see more warnings where there is nothing to
merge.

@Evan-M Evan-M force-pushed the add_rubocop branch 3 times, most recently from b41294b to c19432b Compare April 28, 2018 18:54
@krzysiek1507
Copy link
Contributor

I'm not a big fan of rubocop -a because, to be honest, does anybody check every single line here? It's too much to check and most people just scroll it after 10 files. I prefer to do it step by step, e.g. fix hash style, fix indentation and so on, so we can be sure that we don't break anything (e.g, change and to &&).

@dks17
Copy link
Contributor

dks17 commented Apr 29, 2018

I did not use auto correction (manually only) then ran the tests.

@Evan-M
Copy link
Collaborator Author

Evan-M commented Apr 30, 2018

I've been using the -a option in conjunction with --only <COP_NAME>. Then I review all the changes via git add --patch, and make sure the tests pass before committing the changes.

I also frequently use rubocop --only <COP_NAME> --format worst to check the violations before running with -a option.

¯\_(ツ)_/¯

@krzysiek1507 To your point though, running rubocop -a against all cops, kinda feels like biting off more than you could chew.

#1157 added the frozen string literal comment to _most_ files; this
cop fixes the remaining files and enforces the presence of the frozen
string literal comment in future files.
@krzysiek1507
Copy link
Contributor

I saw a lot of pull requests with rubocop -a, green tests and new bugs introduced.

In this case, it's better but it is still hard to review it because of 2.5k additions and 1.9 deletions.

@krzysiek1507
Copy link
Contributor

We can always split this PR into smaller by cherrypicking.

@krzysiek1507
Copy link
Contributor

You don't need to freeze strings if there is # frozen_string_literal: true pragma.

@MaicolBen
Copy link
Collaborator

MaicolBen commented May 2, 2018

@Evan-M Is this still on hold? because we can merge after you fix @krzysiek1507 comment, and you continue it in another PR, so it doesn't keep growing

@MaicolBen
Copy link
Collaborator

MaicolBen commented Jul 2, 2018

@krzysiek1507 @Evan-M I reviewed the PR and it looks good, as I don't see more activity from the author and I don't want to lose this work, I will merge it. About frozen_string_literal, most of the files have it, so I don't see bad adding it

@MaicolBen MaicolBen removed the on hold label Jul 2, 2018
@MaicolBen MaicolBen merged commit 72976d8 into master Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants