airbnb / ruby

Ruby Style Guide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rubocop ruleset?

00defeat opened this issue · comments

Is there a rubocop ruleset for this coding style similar to your eslint for js?

I'm happy to work on a PR for this. Rubocop comes with a large set of defaults. Do you think it'd be best to explicitly define all rules or just override those that are not specified in the defaults?

We're already building up an internal rubocop ruleset, but in the meantime, a PR that creates one to match the styleguide would be very appreciated!

I have a strong preference for not relying on defaults.

Cool, I'll get started! 👍

Cool, I'll get started! 👍

@daltonamitchell Any progress on this? 😄

Not much, got sidetracked with another project. Hopefully next week I'll be back on it though

Waiting for it !

Hey all, it's been a couple months and I really haven't made any significant progress. I think I better let someone else handle this. Sorry but hopefully someone will have better luck with it.

I've been working (in my spare time) to incorporate a lot of the rules into the rubocop configuration on monorail. Some of it has been working through rule definitions. That is probably the best place to look for a rubocop ruleset right now. it's not complete by any means but is a good start, still very much a work in progress and will continue to be as rubocop rolls out new rules which can better help match what we have decided on in this style guide.

@robotpistol Do you happen to have a link by any chance that you could share? Scoured Google but couldn't find anything.

@MindRave no, his comment means we have that configuration internally to Airbnb - it's not publicly available.

@ljharb Any plans on making it so?

I'd very much like to! I believe @robotpistol is still working on firming up our internal ruleset, but hopefully we'll be able to publish it sooner than later.

@ljharb and @robotpistol - Do you happen to have a draft .rubocop.yml you could release prior to a final version?

:bump:

Any updates on the official AirBNB approved rubocop.yml?

That would be great!

Any update on this? Curious, are there any custom rules you guys are using to enforce the style guide?

DuckDuckGoed airbnb rubocop and ended up here anticipating a yml file - ended up slightly disappointed that this issue has been open 1.5years... Please share the ❤️ 💜 💚 @daltonamitchell @ljharb @robotpistol

Any update? 😄

I apologize for the long wait for this. I've been working on trying to open source our internal version of rubocop (using similar configuration injection to rubocop-rspec) but have been holding off for a while. But clearly there's enough demand for this that I will put a copy of our current configs (it will evolve over time) i'll try to include them either in this repo or a related one.

Again sorry for the delay. Our rubocop config has been a work in progress.

Hey! it's awesome that you are working on this, it would be very appreciated by developers, personally i like rubocop but it would be greate if we can implement a ruleset for the airbnb ruby styleguide, so thanks in advantage for your work @robotpistol we are waiting for this :)

@robotpistol Hey, you know what's great for works in progress? Open sourcing them so strangers can help you fix them. :trollface: ❤️

I gave up on finding a good rubocop.yml from the "big" players. It could be different even within a place such as airbnb, I guess that's why we dont see anything.

Instead, I think this is something that teams should decide on themselves using the following procedure:

  1. Initial step: Simply use vanilla rubocop with no rules. It's not bad, give it a try.
  2. Use autocorrect (rubocop -a)
  3. Correct todos in .rubocop_todo.yml once in a while, cop-by-cop or file-by-file
  4. If there is something you and your team cannot live with, track the Cop down and disable/tweak it using .rubocop.yml
  5. Go to step 1

This is all well and good, but then you soon discover that you are working in multiple repos, and .rubocop.yml gets out of sync between projects... Hmm... Someone should really make a gem that keeps a master .rubocop.yml in a shared repo, so each repo can source from a shared place...

Well, actually... In our team at Klarna we developed a gem to help you with this. Check it out at https://github.com/klippx/rubocop_rules

  • Can be used in development, skipped in production
  • Supports using your one and only master .rubocop_common.yml file (which is sourced by regular .rubocop.yml). Which repo to source from is pointed out by config file .rubosync.yml
  • Adds a lint spec to make sure rubocop style is always up to date in CI
  • Respects .rubocop_todo.yml
  • Can self update with new definition of .rubocop_common.yml which also of course regenerates .rubocop_todo.yml
  • Self updating can of course (in theory) be automated by your build tool... Example: When you update the master rubocop_common.yml this could trigger downstream builds for all ruby projects using rubocop_rules to create new branch, run bundle exec rubocop_rules update and commit everything, push and open a PR. NOTE: This is not a feature of the gem, but the gem supports this idea, however you have to build this in your pipeline yourself. I have just thrown in the idea here to prove a pretty cool point.
  • Finally you can let rubocop solve style bike-shedding for you across all projects with zero effort

Please try it and give it some ❤️ on twitter if you like it