From acccb02885f277c0afcdda358af40040de30ac45 Mon Sep 17 00:00:00 2001 From: Justin Searls Date: Mon, 8 Jan 2024 09:46:10 -0500 Subject: [PATCH] Remove base rubocop rules redefined/extended by rubocop-rails (clears warning) See https://github.com/standardrb/standard-rails/issues/25#issuecomment-1881127173 Fixes #25 --- config/base.yml | 12 ------------ lib/standard/rails/plugin.rb | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/config/base.yml b/config/base.yml index 6037910..150c699 100644 --- a/config/base.yml +++ b/config/base.yml @@ -19,15 +19,6 @@ AllCops: # as the default. TargetRailsVersion: ~ -# This cop from rubocop was added to the Rubocop-Rails -# config as part of this PR: -# https://github.com/rubocop/rubocop-rails/pull/1014 -# in order to support some Rails-specific methods. At the -# time of writing, it's disabled in Standard, so it's -# disabled here. -Lint/RedundantSafeNavigation: - Enabled: false - Lint/SafeNavigationChain: Enabled: true AllowedMethods: @@ -427,6 +418,3 @@ Rails/WhereNot: Rails/WhereNotWithMultipleConditions: Enabled: false - -Style/InvertibleUnlessCondition: - Enabled: false diff --git a/lib/standard/rails/plugin.rb b/lib/standard/rails/plugin.rb index 5bfe65d..f79c079 100644 --- a/lib/standard/rails/plugin.rb +++ b/lib/standard/rails/plugin.rb @@ -27,7 +27,9 @@ def rules(context) LintRoller::Rules.new( type: :object, config_format: :rubocop, - value: rules_with_config_applied + value: without_extended_rule_configs( + rules_with_config_applied + ) ) end @@ -44,6 +46,18 @@ def rules_with_config_applied ) end + # rubocop-rails adds additional options to a couple out-of-the-box cops + # but Standard (1) doesn't enable these to begin with and (2) doesn't + # allow rules' configs to be edited once they are defined, so we'll just + # remove them here + # + # See: https://github.com/standardrb/standard-rails/issues/25#issuecomment-1881127173 + def without_extended_rule_configs(rules) + rules.reject { |(name,_)| + ["Style/InvertibleUnlessCondition", "Lint/SafeNavigationChain"].include?(name) + }.to_h + end + # This is not fantastic. # # When you `require "rubocop-rails"`, it will not only load the cops,