Skip to content

Commit

Permalink
Autofix some safe RuboCop offenses
Browse files Browse the repository at this point in the history
- `Layout/DotPosition`
- `Lint/AmbiguousOperator`
- `Lint/LiteralInInterpolation`
- `RSpec/BeEmpty`
- `RSpec/ContextMethod`
- `RSpec/HookArgument`
- `RSpec/MatchArray`
- `RSpec/NotToNot`
- `Style/ExpandPathArguments`
- `Style/HashSyntax`
- `Style/NestedParenthesizedCalls`
- `Style/RedundantBegin`
- `Style/RedundantConstantBase`
- `Style/RedundantReturn`
- `Style/RegexpLiteral`

Some manual fixes:
- `Lint/RedundantSplatExpansion` and subsequent unsafe
  manual fix of `Style/HashConversion`
- `Style/NonNilCheck` and subsequent switch unsafe manual fix of
  `Style/InverseMethods`
  • Loading branch information
tagliala committed Oct 14, 2024
1 parent 9ab5ccf commit 40c7a16
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 215 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ AllCops:
NewCops: enable
DisplayStyleGuide: true
ExtraDetails: true

# https://github.com/jamesmartin/inline_svg/pull/171/files#r1798763446
Style/EachWithObject:
Enabled: false
123 changes: 0 additions & 123 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = Dir.glob("spec/**/*_spec.rb")
# t.rspec_opts = "--format documentation"
end
task :default => :spec
task default: :spec
18 changes: 8 additions & 10 deletions lib/inline_svg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ def initialize
end

def asset_file=(custom_asset_file)
begin
method = custom_asset_file.method(:named)
if method.arity == 1
@asset_file = custom_asset_file
else
raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method with arity 1")
end
rescue NameError
raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method")
method = custom_asset_file.method(:named)
if method.arity == 1
@asset_file = custom_asset_file
else
raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method with arity 1")
end
rescue NameError
raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method")
end

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

@custom_transformations.merge!(Hash[*[options.fetch(:attribute, :no_attribute), options]])
@custom_transformations.merge!(options.fetch(:attribute, :no_attribute) => options)
end

def raise_on_file_not_found=(value)
Expand Down
4 changes: 2 additions & 2 deletions lib/inline_svg/action_view/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def placeholder(filename)
not_found_message = "'#{ERB::Util.html_escape_once(filename)}' #{extension_hint(filename)}"

if css_class.nil?
return "<svg><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
"<svg><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
else
return "<svg class='#{css_class}'><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
"<svg class='#{css_class}'><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/inline_svg/transform_pipeline/transformations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def self.without_empty_values(params)
def self.all_default_values
custom_transformations
.values
.select { |opt| opt[:default_value] != nil }
.reject { |opt| opt[:default_value].nil? }
.map { |opt| [opt[:attribute], opt[:default_value]] }
.inject({}) { |options, attrs| options.merge!(attrs[0] => attrs[1]) }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/cached_asset_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "inline_svg"

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

it "loads assets under configured paths" do
known_document = File.read(fixture_path.join("assets0", "known-document.svg"))
Expand Down
20 changes: 10 additions & 10 deletions spec/finds_asset_paths_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
it "returns fully qualified file paths from Sprockets" do
sprockets = double('SprocketsDouble')

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

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

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

InlineSvg.configure do |config|
config.asset_finder = sprockets
Expand Down Expand Up @@ -50,8 +50,8 @@
it "returns fully qualified file paths from Propshaft" do
propshaft = double('PropshaftDouble')

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

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

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

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

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

InlineSvg.configure do |config|
config.asset_finder = shakapacker
Expand Down
Loading

0 comments on commit 40c7a16

Please sign in to comment.