Skip to main content
Test Double company logo
Services
Services Overview
Holistic software investment consulting
Software Delivery
Accelerate quality software development
Product Management
Launch modern product orgs
Legacy Modernization
Renovate legacy software systems
DevOps
Scale infrastructure smoothly
Upgrade Rails
Update Rails versions seamlessly
Technical Recruitment
Build tech & product teams
Technical Assessments
Uncover root causes & improvements
Case Studies
Solutions
Accelerate Quality Software
Software Delivery, DevOps, & Product Delivery
Maximize Software Investments
Product Performance, Product Scaling, & Technical Assessments
Future-Proof Innovative Software
Legacy Modernization, Product Transformation, Upgrade Rails, Technical Recruitment
About
About
What's a test double?
Approach
Meeting you where you are
Founder's Story
The origin of our mission
Culture
Culture & Careers
Double Agents decoded
Great Causes
Great code for great causes
EDI
Equity, diversity & inclusion
Insights
All Insights
Hot takes and tips for all things software
Leadership
Bold opinions and insights for tech leaders
Developer
Essential coding tutorials and tools
Product Manager
Practical advice for real-world challenges
Say Hello
Test Double logo
Menu
Services
BackGrid of dots icon
Services Overview
Holistic software investment consulting
Software Delivery
Accelerate quality software development
Product Management
Launch modern product orgs
Legacy Modernization
Renovate legacy software systems
Cycle icon
DevOps
Scale infrastructure smoothly
Upgrade Rails
Update Rails versions seamlessly
Technical Recruitment
Build tech & product teams
Technical Assessments
Uncover root causes & improvements
Case Studies
Solutions
Solutions
Accelerate Quality Software
Software Delivery, DevOps, & Product Delivery
Maximize Software Investments
Product Performance, Product Scaling, & Technical Assessments
Future-Proof Innovative Software
Legacy Modernization, Product Transformation, Upgrade Rails, Technical Recruitment
About
About
About
What's a test double?
Approach
Meeting you where you are
Founder's Story
The origin of our mission
Culture
Culture
Culture & Careers
Double Agents decoded
Great Causes
Great code for great causes
EDI
Equity, diversity & inclusion
Insights
Insights
All Insights
Hot takes and tips for all things software
Leadership
Bold opinions and insights for tech leaders
Developer
Essential coding tutorials and tools
Product Manager
Practical advice for real-world challenges
Say hello
Developers
Developers
Developers
Accelerate quality software

Super Standard: How to add gem extensions and custom rules to Standard Ruby

Discover how the new extend_config option in Ruby Standard 1.22.1 allows you to tailor your code formatting to fit your team's needs, reducing debates and boosting productivity.
Justin Searls
|
January 18, 2023
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

We’ve been delighted by the enthusiasm and adoption of Standard Ruby since its release in 2018, and it’s only picked up steam since hitting 1.0 in 2021.

In fact, as Standard crosses 8 million downloads this week (but who’s counting?), we have something new and exciting to share!

What Standard Ruby aims to solve

But first, it might be good to back up and remind ourselves of Standard’s purpose. Yes, what it does is to automatically format code and safeguard it against common problems. But why it exists is to reduce the frequency of low-value discussions and disagreements that occur when it falls on each and every team to reach consensus on how to format code consistently. Put differently, Standard is less of a code linter (it relies on RuboCop to be that) and more of an anti-bike shedding tool.

How does Standard reduce meaningless debates about syntax? By imposing a liberating constraint: it doesn’t let you change the rules. When you disagree with how Standard wants you to format your code, you’re welcome to take that frustration out on the tool (or me), but it wouldn’t do any good to blame your teammates. Instead of each Ruby team arguing over its own bike shed of a RuboCop config, we host discussions on Standard’s ruleset as a service to the community. One bike shed to rule them all.

Configuring the unconfigurable

Well, if Standard’s rigidity and lack of configurability has ever rubbed you the wrong way: I have good news! As of version 1.22.1, Standard is now infinitely extensible and configurable!

A new problem has emerged as Standard has gained adoption: many teams see the benefit of Standard and want to adopt it, but they need it to do just a little bit more. Because Standard is only concerned with the rules bundled with the rubocop and rubocop-performance gems, it didn’t have an answer for people who wanted to incorporate additional rulesets like rubocop-rails or rubocop-rspec. Additionally, there are perfectly valid reasons a team might want to write custom rules to protect their code against risks that are specific to their domain (like Betterment/UnscopedFind, which can prevent data from leaking between customers in multi-tenant systems).

Up to now, the only solutions available to this problem have been:

  • Run both RuboCop and Standard side-by-side in your build, which would be a huge waste of time and resources—especially on large codebases
  • “Eject” your Standard configuration by dropping down to RuboCop CLI and requiring Standard’s configuration as if it were any other gem, and running the risk that something will overwrite Standard’s defaults (which would sort of defeat the point of using it)

Not ideal.

This is why we’re introducing a brand new extend_config option to the .standard.yml configuration file. This property will allow you to specify one or more YAML files that conform to RuboCop’s configuration format like so:

# .standard.yml
extend_config:
  - .rubocop_rails.yml

‍And in turn, require and configure that file however you like:

# .rubocop_rails.yml

require:
  - rubocop-rails

AllCops:
  DisabledByDefault: true

Rails/FindBy:
  Enabled: true
  Exclude:
    - lib/example.rb

That’s pretty much it, but for more on how to use extend_config, see Standard’s README.

How it works

Like everything Standard does, RuboCop is still doing most of the heavy-lifting here, as you can see in the feature’s source code. What’s worth knowing as a user, though, is that extend_config is designed to ensure that Standard’s core ruleset is not changed, whether intentionally or inadvertently.

Here’s how Standard accomplishes this:

  1. Load the Standard configuration like usual, noting that it explicitly configures every single rule included in rubocop and rubocop-performance
  2. For each custom RuboCop configuration specified in extend_config, load any rule configurations (this has the happy side effect of loading any required gems and files into a single shared cache)
  3. Reject any rules that Standard has already configured and merge in the rest
  4. Similarly, merge in any changes to AllCops, excepting a handful that would conflict with Standard’s behavior or settings

That’s it! No magic, I swear.

The future of Standard

In addition to the extend_config feature that shipped this week, its implementation could lay the groundwork for an exciting potential future: additional standard gems that define standardized rulesets for popular RuboCop extensions. Imagine a standard-rails gem that configured rubocop-rails just like standard applies a consistent ruleset to rubocop’s rules. Stay tuned!

Important Note: Please do us a favor and hold off on publishing any standard-* gems until you’ve had a chance to discuss with us first, because we’d like to coordinate our efforts. If you’re interested in helping out by maintaining one, though, reach out and let me know!

More than being adopted by major companies or seeing a download counter go up, what drives my excitement about Standard is a much-harder-to-measure metric: meaningless arguments prevented. I say this as someone who disagrees (sometimes, strongly!) with several of Standard’s own rules, despite having initially created it myself. I’m very glad, however, I managed to bite my tongue long enough to gradually acclimate to all its code styles that I didn’t personally agree with. After a month or two I forgot I ever cared so much.

I’ve heard similar stories from other Rubyists who were skeptical of Standard: that the benefit of having their team focused on more meaningful conversations far outweighs the cost of swallowing one’s pride and changing how they indent variable assignments or arrange commas in array literals. Hopefully extend_config will give even more developers the opportunity to give Standard a try!

Related Insights

🔗
Let's Standardize Rails!: An experiment in direct RuboCop democracy
🔗
How test_data speeds up Rails tests

Explore our insights

See all insights
Developers
Developers
Developers
You’re holding it wrong! The double loop model for agentic coding

Joé Dupuis has noticed an influx of videos and blog posts about the "correct" way of working with AI agents. Joé thinks most of it is bad advice, and has a better approach he wants to show you.

by
Joé Dupuis
Leadership
Leadership
Leadership
Don't play it safe: Improve your continuous discovery process to reduce risk

We often front-load discovery to feel confident before building—but that’s not real agility. This post explores how continuous learning reduces risk better than perfect plans ever could.

by
Doc Norton
Leadership
Leadership
Leadership
How an early-stage startup engineering team improved the bottom line fast

A fast-growing startup was burning cash faster than it could scale. Here’s how smart engineering decisions helped them improve the bottom line.

by
Jonathon Baugh
Letter art spelling out NEAT

Join the conversation

Technology is a means to an end: answers to very human questions. That’s why we created a community for developers and product managers.

Explore the community
Test Double Executive Leadership Team

Learn about our team

Like what we have to say about building great software and great teams?

Get to know us
Test Double company logo
Improving the way the world builds software.
What we do
Services OverviewSoftware DeliveryProduct ManagementLegacy ModernizationDevOpsUpgrade RailsTechnical RecruitmentTechnical Assessments
Who WE ARE
About UsCulture & CareersGreat CausesEDIOur TeamContact UsNews & AwardsN.E.A.T.
Resources
Case StudiesAll InsightsLeadership InsightsDeveloper InsightsProduct InsightsPairing & Office Hours
NEWSLETTER
Sign up hear about our latest innovations.
Your email has been added!
Oops! Something went wrong while submitting the form.
Standard Ruby badge
614.349.4279hello@testdouble.com
Privacy Policy
© 2020 Test Double. All Rights Reserved.