@StatelessCode
  @StatelessCode
Stateless Code | Create a RubyGem 93: Refactor RuboCop to Enable New Cops by Default for the Gem @StatelessCode | Uploaded February 2023 | Updated October 2024, 3 hours ago.
In our other series, NerdDice.com where we build a Ruby on Rails application to manage table-top role playing, we recently modified our RuboCop configuration file to enable new cops by default. In that episode, we added a backlog item for this project to do the same thing.

If you don't enable new cops by default, each time you upgrade RuboCop in your bundle, you will see warnings about new cops that need to be enabled or disabled in your configuration. While this allows for explicit documentation about your configuration, it also causes your RuboCop configuration file to grow by quite a bit over time.

When you get the warnings, RuboCop presents another alternative: You can enable new cops by default. The trade-off here is that if your existing codebase has violations, you will start getting new failures when you upgrade your bundle. When that happens, you can either modify your code to conform, or add configuration to ignore the new cops. Either way, our configuration file will be more meaningful; it will only have non-default or explicit configuration instead of a bunch noise about new cops we have enabled over the course of the project.

When removing the redundant configuration, we also find a few places where we are excluding directories that don't exist in our project. (We copied and adapted this file from Rails back in 2020 and didn't remove the references to the Rails project directories.)

This video covers:
00:00:12 Introduction, overview of RuboCop
00:01:47 Demonstrate the warning when new cops are available but not configured
00:05:25 Overview of what we're going to remove
00:07:11 Remove the unnecessary config from the .rubocop.yml file
00:08:24 Review file after making changes
00:09:17 Remove exclude lines for directories that don't exist in this project
00:10:28 Save and re-run RuboCop. Observe the expected warnings.
00:11:20 Add the NewCops: enable line to the config and re-re-run RuboCop to demonstrate no warnings
00:13:03 Review diff and compare size before and after
00:15:29 Commit, push, pull request
00:17:10 Merge pull request and close issue as complete

#ruby #rubygems #codecast #screencast #NerdDice #DnD #roleplaying #softwaredevelopment #github #opensource #dice #TDD #rubocop #configuration

See other related StatelessCode videos:
- Change RuboCop Config to Enable New Cops By Default for a Rails Application youtu.be/J8QvGnn-wso
- Codecast: Rubocop install and initial setup youtu.be/dKpiJhA19yg
- Codecast: Create a RubyGem 03: Set up RuboCop and flesh out the README youtu.be/Iz_Wl-IDL-c
- Codecast: Create a RubyGem 09: Fix RuboCop issues and release a patch version youtu.be/2tw6ozMgTpQ
- Codecast: Create a RubyGem 27: Add Rubocop to Github Actions youtu.be/2tw6ozMgTpQ
- Update Ruby then Add RuboCop to a Rails Project youtu.be/5MbY5k5Wk68
- NerdDice.com playlist youtube.com/playlist?list=PL9kkbu1kLUeMJFb0GT8ZMzrsSKJaxjOKH

Resources that we relied upon for this solution:
- RuboCop main site rubocop.org
- RuboCop Documentation for command line docs.rubocop.org/rubocop/usage/basic_usage.html

This video is CC0 - No rights reserved. (YouTube doesn't allow this option when publishing.) All code is released under the UNLICENSE. Stateless Code denies the concept of "intellectual property". Copying is not stealing.
Create a RubyGem 93: Refactor RuboCop to Enable New Cops by Default for the GemCodecast: Create a RubyGem 63: Create 0.3.x Stable Branch and Prune Old BranchesCodecast: Create a RubyGem 88: Add Ruby 3.1 to GitHub Actions and Update BundleGet Devise Working with Turbo in Rails 7Codecast: Getting Started with Rails 7 26: Fix Rich Text Fixtures and ValidationsInstall Ubuntu 24.04 LTS DesktopMediocre Karaoke - Dust in the Wind by KansasCodecast: Create a RubyGem 86: Retro on Version 0.4.0 (Now with Mediocre Karaoke)Write and Debug Happy Path System Tests for Devise Reset PasswordCodecast: statelesscode.com WordPress 22: Start Styling CommentsCodecast: Getting Started with Rails 7 13: Create Comments for an Article

Create a RubyGem 93: Refactor RuboCop to Enable New Cops by Default for the Gem @StatelessCode

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER