One of the open source projects Test Double maintains is called StandardRuby. No, it's not Ruby's standardlibrary and it doesn't implement any industry standards. Instead, Standard—like the JavaScript library of the same name—is a set of static analysis ("linting") and codestyle rules for your Ruby code. Because it's built on top of RuboCop, Standard is also able to automatically lint and format your source code from the command line or even right in your editor. All that, and I haven't even mentioned Standard's headline feature: you can't configure it!
And it's a big week here at Standard HQ: We just released version 1.0.0
!
It's hard to believe that it was over two years ago when we unveiled Standard in a lightning talk at RubyConf2018. We've since released over 80 iterations of the tool, incorporated dozens of rule changes from the community, and battle-testedStandard's unconfigurable configuration against thousands of projects with over a million downloads.
As more developers have come to rely on Standard, my colleague Jennifer Konikowski has joined as a co-maintainer and helped us keep up with the steady stream of RuboCop releases (which also hit 1.0 this year!) being published by @bbatsov, @koic, and its legion of contributors. We've learned first-hand that staying on top of these changes is a lot of work. Because we carefully evaluate each RuboCop change before incorporating it into Standard's base configuration, an additional value-add for our users has become apparent: Standard sweats the details of each RuboCop release, so you don't have to!
Finally, coinciding with its 1.0 release, Standard was just added to Bundler today as one of the available options when you create a new Ruby gem project using its (excellent) bundlegem scaffolding command. (If you've never used bundle gem
, give it a try! It makes creating a gem so easy, you'll be publishing your own gems in no time.)
If you don't already use Standard, it's easy to get started. Just toss it into your Gemfile
:
gem "standard"
From there, the standardrb
binary will print out all of its linting and style suggestions. You can also run standardrb --fix
to automatically reformat your code and get an idea on the impact adding Standard would have on your codebase.
Use Rake? Just require Standard in your Rakefile
to load the standard
and standard:fix
tasks. For what it's worth, I also add Standard to my default task list, as shown below:
require "standard/rake"
task default: [:test, "standard:fix"]
For more on Standard's rules, check ourREADME.
If you're not already a fan of using linters and code formatters, that's okay!One of the things that first attracted me to Ruby when I started using it in2005 was how free-form and liberating it was in comparison to Java. As a result, any tool that constrains Ruby's expressiveness risks undercutting one of the best reasons to use Ruby in the first place!
It's for this reason we're incredibly conservative about the rules we've chosen to enable in Standard. Here are some of our guiding principles, and how they might benefit your project:
Standard is essentially a thin candy shell on top of RuboCop. We built it that way because RuboCop is a great tool in its own right! Rather than compete with RuboCop, Standard aims to leverage its breadth of technical capabilities in order to establish a set of community norms among as many Ruby developers and codebases as possible. Ruby's expressiveness is one of its greatest strengths, but that same flexibility can lead to Balkanization within our community when different projects arrive at wildly different style rules, and Standard seeks to address that.
If your team uses RuboCop today and things are going well, by all means do what works for you! But if you can get behind the idea that increased consistency across Ruby projects would be a net good for our community, I hope you'll consider giving Standard a second look!
Not many of my projects ever reach 1.0. But with Standard, we wanted to communicate that things are pretty much stable and won't be changing dramatically from here on out. That said, the work is hardly over. RuboCop continues to be one of the most prolific gems in the Ruby ecosystem, releasing on a nearly biweekly cadence. And Ruby itself is no slouch either; many of us doubted Matz's promises for Ruby 3.0 back in 2015, but amazingly almost all of them came true! Our commitment is to continue the work of maintaining Standard as Ruby and RuboCop change and evolve, and we'll continue to invest in better integrations with developer tools like editors and CI/CD environments.
If you've been holding out on trying Standard, waiting for the dust to settle, now's a great time to start using it. And if you find something you don't like, we still want to hear from you! Just open an issue or give us a shout at hello@testdouble.com.