Skip to content

Commit 01b5e60

Browse files
authored
Merge pull request #171 from tagliala/chore/rubocop-stage-iv
RuboCop: Stage IV
2 parents 9ab5ccf + 40c7a16 commit 01b5e60

19 files changed

+94
-215
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ AllCops:
1111
NewCops: enable
1212
DisplayStyleGuide: true
1313
ExtraDetails: true
14+
15+
# https://github.com/jamesmartin/inline_svg/pull/171/files#r1798763446
16+
Style/EachWithObject:
17+
Enabled: false

.rubocop_todo.yml

Lines changed: 0 additions & 123 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ RSpec::Core::RakeTask.new(:spec) do |t|
55
t.pattern = Dir.glob("spec/**/*_spec.rb")
66
# t.rspec_opts = "--format documentation"
77
end
8-
task :default => :spec
8+
task default: :spec

lib/inline_svg.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ def initialize
3030
end
3131

3232
def asset_file=(custom_asset_file)
33-
begin
34-
method = custom_asset_file.method(:named)
35-
if method.arity == 1
36-
@asset_file = custom_asset_file
37-
else
38-
raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method with arity 1")
39-
end
40-
rescue NameError
41-
raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method")
33+
method = custom_asset_file.method(:named)
34+
if method.arity == 1
35+
@asset_file = custom_asset_file
36+
else
37+
raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method with arity 1")
4238
end
39+
rescue NameError
40+
raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method")
4341
end
4442

4543
def asset_finder=(finder)
@@ -67,7 +65,7 @@ def add_custom_transformation(options)
6765
raise InlineSvg::Configuration::Invalid.new("#{options.fetch(:transform)} should implement the .create_with_value and #transform methods")
6866
end
6967

70-
@custom_transformations.merge!(Hash[*[options.fetch(:attribute, :no_attribute), options]])
68+
@custom_transformations.merge!(options.fetch(:attribute, :no_attribute) => options)
7169
end
7270

7371
def raise_on_file_not_found=(value)

lib/inline_svg/action_view/helpers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def placeholder(filename)
5454
not_found_message = "'#{ERB::Util.html_escape_once(filename)}' #{extension_hint(filename)}"
5555

5656
if css_class.nil?
57-
return "<svg><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
57+
"<svg><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
5858
else
59-
return "<svg class='#{css_class}'><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
59+
"<svg class='#{css_class}'><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
6060
end
6161
end
6262

lib/inline_svg/transform_pipeline/transformations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def self.without_empty_values(params)
6565
def self.all_default_values
6666
custom_transformations
6767
.values
68-
.select { |opt| opt[:default_value] != nil }
68+
.reject { |opt| opt[:default_value].nil? }
6969
.map { |opt| [opt[:attribute], opt[:default_value]] }
7070
.inject({}) { |options, attrs| options.merge!(attrs[0] => attrs[1]) }
7171
end

spec/cached_asset_file_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require "inline_svg"
55

66
describe InlineSvg::CachedAssetFile do
7-
let(:fixture_path) { Pathname.new(File.expand_path("../files/static_assets", __FILE__)) }
7+
let(:fixture_path) { Pathname.new(File.expand_path('files/static_assets', __dir__)) }
88

99
it "loads assets under configured paths" do
1010
known_document = File.read(fixture_path.join("assets0", "known-document.svg"))

spec/finds_asset_paths_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
it "returns fully qualified file paths from Sprockets" do
77
sprockets = double('SprocketsDouble')
88

9-
expect(sprockets).to receive(:find_asset).with('some-file').
10-
and_return(double(pathname: Pathname('/full/path/to/some-file')))
9+
expect(sprockets).to receive(:find_asset).with('some-file')
10+
.and_return(double(pathname: Pathname('/full/path/to/some-file')))
1111

1212
InlineSvg.configure do |config|
1313
config.asset_finder = sprockets
@@ -21,8 +21,8 @@
2121
it "returns fully qualified file paths from Sprockets" do
2222
sprockets = double('SprocketsDouble')
2323

24-
expect(sprockets).to receive(:find_asset).with('some-file').
25-
and_return(double(filename: Pathname('/full/path/to/some-file')))
24+
expect(sprockets).to receive(:find_asset).with('some-file')
25+
.and_return(double(filename: Pathname('/full/path/to/some-file')))
2626

2727
InlineSvg.configure do |config|
2828
config.asset_finder = sprockets
@@ -50,8 +50,8 @@
5050
it "returns fully qualified file paths from Propshaft" do
5151
propshaft = double('PropshaftDouble')
5252

53-
expect(propshaft).to receive(:find_asset).with('some-file').
54-
and_return(double(pathname: Pathname('/full/path/to/some-file')))
53+
expect(propshaft).to receive(:find_asset).with('some-file')
54+
.and_return(double(pathname: Pathname('/full/path/to/some-file')))
5555

5656
InlineSvg.configure do |config|
5757
config.asset_finder = propshaft
@@ -65,8 +65,8 @@
6565
it "returns the fully qualified file path" do
6666
shakapacker = double('ShakapackerDouble')
6767

68-
expect(shakapacker).to receive(:find_asset).with('some-file').
69-
and_return(double(filename: Pathname('/full/path/to/some-file')))
68+
expect(shakapacker).to receive(:find_asset).with('some-file')
69+
.and_return(double(filename: Pathname('/full/path/to/some-file')))
7070

7171
InlineSvg.configure do |config|
7272
config.asset_finder = shakapacker
@@ -80,8 +80,8 @@
8080
it "returns the fully qualified file path" do
8181
shakapacker = double('ShakapackerDouble')
8282

83-
expect(shakapacker).to receive(:find_asset).with('some-file').
84-
and_return(double(filename: Pathname('https://my-fancy-domain.test/full/path/to/some-file')))
83+
expect(shakapacker).to receive(:find_asset).with('some-file')
84+
.and_return(double(filename: Pathname('https://my-fancy-domain.test/full/path/to/some-file')))
8585

8686
InlineSvg.configure do |config|
8787
config.asset_finder = shakapacker

0 commit comments

Comments
 (0)