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

Rubocop too overzealous? #14

Closed
jyaworski opened this issue Oct 10, 2015 · 31 comments · Fixed by #35
Closed

Rubocop too overzealous? #14

jyaworski opened this issue Oct 10, 2015 · 31 comments · Fixed by #35

Comments

@jyaworski
Copy link
Member

Hello:

I've been working on the puppet-rundeck modulesync changes at voxpupuli/puppet-rundeck#134

It looks like it's failing on rubocop, but a lot of it is very benign.

  1. Long lines
  2. and vs &&
  3. Nested functions
    etc

One of the main things I'm running into is:

rubocop/rubocop#1238

Can we tone down Rubocop's aggression?

@jyaworski
Copy link
Member Author

Also here:

rubocop/rubocop#947

@jyaworski
Copy link
Member Author

One possible solution is to use --only-guide-cops as documented in rubocop/rubocop#1454

@igalic
Copy link
Contributor

igalic commented Oct 13, 2015

@jyaworski that seems like a very good idea, and is probably very much less… opinionated.!

@igalic
Copy link
Contributor

igalic commented Oct 13, 2015

@jyaworski can you add pr that changes our config to that?

@mkrakowitzer
Copy link
Contributor

Can I suggest using .rubocop.yml from garethr/puppet-module-skeleton as a base?

https://github.com/garethr/puppet-module-skeleton/blob/master/skeleton/.rubocop.yml

@igalic
Copy link
Contributor

igalic commented Oct 13, 2015

there are a couple of those i don't entirely agree with… such as:

Style/RegexpLiteral:
  Enabled: false

that's literally the reason i started this whole thing ;)

@jyaworski
Copy link
Member Author

One solution is to add --fail-level and set it to a sane default; say 'E'. Maybe add a parameter to .sync.yml to toggle it per-project if you want? How does that sound?

joseph.yaworski@jyaworski-mbpr ~/puppet-rundeck (git)-[modulesync] % rubocop
...
25 files inspected, 121 offenses detected
joseph.yaworski@jyaworski-mbpr ~/puppet-rundeck (git)-[modulesync] % echo $?                                                                                                                                                             :(
1

joseph.yaworski@jyaworski-mbpr ~/puppet-rundeck (git)-[modulesync] % rubocop --fail-level=E
...
25 files inspected, 121 offenses detected
joseph.yaworski@jyaworski-mbpr ~/puppet-rundeck (git)-[modulesync] % echo $?                                                                                                                                                             
0

@mkrakowitzer
Copy link
Contributor

OK so my initial thoughts on trying to get my spec tests reformatted to meet the current requirements is that I will still be reformatting perfectly working code in about 2 weeks from now, and this is only one project! I have literally spent an entire evening formatting text and I am only about 50% done. Rubocops autocorrect is a disaster, so that did not even help.

We need a more sane config file in order for any module to make rubocop a viable option or force it to exit 0 as per @jyaworski previous comment.

@igalic
Copy link
Contributor

igalic commented Oct 14, 2015

Agreed.
the defaults are impossible to comply with, especially in rspec tests.

@daenney
Copy link
Member

daenney commented Oct 14, 2015

I don't think long lines or and vs && is pretty benign. Long lines are hard to read and the longer they get the more complicated expressions they usually contain.

&& vs and are pretty similar in Ruby but their difference is in binding strength / operator precedence so we should care about those. The style guide is pretty clear on this too:

Use &&/|| for boolean expressions, and/or for control flow. (Rule of thumb: If you have to use outer parentheses, you are using the wrong operators.)

We can certainly tone them down a bit but just throwing out parts from the style guide we find inconvenient is not something I'm willing to support. Theres should be good reasons and arguments for the exceptions we're going to make.

@igalic
Copy link
Contributor

igalic commented Oct 14, 2015

@daenney i also agree with that, however, rubocop's default auto_correct behaviour is awful…

@daenney
Copy link
Member

daenney commented Oct 14, 2015

Then don't autocorrect/use the fixers, just let it complain about it and fix it yourself 😄. There's a few we can disable but from the presented use cases I only find nested functions potentially troublesome. But nested functions are also bad.

@igalic
Copy link
Contributor

igalic commented Oct 14, 2015

fixing thousands of lines code isn't really my idea of fun :P

@daenney
Copy link
Member

daenney commented Oct 14, 2015

It's not thousands of lines, it's one module at a time and not all modules, far from all, have native types and providers. And new code can start out directly by adhering to this. There's also no need to go full on zealot on it and fix everything now now now.

@igalic
Copy link
Contributor

igalic commented Oct 14, 2015

when i say thousands of lines of code, i specifically mean rspec tests.
but yes, you are right.

@danzilio
Copy link
Member

Definitely agree with @daenney on and vs. &&. Also, don't forget about control comments for exceptions. Sometimes breaking with the style guide on a single line makes sense for readability or maintainability. You can disable a cop for a single line by adding a trailing control comment like this: # rubocop:disable RULENAME. This should obviously be used judiciously, but we shouldn't be pedantic.

@igalic
Copy link
Contributor

igalic commented Oct 14, 2015

after merging #21 i think we've got some better fit…

@igalic
Copy link
Contributor

igalic commented Oct 14, 2015

now, if only we had some kind of trigger that would run msync update for us…

@jyaworski
Copy link
Member Author

I just resynced voxpupuli/puppet-rundeck#139 and I'm getting different errors. Still looking into them.

@jyaworski
Copy link
Member Author

All right. Lots of refactoring later and I'm back to a smaller number of rubocop errors.

@daenney and @danzilio: I'm not super well-versed in Ruby, so maybe I spoke out of naivete with the and/&& thing. Long lines I understand the frustration as well. However, I share @igalic's general frustration surrounding rspec tests; that's where all of that PR I mentioned is failing, and some of them are non-trivial to fix. Do we really want to lint spec files in that case?

@daenney
Copy link
Member

daenney commented Oct 14, 2015

That is a good question. I'm not convinced the spec tests have to adhere to all the Rubocop madness. It might be worth only loading rubocop-rspec for the spec/ directory and a few basic other cops.

@mkrakowitzer
Copy link
Contributor

Personally I think it makes the spec tests harder to read: https://github.com/puppet-community/puppet-stash/pull/99/files

@jyaworski
Copy link
Member Author

All right; I've turned off a few cops in #24.

@igalic
Copy link
Contributor

igalic commented Oct 14, 2015

@mkrakowitzer i can't even tell the difference anymore _
@jyaworski merged

@logicminds
Copy link
Contributor

We need an exclusion for these kinds of errors. I don't agree with rubocop

lib/puppet/parser/functions/default_content.rb:10:1: C: Align ) with (.
) do |args|
^
lib/puppet/parser/functions/dump_args.rb:11:1: C: Align ) with (.
) do |args|

@daenney
Copy link
Member

daenney commented Oct 30, 2015

Well, just because one person doesn't agree is not a good enough reason to exclude. Why do you disagree and perhaps share a few screenshots of code that is more legible in your case than what rubocop recommends?

@igalic
Copy link
Contributor

igalic commented Oct 30, 2015

i'm pretty and sure i've excluded those ;)
@daenney they make most of our rspec code completely unreadable

@logicminds
Copy link
Contributor

@daenney this is the default way of defining puppet functions. example: logicminds/puppet-extlib@fc46c63#diff-e24a4c8f84f47be4ba90e4572ed66e18R11

Every puppet function in puppet core is defined this way.

@jyaworski
Copy link
Member Author

I just linked from a PR where it's complaining about module comments. Definitely not something worth failing on.

@igalic
Copy link
Contributor

igalic commented Nov 3, 2015

@jyaworski any idea what needs to change to make it pass?

@jyaworski
Copy link
Member Author

@igalic yes.

#35

@igalic igalic closed this as completed in #35 Nov 4, 2015
wyardley added a commit that referenced this issue Oct 4, 2017
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 a pull request may close this issue.

6 participants