(CONT-773) Rubocop Unsafe Auto Fixes 1-3
authordavid22swan <david.swan@puppet.com>
Wed, 26 Apr 2023 14:37:01 +0000 (15:37 +0100)
committerdavid22swan <david.swan@puppet.com>
Wed, 26 Apr 2023 14:43:13 +0000 (15:43 +0100)
- Lint/BooleanSymbol
- RSpec/BeEq
- Style/CaseLikeIf

.rubocop_todo.yml
lib/puppet/provider/apt_key/apt_key.rb
spec/unit/facter/apt_reboot_required_spec.rb
spec/unit/puppet/type/apt_key_spec.rb

index bed1ce798542435d55e981f22bf2e428dbbe34b0..a20672eb0000298e8a271ff8df87780173a7a37a 100644 (file)
@@ -6,12 +6,6 @@
 # Note that changes in the inspected code, or installation of new
 # versions of RuboCop, may require this file to be generated again.
 
-# Offense count: 1
-# This cop supports unsafe autocorrection (--autocorrect-all).
-Lint/BooleanSymbol:
-  Exclude:
-    - 'spec/unit/puppet/type/apt_key_spec.rb'
-
 # Offense count: 3
 # Configuration parameters: AllowedMethods.
 # AllowedMethods: enums
@@ -53,13 +47,6 @@ Performance/CollectionLiteralInLoop:
   Exclude:
     - 'spec/classes/apt_update_spec.rb'
 
-# Offense count: 6
-# This cop supports unsafe autocorrection (--autocorrect-all).
-RSpec/BeEq:
-  Exclude:
-    - 'spec/unit/facter/apt_reboot_required_spec.rb'
-    - 'spec/unit/puppet/type/apt_key_spec.rb'
-
 # Offense count: 6
 # Configuration parameters: Prefixes, AllowedPatterns.
 # Prefixes: when, with, without
@@ -141,13 +128,6 @@ Security/Open:
   Exclude:
     - 'lib/puppet/provider/apt_key/apt_key.rb'
 
-# Offense count: 1
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: MinBranchesCount.
-Style/CaseLikeIf:
-  Exclude:
-    - 'lib/puppet/provider/apt_key/apt_key.rb'
-
 # Offense count: 1
 # This cop supports unsafe autocorrection (--autocorrect-all).
 Style/GlobalStdStream:
index 8cdf78bb71293300afd6cb0c13d9806a6b950afb..9ad21bcc6e6f51d5873230c867475fd122fa47cb 100644 (file)
@@ -71,13 +71,14 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do
   def self.prefetch(resources)
     apt_keys = instances
     resources.each_key do |name|
-      if name.length == 40
+      case name.length
+      when 40
         provider = apt_keys.find { |key| key.fingerprint == name }
         resources[name].provider = provider if provider
-      elsif name.length == 16
+      when 16
         provider = apt_keys.find { |key| key.long == name }
         resources[name].provider = provider if provider
-      elsif name.length == 8
+      when 8
         provider = apt_keys.find { |key| key.short == name }
         resources[name].provider = provider if provider
       end
index f92282278494603a5e7cbcb3f77c0c3a7f26f3ba..b60724514eac3881c3a0b7c337d528a5130c66d6 100644 (file)
@@ -14,7 +14,7 @@ describe 'apt_reboot_required fact' do
       allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(true)
     end
 
-    it { is_expected.to eq true }
+    it { is_expected.to be true }
   end
 
   describe 'if a reboot is not required' do
@@ -24,6 +24,6 @@ describe 'apt_reboot_required fact' do
       allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(false)
     end
 
-    it { is_expected.to eq false }
+    it { is_expected.to be false }
   end
 end
index a23aa90c4ce9d99ed2ed73b57a01edf0d7a95013..a146a26e82353a17de24c9339e1c1fb27b0be838 100644 (file)
@@ -24,19 +24,19 @@ describe Puppet::Type.type(:apt_key) do
     end
 
     it 'source is not set' do
-      expect(resource[:source]).to eq nil
+      expect(resource[:source]).to be_nil
     end
 
     it 'content is not set' do
-      expect(resource[:content]).to eq nil
+      expect(resource[:content]).to be_nil
     end
 
     it 'refresh is not set' do
-      expect(resource[:refresh]).to eq nil
+      expect(resource[:refresh]).to be_nil
     end
 
     it 'weak_ssl is not set' do
-      expect(resource[:weak_ssl]).to eq nil
+      expect(resource[:weak_ssl]).to be_nil
     end
   end
 
@@ -167,7 +167,7 @@ describe Puppet::Type.type(:apt_key) do
         Puppet::Type.type(:apt_key).new(id: 'EF8D349F',
                                         source: 'http://apt.puppetlabs.com/pubkey.gpg',
                                         ensure: :absent,
-                                        refresh: :true)
+                                        refresh: true)
       }.to raise_error(%r{ensure => absent and refresh => true are mutually exclusive})
     end