Skip to content

Commit

Permalink
Fix Style/AndOr
Browse files Browse the repository at this point in the history
  • Loading branch information
halostatue committed Jul 5, 2022
1 parent f5781c0 commit 22303f0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions lib/diff/lcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ def traverse_sequences(seq1, seq2, callbacks = Diff::LCS::SequenceCallbacks) #:y

# The last entry (if any) processed was a match. +ai+ and +bj+ point just
# past the last matching lines in their sequences.
while (ai < a_size) or (bj < b_size)
while (ai < a_size) || (bj < b_size)
# last A?
if ai == a_size and bj < b_size
if callbacks.respond_to?(:finished_a) and !run_finished_a
if ai == a_size && bj < b_size
if callbacks.respond_to?(:finished_a) && !run_finished_a
ax = string ? seq1[-1, 1] : seq1[-1]
bx = string ? seq2[bj, 1] : seq2[bj]
event = Diff::LCS::ContextChange.new(">", (a_size - 1), ax, bj, bx)
Expand All @@ -350,8 +350,8 @@ def traverse_sequences(seq1, seq2, callbacks = Diff::LCS::SequenceCallbacks) #:y
end

# last B?
if bj == b_size and ai < a_size
if callbacks.respond_to?(:finished_b) and !run_finished_b
if bj == b_size && ai < a_size
if callbacks.respond_to?(:finished_b) && !run_finished_b
ax = string ? seq1[ai, 1] : seq1[ai]
bx = string ? seq2[-1, 1] : seq2[-1]
event = Diff::LCS::ContextChange.new("<", ai, ax, (b_size - 1), bx)
Expand Down Expand Up @@ -485,15 +485,15 @@ def traverse_balanced(seq1, seq2, callbacks = Diff::LCS::BalancedCallbacks)
# Find next match indices +ma+ and +mb+
loop do
ma += 1
break unless ma < matches.size and matches[ma].nil?
break unless ma < matches.size && matches[ma].nil?
end

break if ma >= matches.size # end of matches?

mb = matches[ma]

# Change(seq2)
while (ai < ma) or (bj < mb)
while (ai < ma) || (bj < mb)
ax = string ? seq1[ai, 1] : seq1[ai]
bx = string ? seq2[bj, 1] : seq2[bj]

Expand Down Expand Up @@ -539,7 +539,7 @@ def traverse_balanced(seq1, seq2, callbacks = Diff::LCS::BalancedCallbacks)
bj += 1
end

while (ai < a_size) or (bj < b_size)
while (ai < a_size) || (bj < b_size)
ax = string ? seq1[ai, 1] : seq1[ai]
bx = string ? seq2[bj, 1] : seq2[bj]

Expand Down
4 changes: 2 additions & 2 deletions lib/diff/lcs/change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def initialize(*args)
@action, @old_position, @old_element, @new_position, @new_element = *args

fail "Invalid Change Action '#{@action}'" unless Diff::LCS::Change.valid_action?(@action)
fail "Invalid (Old) Position Type" unless @old_position.nil? or @old_position.kind_of? IntClass
fail "Invalid (New) Position Type" unless @new_position.nil? or @new_position.kind_of? IntClass
fail "Invalid (Old) Position Type" unless @old_position.nil? || @old_position.kind_of?(IntClass)
fail "Invalid (New) Position Type" unless @new_position.nil? || @new_position.kind_of?(IntClass)
end

def to_a
Expand Down
2 changes: 1 addition & 1 deletion lib/diff/lcs/hunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def initialize(data_old, data_new, piece, flag_context, file_length_difference)
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

Expand Down
8 changes: 4 additions & 4 deletions lib/diff/lcs/internals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def lcs(a, b)
vector = []

# Collect any common elements at the beginning...
while (a_start <= a_finish) and (b_start <= b_finish) and (a[a_start] == b[b_start])
while (a_start <= a_finish) && (b_start <= b_finish) && (a[a_start] == b[b_start])
vector[a_start] = b_start
a_start += 1
b_start += 1
end

# Now the end...
while (a_start <= a_finish) and (b_start <= b_finish) and (a[a_finish] == b[b_finish])
while (a_start <= a_finish) && (b_start <= b_finish) && (a[a_finish] == b[b_finish])
vector[a_finish] = b_finish
a_finish -= 1
b_finish -= 1
Expand All @@ -75,7 +75,7 @@ def lcs(a, b)
# it may have an optimization purpose
# An attempt to remove it: https://github.com/halostatue/diff-lcs/pull/72
# Why it is reintroduced: https://github.com/halostatue/diff-lcs/issues/78
if k and (thresh[k] > j) and (thresh[k - 1] < j)
if k && (thresh[k] > j) && (thresh[k - 1] < j)
thresh[k] = j
else
k = replace_next_larger(thresh, j, k)
Expand Down Expand Up @@ -251,7 +251,7 @@ def intuit_diff_direction(src, patchset, limit = nil)
# This operation preserves the sort order.
def replace_next_larger(enum, value, last_index = nil)
# Off the end?
if enum.empty? or (value > enum[-1])
if enum.empty? || (value > enum[-1])
enum << value
return enum.size - 1
end
Expand Down
4 changes: 2 additions & 2 deletions lib/diff/lcs/ldiff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def run(args, _input = $stdin, output = $stdout, error = $stderr) #:nodoc:
return 1
end

if (@format == :unified) or (@format == :context)
if (@format == :unified) || (@format == :context)
ft = File.stat(file_old).mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.000000000 %z")
output << "#{char_old} #{file_old}\t#{ft}\n"
ft = File.stat(file_new).mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.000000000 %z")
Expand All @@ -152,7 +152,7 @@ def run(args, _input = $stdin, output = $stdout, error = $stderr) #:nodoc:
file_length_difference = hunk.file_length_difference

next unless oldhunk
next if @lines.positive? and hunk.merge(oldhunk)
next if @lines.positive? && hunk.merge(oldhunk)

output << oldhunk.diff(@format)
output << "\n" if @format == :unified
Expand Down

0 comments on commit 22303f0

Please sign in to comment.