diff --git a/.rubocop.yml b/.rubocop.yml index 091f612..e146555 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -15,9 +15,6 @@ Layout/CaseIndentation: Layout/EndAlignment: EnforcedStyleAlignWith: variable -Layout/FirstHashElementIndentation: - EnforcedStyle: consistent - Layout/LineLength: Max: 120 @@ -25,9 +22,6 @@ Layout/SpaceBeforeBlockBraces: EnforcedStyle: no_space EnforcedStyleForEmptyBraces: no_space -Lint/PercentStringArray: # broken in rubocop 0.55.0 - Enabled: false - Metrics/BlockLength: Exclude: - 'spec/**/*.rb' @@ -41,39 +35,18 @@ Metrics/MethodLength: Naming/MethodParameterName: Enabled: false -Style/AccessorGrouping: - Enabled: false - Style/Alias: EnforcedStyle: prefer_alias_method -Style/EmptyCaseCondition: - Enabled: false - -Style/Encoding: - Enabled: false - -Style/FileRead: +Style/ArgumentsForwarding: Enabled: false -Style/HashEachMethods: - Enabled: true - -Style/HashTransformKeys: - Enabled: false - -Style/HashTransformValues: - Enabled: false - -Style/IfUnlessModifier: +Style/EmptyCaseCondition: Enabled: false Style/NumericPredicate: Enabled: false -Style/ParallelAssignment: - Enabled: false - Style/SafeNavigation: Enabled: false diff --git a/lib/image_size.rb b/lib/image_size.rb index a881e7f..7fd6a0f 100644 --- a/lib/image_size.rb +++ b/lib/image_size.rb @@ -150,17 +150,13 @@ def size_of_gif(ir) end def size_of_mng(ir) - unless ir[12, 4] == 'MHDR' - raise FormatError, 'MHDR not in place for MNG' - end + raise FormatError, 'MHDR not in place for MNG' unless ir[12, 4] == 'MHDR' ir.unpack(16, 8, 'NN') end def size_of_png(ir) - unless ir[12, 4] == 'IHDR' - raise FormatError, 'IHDR not in place for PNG' - end + raise FormatError, 'IHDR not in place for PNG' unless ir[12, 4] == 'IHDR' ir.unpack(16, 8, 'NN') end @@ -178,14 +174,12 @@ def size_of_jpeg(ir) loop do offset += 1 until [nil, section_marker].include? ir[offset, 1] offset += 1 until section_marker != ir[offset + 1, 1] - raise FormatError, 'EOF in JPEG' if ir[offset, 1].nil? + raise FormatError, 'EOF in JPEG' unless ir[offset, 1] code, length = ir.unpack(offset, 4, 'xCn') offset += 4 - if JPEG_CODE_CHECK.include?(code) - return ir.unpack(offset + 1, 4, 'nn').reverse - end + return ir.unpack(offset + 1, 4, 'nn').reverse if JPEG_CODE_CHECK.include?(code) offset += length - 2 end @@ -250,9 +244,7 @@ def size_of_xbm(ir) def size_of_xpm(ir) length = 1024 until (data = ir[0, length]) =~ /"\s*(\d+)\s+(\d+)(\s+\d+\s+\d+){1,2}\s*"/m - if data.length != length - raise FormatError, 'XPM size not found' - end + raise FormatError, 'XPM size not found' if data.length != length length += 1024 end @@ -281,7 +273,7 @@ def size_of_tiff(ir) tag, type = ifd.unpack(endian2b * 2) offset += 12 - next if packspec[type].nil? + next unless packspec[type] value = ifd[8, 4].unpack(packspec[type])[0] case tag diff --git a/spec/image_size/chunky_reader_spec.rb b/spec/image_size/chunky_reader_spec.rb index 5322033..51e27a8 100644 --- a/spec/image_size/chunky_reader_spec.rb +++ b/spec/image_size/chunky_reader_spec.rb @@ -29,7 +29,7 @@ def chunk_size { 'empty string' => '', 'a bit of data' => 'foo bar baz', - 'a lot of data' => File.open('GPL', 'rb', &:read), + 'a lot of data' => File.binread('GPL'), }.each do |data_description, data| { 'default' => test_reader.new(data), diff --git a/spec/image_size_spec.rb b/spec/image_size_spec.rb index 3561ecf..892c58a 100644 --- a/spec/image_size_spec.rb +++ b/spec/image_size_spec.rb @@ -62,8 +62,11 @@ def supported_formats describe "for #{path}" do let(:name){ File.basename(path) } let(:attributes) do - match = /(\d+)x(\d+)\.([^.]+)$/.match(name) - width, height, format = match[1].to_i, match[2].to_i, match[3].to_sym if match + if (match = /(\d+)x(\d+)\.([^.]+)$/.match(name)) + width = match[1].to_i + height = match[2].to_i + format = match[3].to_sym + end size = format && [width, height] media_types = ImageSize::MEDIA_TYPES[format] || [] media_type = format && media_types.first.to_s @@ -78,7 +81,7 @@ def supported_formats media_types: media_types, } end - let(:file_data){ File.open(path, 'rb', &:read) } + let(:file_data){ File.binread(path) } let(:file_size){ file_data.length } before do