From e071c6e5e8018b6d262a1230a4f666fa6bb4aeca Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 7 Dec 2017 19:44:32 -0800 Subject: [PATCH] Resolve a few rubocop warnings Signed-off-by: Tim Smith --- lib/rubocop/cop/chef/attribute_keys.rb | 7 +++--- lib/rubocop/cop/chef/file_mode.rb | 1 - lib/rubocop/cop/chef/tmp_path.rb | 4 +--- rubocop-chef.gemspec | 8 +++---- spec/rubocop/chef/cookbook_only_spec.rb | 24 +++++++++---------- .../rubocop/cop/chef/service_resource_spec.rb | 1 - spec/rubocop/cop/chef/tmp_path_spec.rb | 1 - spec/support/expect_violation.rb | 12 ++++++---- 8 files changed, 26 insertions(+), 32 deletions(-) diff --git a/lib/rubocop/cop/chef/attribute_keys.rb b/lib/rubocop/cop/chef/attribute_keys.rb index 7804e2a..14a6684 100644 --- a/lib/rubocop/cop/chef/attribute_keys.rb +++ b/lib/rubocop/cop/chef/attribute_keys.rb @@ -79,14 +79,13 @@ def autocorrect(node) lambda do |corrector| key_string = node.children.first.to_s key_replacement = if style == :symbols - key_string.to_sym.inspect - else # strings - key_string.inspect + key_string.to_sym.inspect + else # strings + key_string.inspect end corrector.replace(node.loc.expression, key_replacement) end end - end end end diff --git a/lib/rubocop/cop/chef/file_mode.rb b/lib/rubocop/cop/chef/file_mode.rb index 21faa60..f34d1c8 100644 --- a/lib/rubocop/cop/chef/file_mode.rb +++ b/lib/rubocop/cop/chef/file_mode.rb @@ -55,7 +55,6 @@ def autocorrect(node) def is_octal?(node) node.source =~ /^0o?\d+/i end - end end end diff --git a/lib/rubocop/cop/chef/tmp_path.rb b/lib/rubocop/cop/chef/tmp_path.rb index 9d98a3f..b1154ec 100644 --- a/lib/rubocop/cop/chef/tmp_path.rb +++ b/lib/rubocop/cop/chef/tmp_path.rb @@ -29,7 +29,6 @@ module Chef # # class TmpPath < Cop - MSG = 'Use file_cache_path rather than hard-coding tmp paths'.freeze def_node_matcher :remote_file?, <<-PATTERN @@ -46,14 +45,13 @@ def on_send(node) def has_hardcoded_tmp?(path) path_str = path.to_s.scan(/"(.*)"/)[0][0] - path_str.start_with?("/tmp/") + path_str.start_with?('/tmp/') end def has_file_cache_path?(path) path_str = path.to_s.scan(/"(.*)"/)[0][0] path_str.start_with?("\#\{Chef::Config[:file_cache_path]\}") end - end end end diff --git a/rubocop-chef.gemspec b/rubocop-chef.gemspec index 147a94d..a422703 100755 --- a/rubocop-chef.gemspec +++ b/rubocop-chef.gemspec @@ -1,5 +1,3 @@ -# encoding: utf-8 - $LOAD_PATH.unshift File.expand_path('../lib', __FILE__) require 'rubocop/chef/version' @@ -29,11 +27,11 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'rubocop', '>= 0.39' + spec.add_development_dependency 'adamantium' + spec.add_development_dependency 'anima' + spec.add_development_dependency 'concord' spec.add_development_dependency 'rake' spec.add_development_dependency 'rspec', '>= 3.4' spec.add_development_dependency 'simplecov' - spec.add_development_dependency 'anima' - spec.add_development_dependency 'concord' - spec.add_development_dependency 'adamantium' spec.add_development_dependency 'yard' end diff --git a/spec/rubocop/chef/cookbook_only_spec.rb b/spec/rubocop/chef/cookbook_only_spec.rb index 3455b91..d1318f5 100644 --- a/spec/rubocop/chef/cookbook_only_spec.rb +++ b/spec/rubocop/chef/cookbook_only_spec.rb @@ -43,7 +43,7 @@ def on_send(node) end context 'with the metadata segment enabled' do - let(:segments) { {metadata: true} } + let(:segments) { { metadata: true } } it 'registers an offense' do expect_violation(<<-RUBY, filename: 'metadata.rb') @@ -54,7 +54,7 @@ def on_send(node) end # /context with the metadata segment enabled context 'with the metadata segment disabled' do - let(:segments) { {metadata: false} } + let(:segments) { { metadata: false } } it 'ignores the source' do expect_no_violations(<<-RUBY, filename: 'metadata.rb') @@ -73,7 +73,7 @@ def on_send(node) end context 'with the recipes segment enabled' do - let(:segments) { {recipes: true} } + let(:segments) { { recipes: true } } it 'registers an offense' do expect_violation(<<-RUBY, filename: 'recipes/default.rb') @@ -84,7 +84,7 @@ def on_send(node) end # /context with the recipes segment enabled context 'with the recipes segment disabled' do - let(:segments) { {recipes: false} } + let(:segments) { { recipes: false } } it 'ignores the source' do expect_no_violations(<<-RUBY, filename: 'recipes/default.rb') @@ -95,14 +95,14 @@ def on_send(node) end # /context when the source path is recipes/default.rb context 'when the source path is recipes/ignored.rb' do - it 'ignores the source' do - expect_no_violations(<<-RUBY, filename: 'recipes/ignored.rb') - foo(1) - RUBY - end + it 'ignores the source' do + expect_no_violations(<<-RUBY, filename: 'recipes/ignored.rb') + foo(1) + RUBY + end context 'with the recipes segment enabled' do - let(:segments) { {recipes: true} } + let(:segments) { { recipes: true } } it 'ignores the source' do expect_no_violations(<<-RUBY, filename: 'recipes/ignored.rb') @@ -112,7 +112,7 @@ def on_send(node) end # /context with the recipes segment enabled context 'with the recipes segment disabled' do - let(:segments) { {recipes: false} } + let(:segments) { { recipes: false } } it 'ignores the source' do expect_no_violations(<<-RUBY, filename: 'recipes/ignored.rb') @@ -124,7 +124,7 @@ def on_send(node) context 'when custom patterns are specified' do let(:all_cop_config) do - {'ChefRecipes' => {'Patterns' => ['chef/recipes/.*\\.rb']}} + { 'ChefRecipes' => { 'Patterns' => ['chef/recipes/.*\\.rb'] } } end it 'registers offenses when the path matches a custom specified pattern' do diff --git a/spec/rubocop/cop/chef/service_resource_spec.rb b/spec/rubocop/cop/chef/service_resource_spec.rb index 6190c07..c0e675d 100644 --- a/spec/rubocop/cop/chef/service_resource_spec.rb +++ b/spec/rubocop/cop/chef/service_resource_spec.rb @@ -35,5 +35,4 @@ end RUBY end - end diff --git a/spec/rubocop/cop/chef/tmp_path_spec.rb b/spec/rubocop/cop/chef/tmp_path_spec.rb index 9b9876c..666dc7b 100644 --- a/spec/rubocop/cop/chef/tmp_path_spec.rb +++ b/spec/rubocop/cop/chef/tmp_path_spec.rb @@ -35,5 +35,4 @@ end RUBY end - end diff --git a/spec/support/expect_violation.rb b/spec/support/expect_violation.rb index 99693c9..4f567fb 100755 --- a/spec/support/expect_violation.rb +++ b/spec/support/expect_violation.rb @@ -42,7 +42,8 @@ class Expectation VIOLATION = :violation SOURCE = :line - include Adamantium, Concord.new(:string) + include Concord.new(:string) + include Adamantium def source source_map.to_s @@ -125,9 +126,9 @@ def self.parse(text:, line_number:) ) end - include Anima.new(:message, :column_range, :line_number), - Adamantium, - Comparable + include Comparable + include Adamantium + include Anima.new(:message, :column_range, :line_number) def <=>(other) to_a <=> other.to_a @@ -142,7 +143,8 @@ def to_a class Parser COLUMN_PATTERN = /^ *(?\^\^*) (?.+)$/ - include Concord.new(:text), Adamantium + include Adamantium + include Concord.new(:text) def column_range Range.new(*match.offset(:carets), true)