diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 3bc6d7a..5f8202a 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -6,17 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: leading, trailing
-Layout/DotPosition:
- Exclude:
- - 'spec/finds_asset_paths_spec.rb'
- - 'spec/helpers/inline_svg_spec.rb'
- - 'spec/id_generator_spec.rb'
- - 'spec/transformation_pipeline/transformations/aria_attributes_spec.rb'
- - 'spec/transformation_pipeline/transformations/data_attributes_spec.rb'
-
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
@@ -41,22 +30,6 @@ Layout/MultilineMethodCallIndentation:
- 'spec/transformation_pipeline/transformations/style_attribute_spec.rb'
- 'spec/transformation_pipeline/transformations/view_box_spec.rb'
-# This cop supports safe autocorrection (--autocorrect).
-Lint/AmbiguousOperator:
- Exclude:
- - 'spec/io_resource_spec.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
-Lint/LiteralInInterpolation:
- Exclude:
- - 'spec/inline_svg_spec.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AllowPercentLiteralArrayArgument.
-Lint/RedundantSplatExpansion:
- Exclude:
- - 'lib/inline_svg.rb'
-
Lint/ShadowingOuterLocalVariable:
Exclude:
- 'lib/inline_svg/transform_pipeline/transformations/description.rb'
@@ -102,17 +75,6 @@ Performance/MapCompact:
Exclude:
- 'lib/inline_svg/transform_pipeline/transformations.rb'
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AutoCorrect.
-RSpec/BeEmpty:
- Exclude:
- - 'spec/transformation_pipeline/transformations_spec.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
-RSpec/ContextMethod:
- Exclude:
- - 'spec/transformation_pipeline/transformations/transformation_spec.rb'
-
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
@@ -121,7 +83,6 @@ RSpec/ContextWording:
- 'spec/inline_svg_spec.rb'
- 'spec/io_resource_spec.rb'
- 'spec/transformation_pipeline/transformations/aria_attributes_spec.rb'
- - 'spec/transformation_pipeline/transformations/transformation_spec.rb'
- 'spec/transformation_pipeline/transformations_spec.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
@@ -140,12 +101,6 @@ RSpec/EmptyExampleGroup:
RSpec/ExampleLength:
Max: 32
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: .
-# SupportedStyles: implicit, each, example
-RSpec/HookArgument:
- EnforcedStyle: each
-
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit
@@ -153,11 +108,6 @@ RSpec/ImplicitSubject:
Exclude:
- 'spec/io_resource_spec.rb'
-# This cop supports safe autocorrection (--autocorrect).
-RSpec/MatchArray:
- Exclude:
- - 'spec/transformation_pipeline/transformations_spec.rb'
-
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
@@ -176,14 +126,6 @@ RSpec/NamedSubject:
RSpec/NestedGroups:
Max: 4
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: not_to, to_not
-RSpec/NotToNot:
- Exclude:
- - 'spec/helpers/inline_svg_spec.rb'
- - 'spec/io_resource_spec.rb'
-
RSpec/RepeatedExampleGroupDescription:
Exclude:
- 'spec/helpers/inline_svg_spec.rb'
@@ -254,18 +196,6 @@ Style/CollectionCompact:
Style/Documentation:
Enabled: false
-# This cop supports safe autocorrection (--autocorrect).
-Style/EachWithObject:
- Exclude:
- - 'lib/inline_svg/transform_pipeline/transformations.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
-Style/ExpandPathArguments:
- Exclude:
- - 'spec/cached_asset_file_spec.rb'
- - 'spec/helpers/inline_svg_spec.rb'
- - 'spec/io_resource_spec.rb'
-
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
@@ -277,15 +207,6 @@ Style/FrozenStringLiteralComment:
Style/GuardClause:
Exclude:
- 'lib/inline_svg.rb'
- - 'lib/inline_svg/action_view/helpers.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
-# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
-# SupportedShorthandSyntax: always, never, either, consistent, either_consistent
-Style/HashSyntax:
- Exclude:
- - 'Rakefile'
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
@@ -294,12 +215,6 @@ Style/IfUnlessModifier:
- 'lib/inline_svg/static_asset_finder.rb'
- 'lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb'
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: InverseMethods, InverseBlocks.
-Style/InverseMethods:
- Exclude:
- - 'lib/inline_svg/transform_pipeline/transformations.rb'
-
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/MapIntoArray:
Exclude:
@@ -313,19 +228,6 @@ Style/MutableConstant:
- 'lib/inline_svg/asset_file.rb'
- 'lib/inline_svg/version.rb'
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AllowedMethods.
-# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with
-Style/NestedParenthesizedCalls:
- Exclude:
- - 'spec/io_resource_spec.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: IncludeSemanticChanges.
-Style/NonNilCheck:
- Exclude:
- - 'lib/inline_svg/transform_pipeline/transformations.rb'
-
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowedCompactTypes.
# SupportedStyles: compact, exploded
@@ -341,24 +243,6 @@ Style/RedundantArgument:
Exclude:
- 'lib/inline_svg/transform_pipeline/transformations/class_attribute.rb'
-# This cop supports safe autocorrection (--autocorrect).
-Style/RedundantBegin:
- Exclude:
- - 'lib/inline_svg.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
-Style/RedundantConstantBase:
- Exclude:
- - 'spec/propshaft_asset_finder_spec.rb'
- - 'spec/static_asset_finder_spec.rb'
- - 'spec/webpack_asset_finder_spec.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AllowMultipleReturnValues.
-Style/RedundantReturn:
- Exclude:
- - 'lib/inline_svg/action_view/helpers.rb'
-
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantSelf:
Exclude:
@@ -372,13 +256,6 @@ Style/RedundantSelf:
- 'lib/inline_svg/transform_pipeline/transformations/transformation.rb'
- 'lib/inline_svg/transform_pipeline/transformations/width.rb'
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
-# SupportedStyles: slashes, percent_r, mixed
-Style/RegexpLiteral:
- Exclude:
- - 'spec/transformation_pipeline/transformations/transformation_spec.rb'
-
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
# AllowedMethods: present?, blank?, presence, try, try!
diff --git a/Rakefile b/Rakefile
index 88c85cf..0391f03 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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
diff --git a/lib/inline_svg.rb b/lib/inline_svg.rb
index 7a76776..8ad5d44 100644
--- a/lib/inline_svg.rb
+++ b/lib/inline_svg.rb
@@ -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)
@@ -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)
diff --git a/lib/inline_svg/action_view/helpers.rb b/lib/inline_svg/action_view/helpers.rb
index 957b6b0..8d945fe 100644
--- a/lib/inline_svg/action_view/helpers.rb
+++ b/lib/inline_svg/action_view/helpers.rb
@@ -54,9 +54,9 @@ def placeholder(filename)
not_found_message = "'#{ERB::Util.html_escape_once(filename)}' #{extension_hint(filename)}"
if css_class.nil?
- return "".html_safe
+ "".html_safe
else
- return "".html_safe
+ "".html_safe
end
end
diff --git a/lib/inline_svg/transform_pipeline/transformations.rb b/lib/inline_svg/transform_pipeline/transformations.rb
index 39558f7..0759e85 100644
--- a/lib/inline_svg/transform_pipeline/transformations.rb
+++ b/lib/inline_svg/transform_pipeline/transformations.rb
@@ -24,11 +24,10 @@ def self.custom_transformations
end
def self.magnify_priorities(transforms)
- transforms.inject({}) do |output, (name, definition)|
+ transforms.each_with_object({}) do |(name, definition), output|
priority = definition.fetch(:priority, built_in_transformations.size)
output[name] = definition.merge({ priority: magnify(priority) })
- output
end
end
@@ -65,7 +64,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
diff --git a/spec/cached_asset_file_spec.rb b/spec/cached_asset_file_spec.rb
index e99dbe2..29c0284 100644
--- a/spec/cached_asset_file_spec.rb
+++ b/spec/cached_asset_file_spec.rb
@@ -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"))
diff --git a/spec/finds_asset_paths_spec.rb b/spec/finds_asset_paths_spec.rb
index 4354490..b68cefd 100644
--- a/spec/finds_asset_paths_spec.rb
+++ b/spec/finds_asset_paths_spec.rb
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
diff --git a/spec/helpers/inline_svg_spec.rb b/spec/helpers/inline_svg_spec.rb
index 1626bf7..f67945d 100644
--- a/spec/helpers/inline_svg_spec.rb
+++ b/spec/helpers/inline_svg_spec.rb
@@ -14,7 +14,7 @@ def transform(doc)
shared_examples "inline_svg helper" do |helper_method:|
context "when passed the name of an SVG that does not exist" do
- after(:each) do
+ after do
InlineSvg.reset_configuration!
end
@@ -24,9 +24,9 @@ def transform(doc)
config.raise_on_file_not_found = true
end
- allow(InlineSvg::AssetFile).to receive(:named).
- with('some-missing-file.svg').
- and_raise(InlineSvg::AssetFile::FileNotFound.new)
+ allow(InlineSvg::AssetFile).to receive(:named)
+ .with('some-missing-file.svg')
+ .and_raise(InlineSvg::AssetFile::FileNotFound.new)
expect {
helper.send(helper_method, 'some-missing-file.svg')
@@ -35,9 +35,9 @@ def transform(doc)
end
it "returns an empty, html safe, SVG document as a placeholder" do
- allow(InlineSvg::AssetFile).to receive(:named).
- with('some-missing-file.svg').
- and_raise(InlineSvg::AssetFile::FileNotFound.new)
+ allow(InlineSvg::AssetFile).to receive(:named)
+ .with('some-missing-file.svg')
+ .and_raise(InlineSvg::AssetFile::FileNotFound.new)
output = helper.send(helper_method, 'some-missing-file.svg')
expect(output).to eq ""
@@ -46,9 +46,9 @@ def transform(doc)
it "escapes malicious input" do
malicious = "-->