From 106d1749c965b8af857c976197814707b66cbef0 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:43:29 -0500 Subject: Fix issues reported by fasterer --- lib/diff/lcs/hunk.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/diff/lcs/hunk.rb') diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 49b520e..d27b024 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -22,7 +22,7 @@ class Diff::LCS::Hunk end if String.method_defined?(:encoding) - @preferred_data_encoding = data_old.fetch(0, data_new.fetch(0, '')).encoding + @preferred_data_encoding = data_old.fetch(0) { data_new.fetch(0) { '' } }.encoding end @data_old = data_old -- cgit v1.2.1 From f85ec381137c6838600b16c353ff9dba3a05452c Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:44:44 -0500 Subject: standardrb --only Style/StringLiterals --fix --- lib/diff/lcs/hunk.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/diff/lcs/hunk.rb') diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index d27b024..2a9645d 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'diff/lcs/block' +require "diff/lcs/block" # A Hunk is a group of Blocks which overlap because of the context surrounding # each block. (So if we're not using context, every hunk will contain one # block.) Used in the diff program (bin/ldiff). class Diff::LCS::Hunk - OLD_DIFF_OP_ACTION = { '+' => 'a', '-' => 'd', '!' => 'c' }.freeze #:nodoc: - ED_DIFF_OP_ACTION = { '+' => 'a', '-' => 'd', '!' => 'c' }.freeze #:nodoc: + OLD_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze #:nodoc: + ED_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze #:nodoc: private_constant :OLD_DIFF_OP_ACTION, :ED_DIFF_OP_ACTION if respond_to?(:private_constant) @@ -22,7 +22,7 @@ class Diff::LCS::Hunk end if String.method_defined?(:encoding) - @preferred_data_encoding = data_old.fetch(0) { data_new.fetch(0) { '' } }.encoding + @preferred_data_encoding = data_old.fetch(0) { data_new.fetch(0) { "" } }.encoding end @data_old = data_old @@ -133,7 +133,7 @@ class Diff::LCS::Hunk # Note that an old diff can't have any context. Therefore, we know that # there's only one block in the hunk. def old_diff(_last = false) - warn 'Expecting only one block in an old diff hunk!' if @blocks.size > 1 + warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1 block = @blocks[0] @@ -144,13 +144,13 @@ class Diff::LCS::Hunk # If removing anything, just print out all the remove lines in the hunk # which is just all the remove lines in the block. unless block.remove.empty? - @data_old[@start_old..@end_old].each { |e| s << encode('< ') + e.chomp + encode("\n") } + @data_old[@start_old..@end_old].each { |e| s << encode("< ") + e.chomp + encode("\n") } end - s << encode("---\n") if block.op == '!' + s << encode("---\n") if block.op == "!" unless block.insert.empty? - @data_new[@start_new..@end_new].each { |e| s << encode('> ') + e.chomp + encode("\n") } + @data_new[@start_new..@end_new].each { |e| s << encode("> ") + e.chomp + encode("\n") } end s @@ -213,7 +213,7 @@ class Diff::LCS::Hunk def context_diff(last = false) s = encode("***************\n") s << encode("*** #{context_range(:old, ',', last)} ****\n") - r = context_range(:new, ',', last) + r = context_range(:new, ",", last) if last old_missing_newline = missing_last_newline?(@data_old) @@ -269,7 +269,7 @@ class Diff::LCS::Hunk private :context_diff def ed_diff(format, _last = false) - warn 'Expecting only one block in an old diff hunk!' if @blocks.size > 1 + warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1 s = if format == :reverse_ed -- cgit v1.2.1 From 089f932537a540af9c27dd03caf30eff6b4a0306 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:50:34 -0500 Subject: standardrb --only Layout/ExtraSpacing --fix and ignore --- lib/diff/lcs/hunk.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/diff/lcs/hunk.rb') diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 2a9645d..3e4133d 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -54,8 +54,8 @@ class Diff::LCS::Hunk @start_old = a1 || (b1 - before) @start_new = b1 || (a1 + before) - @end_old = a2 || (b2 - after) - @end_new = b2 || (a2 + after) + @end_old = a2 || (b2 - after) + @end_new = b2 || (a2 + after) self.flag_context = flag_context end @@ -183,7 +183,7 @@ class Diff::LCS::Hunk @blocks.each do |block| block.remove.each do |item| - op = item.action.to_s # - + op = item.action.to_s # - offset = item.position - lo + num_added outlist[offset][0, 1] = encode(op) num_removed += 1 @@ -195,7 +195,7 @@ class Diff::LCS::Hunk end block.insert.each do |item| - op = item.action.to_s # + + op = item.action.to_s # + offset = item.position - @start_new + num_removed outlist[offset, 0] = encode(op) + @data_new[item.position].chomp num_added += 1 -- cgit v1.2.1 From 22303f04b44d97455b5c862176d2d93c02a2b2ba Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 10:58:14 -0500 Subject: Fix Style/AndOr --- lib/diff/lcs/hunk.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/diff/lcs/hunk.rb') diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 3e4133d..eccfc7a 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -70,7 +70,7 @@ class Diff::LCS::Hunk attr_accessor :flag_context # rubocop:disable Layout/EmptyLinesAroundAttributeAccessor undef :flag_context= def flag_context=(context) #:nodoc: # rubocop:disable Lint/DuplicateMethods - return if context.nil? or context.zero? + return if context.nil? || context.zero? add_start = context > @start_old ? @start_old : context -- cgit v1.2.1 From 396a82c4d56bc0067c86de7cd32a4ae75f292c41 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:03:11 -0500 Subject: standardrb --only Layout/LeadingCommentSpace --fix --- lib/diff/lcs/hunk.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/diff/lcs/hunk.rb') diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index eccfc7a..d886ba2 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -6,8 +6,8 @@ require "diff/lcs/block" # each block. (So if we're not using context, every hunk will contain one # block.) Used in the diff program (bin/ldiff). class Diff::LCS::Hunk - OLD_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze #:nodoc: - ED_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze #:nodoc: + OLD_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze # :nodoc: + ED_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze # :nodoc: private_constant :OLD_DIFF_OP_ACTION, :ED_DIFF_OP_ACTION if respond_to?(:private_constant) @@ -69,7 +69,7 @@ class Diff::LCS::Hunk # to this hunk. attr_accessor :flag_context # rubocop:disable Layout/EmptyLinesAroundAttributeAccessor undef :flag_context= - def flag_context=(context) #:nodoc: # rubocop:disable Lint/DuplicateMethods + def flag_context=(context) # :nodoc: # rubocop:disable Lint/DuplicateMethods return if context.nil? || context.zero? add_start = context > @start_old ? @start_old : context -- cgit v1.2.1 From 63bb988f761da3fa061c9e3b5d13785477bf44c5 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:14:33 -0500 Subject: standardrb --only Layout/SpaceInsideHashLiteralBraces --fix --- lib/diff/lcs/hunk.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/diff/lcs/hunk.rb') diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index d886ba2..9ff3638 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -6,8 +6,8 @@ require "diff/lcs/block" # each block. (So if we're not using context, every hunk will contain one # block.) Used in the diff program (bin/ldiff). class Diff::LCS::Hunk - OLD_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze # :nodoc: - ED_DIFF_OP_ACTION = { "+" => "a", "-" => "d", "!" => "c" }.freeze # :nodoc: + OLD_DIFF_OP_ACTION = {"+" => "a", "-" => "d", "!" => "c"}.freeze # :nodoc: + ED_DIFF_OP_ACTION = {"+" => "a", "-" => "d", "!" => "c"}.freeze # :nodoc: private_constant :OLD_DIFF_OP_ACTION, :ED_DIFF_OP_ACTION if respond_to?(:private_constant) -- cgit v1.2.1 From 7d087cc973685105e2bc1c69dca60d719138dcbc Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:25:24 -0500 Subject: Clean up lint directives --- lib/diff/lcs/hunk.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/diff/lcs/hunk.rb') diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 9ff3638..9f596f3 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -67,9 +67,9 @@ class Diff::LCS::Hunk # Change the "start" and "end" fields to note that context should be added # to this hunk. - attr_accessor :flag_context # rubocop:disable Layout/EmptyLinesAroundAttributeAccessor + attr_accessor :flag_context undef :flag_context= - def flag_context=(context) # :nodoc: # rubocop:disable Lint/DuplicateMethods + def flag_context=(context) # :nodoc: # standard:disable Lint/DuplicateMethods return if context.nil? || context.zero? add_start = context > @start_old ? @start_old : context -- cgit v1.2.1 From b160187f3d94f84b38faadb0726f7b0ae773d7eb Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:25:43 -0500 Subject: standardrb --only Style/Alias --fix --- lib/diff/lcs/hunk.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/diff/lcs/hunk.rb') diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 9f596f3..7f97a7d 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -102,7 +102,7 @@ class Diff::LCS::Hunk @start_new = hunk.start_new blocks.unshift(*hunk.blocks) end - alias unshift merge + alias_method :unshift, :merge # Determines whether there is an overlap between this hunk and the # provided hunk. This will be true if the difference between the two hunks -- cgit v1.2.1 From e5e78807564a3565a37d385b0898cd58776820f4 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:35:49 -0500 Subject: standardrb --only Style/StringLiteralsInInterpolation --fix and more --- lib/diff/lcs/hunk.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lib/diff/lcs/hunk.rb') diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 7f97a7d..8da65c2 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -22,7 +22,7 @@ class Diff::LCS::Hunk end if String.method_defined?(:encoding) - @preferred_data_encoding = data_old.fetch(0) { data_new.fetch(0) { "" } }.encoding + @preferred_data_encoding = data_old.fetch(0) { data_new.fetch(0, "") }.encoding end @data_old = data_old @@ -33,7 +33,6 @@ class Diff::LCS::Hunk @file_length_difference = after # The caller must get this manually @max_diff_size = @blocks.map { |e| e.diff_size.abs }.max - # Save the start & end of each array. If the array doesn't exist (e.g., # we're only adding items in this block), then figure out the line number # based on the line number of the other file and the current difference in @@ -140,7 +139,7 @@ class Diff::LCS::Hunk # Calculate item number range. Old diff range is just like a context # diff range, except the ranges are on one line with the action between # them. - s = encode("#{context_range(:old, ',')}#{OLD_DIFF_OP_ACTION[block.op]}#{context_range(:new, ',')}\n") + s = encode("#{context_range(:old, ",")}#{OLD_DIFF_OP_ACTION[block.op]}#{context_range(:new, ",")}\n") # If removing anything, just print out all the remove lines in the hunk # which is just all the remove lines in the block. unless block.remove.empty? @@ -172,7 +171,7 @@ class Diff::LCS::Hunk # file -- don't take removed items into account. lo, hi, num_added, num_removed = @start_old, @end_old, 0, 0 - outlist = @data_old[lo..hi].map { |e| String.new("#{encode(' ')}#{e.chomp}") } + outlist = @data_old[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } last_block = blocks[-1] @@ -212,7 +211,7 @@ class Diff::LCS::Hunk def context_diff(last = false) s = encode("***************\n") - s << encode("*** #{context_range(:old, ',', last)} ****\n") + s << encode("*** #{context_range(:old, ",", last)} ****\n") r = context_range(:new, ",", last) if last @@ -226,7 +225,7 @@ class Diff::LCS::Hunk removes = @blocks.reject { |e| e.remove.empty? } unless removes.empty? - outlist = @data_old[lo..hi].map { |e| String.new("#{encode(' ')}#{e.chomp}") } + outlist = @data_old[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } last_block = removes[-1] @@ -248,7 +247,7 @@ class Diff::LCS::Hunk inserts = @blocks.reject { |e| e.insert.empty? } unless inserts.empty? - outlist = @data_new[lo..hi].map { |e| String.new("#{encode(' ')}#{e.chomp}") } + outlist = @data_new[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } last_block = inserts[-1] @@ -273,9 +272,9 @@ class Diff::LCS::Hunk s = if format == :reverse_ed - encode("#{ED_DIFF_OP_ACTION[@blocks[0].op]}#{context_range(:old, ',')}\n") + encode("#{ED_DIFF_OP_ACTION[@blocks[0].op]}#{context_range(:old, ",")}\n") else - encode("#{context_range(:old, ' ')}#{ED_DIFF_OP_ACTION[@blocks[0].op]}\n") + encode("#{context_range(:old, " ")}#{ED_DIFF_OP_ACTION[@blocks[0].op]}\n") end unless @blocks[0].insert.empty? -- cgit v1.2.1 From c00ef1d173c3663a3edd0adaee21cbcad7e1b3c3 Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Thu, 23 Dec 2021 11:37:31 -0500 Subject: standardrb --only Style/StringLiteralsInInterpolation --- lib/diff/lcs/hunk.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/diff/lcs/hunk.rb') diff --git a/lib/diff/lcs/hunk.rb b/lib/diff/lcs/hunk.rb index 8da65c2..2cef5ed 100644 --- a/lib/diff/lcs/hunk.rb +++ b/lib/diff/lcs/hunk.rb @@ -171,7 +171,9 @@ class Diff::LCS::Hunk # file -- don't take removed items into account. lo, hi, num_added, num_removed = @start_old, @end_old, 0, 0 + # standard:disable Performance/UnfreezeString outlist = @data_old[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } + # standard:enable Performance/UnfreezeString last_block = blocks[-1] @@ -225,7 +227,9 @@ class Diff::LCS::Hunk removes = @blocks.reject { |e| e.remove.empty? } unless removes.empty? + # standard:disable Performance/UnfreezeString outlist = @data_old[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } + # standard:enable Performance/UnfreezeString last_block = removes[-1] @@ -247,7 +251,9 @@ class Diff::LCS::Hunk inserts = @blocks.reject { |e| e.insert.empty? } unless inserts.empty? + # standard:disable Performance/UnfreezeString outlist = @data_new[lo..hi].map { |e| String.new("#{encode(" ")}#{e.chomp}") } + # standard:enable Performance/UnfreezeString last_block = inserts[-1] -- cgit v1.2.1