Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuboCop: Stage IV #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

@tagliala tagliala Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: review with "hide whitespaces"


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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual fix 1: looks safe to me

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? }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual fix 2: looks safe to me

.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