Skip to content
This repository has been archived by the owner on Jul 1, 2019. It is now read-only.

Commit

Permalink
Resolve a few rubocop warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Smith <[email protected]>
  • Loading branch information
tas50 committed Dec 8, 2017
1 parent 31138e3 commit e071c6e
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 32 deletions.
7 changes: 3 additions & 4 deletions lib/rubocop/cop/chef/attribute_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/rubocop/cop/chef/file_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def autocorrect(node)
def is_octal?(node)
node.source =~ /^0o?\d+/i
end

end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/chef/tmp_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions rubocop-chef.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
require 'rubocop/chef/version'

Expand Down Expand Up @@ -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
24 changes: 12 additions & 12 deletions spec/rubocop/chef/cookbook_only_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion spec/rubocop/cop/chef/service_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@
end
RUBY
end

end
1 change: 0 additions & 1 deletion spec/rubocop/cop/chef/tmp_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@
end
RUBY
end

end
12 changes: 7 additions & 5 deletions spec/support/expect_violation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -142,7 +143,8 @@ def to_a
class Parser
COLUMN_PATTERN = /^ *(?<carets>\^\^*) (?<message>.+)$/

include Concord.new(:text), Adamantium
include Adamantium
include Concord.new(:text)

def column_range
Range.new(*match.offset(:carets), true)
Expand Down

0 comments on commit e071c6e

Please sign in to comment.