When running rubocop -a --only=Lint/DeprecatedOpenSSLConstant its breaking the code.
Output:
config/initializers/xing_paperclip_setup.rb:2:15: E: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
anew('SHA1')chment.instance.class.to_s.split('::').last.underscore
^^^^^^
config/initializers/xing_paperclip_setup.rb:3:1: E: Lint/Syntax: unexpected token kEND
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
end
^^^
config/initializers/xing_paperclip_setup.rb:15:36: W: [Corrected] Lint/DeprecatedOpenSSLConstant: Use OpenSSL::Digest.new('SHA1') instead of OpenSSL::Digest::SHA1.new.
hash = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, Rails.application.secrets.secret_key_base, data)
^^^^^^^^^^^^^^^^^^^^^^^^^
spec/config/initializers/xing_paperclip_setup_spec.rb:1:50: E: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
describe Paperclip::Interpolations do new('SHA1')ubocop:disable RSpec/FilePath
^^^^^^
spec/config/initializers/xing_paperclip_setup_spec.rb:26:17: W: [Corrected] Lint/DeprecatedOpenSSLConstant: Use OpenSSL::Digest.new('SHA1') instead of OpenSSL::Digest::SHA1.new.
.with(OpenSSL::Digest::SHA1.new, Rails.application.secrets.secret_key_base, data)
^^^^^^^^^^^^^^^^^^^^^^^^^
spec/config/initializers/xing_paperclip_setup_spec.rb:33:1: E: Lint/Syntax: unexpected token kEND
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
end
Broken Changes:
- attachment.instance.class.to_s.split('::').last.underscore
+ anew('SHA1')chment.instance.class.to_s.split('::').last.underscore
- describe Paperclip::Interpolations do # rubocop:disable RSpec/FilePath
+ describe Paperclip::Interpolations do new('SHA1')ubocop:disable RSpec/FilePath
Should only correct change, not other places.
Correcting changes, but also breaking code.
rubocop -a --only=Lint/DeprecatedOpenSSLConstant
0.84.0 (using Parser 2.7.1.2, rubocop-ast 0.0.3, running on ruby 2.7.1 x86_64-darwin19)
Can you show me the original code before auto-correction?
Sure
Paperclip.interpolates :class do |attachment, _style|
attachment.instance.class.to_s.split('::').last.underscore
end
# The security team complained, that the URL of (private) events would be
# guessable. To make this harder be added a hash to the path. In order to not
# migrate all existing files we need to distinguish between old and new
# images/documents. Adding a flag would be the more elegant way, but we have
# many models with assets so the more simple solution is the time bomb.
Paperclip.interpolates :xing_id_partition do |attachment, style|
id = attachment.instance.id || 0
if attachment.instance.updated_at > Time.zone.parse('2019-08-23 00:00')
# inspired by https://github.com/thoughtbot/paperclip/blob/90f9121a18df25bc3ef948356450ce19fbe1da83/lib/paperclip/attachment.rb#L325
data = %i[class id].map { |method| attachment.instance.send(method) }.push(style).join('/')
hash = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, Rails.application.secrets.secret_key_base, data)
end
format("%03x", id)[-3..].split('').push(id).push(hash).compact.join('/')
end
I've opened #8014. Thank you!
Most helpful comment
I've opened #8014. Thank you!