From 8379ba64db63b5db8552c6b7b0f6a3c0eaa99a30 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 3 Sep 2020 23:18:01 +0200 Subject: [PATCH] Fix newly reported offenses * Style/MultilineWhenThen: Do not use then for multiline when statement * Style/StringConcatenation: Prefer string interpolation to string concatenation * Style/OptionalBooleanParameter: Use keyword arguments when defining method with boolean argument * Style/GlobalStdStream: Use $stderr instead of STDERR * Style/GlobalStdStream: Use $stdout instead of STDOUT --- lib/colorls/core.rb | 8 ++++---- lib/colorls/fileinfo.rb | 4 ++-- lib/colorls/flags.rb | 6 +++--- spec/color_ls/flags_spec.rb | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/colorls/core.rb b/lib/colorls/core.rb index a25f617..ca702af 100644 --- a/lib/colorls/core.rb +++ b/lib/colorls/core.rb @@ -34,7 +34,7 @@ module ColorLS return print "\n Nothing to show here\n".colorize(@colors[:empty]) if @contents.empty? layout = case - when @tree[:mode] then + when @tree[:mode] print "\n" return tree_traverse(@input, 0, 1, 2) when @horizontal @@ -76,14 +76,14 @@ module ColorLS end def init_contents(path) - info = FileInfo.new(path, link_info = @long) + info = FileInfo.new(path, link_info: @long) if info.directory? @contents = Dir.entries(path, encoding: Encoding::ASCII_8BIT) filter_hidden_contents - @contents.map! { |e| FileInfo.new(File.join(path, e), link_info = @long) } + @contents.map! { |e| FileInfo.new(File.join(path, e), link_info: @long) } filter_contents if @show sort_contents if @sort @@ -290,7 +290,7 @@ module ColorLS name = content.show name = make_link(path, name) if @hyperlink name += content.directory? ? '/' : ' ' - entry = logo.encode(Encoding.default_external, undef: :replace, replace: '') + ' ' + name + entry = "#{logo.encode(Encoding.default_external, undef: :replace, replace: '')} #{name}" "#{long_info(content)} #{git_info(content)} #{entry.colorize(color)}#{symlink_info(content)}" end diff --git a/lib/colorls/fileinfo.rb b/lib/colorls/fileinfo.rb index c128bca..1fb1a83 100644 --- a/lib/colorls/fileinfo.rb +++ b/lib/colorls/fileinfo.rb @@ -11,7 +11,7 @@ module ColorLS attr_reader :stats, :name - def initialize(path, link_info=true) + def initialize(path, link_info: true) @name = File.basename(path) @stats = File.lstat(path) @@ -70,7 +70,7 @@ module ColorLS @target = File.readlink(path) @dead = !File.exist?(path) rescue SystemCallError => e - STDERR.puts "cannot read symbolic link: #{e}" + $stderr.puts "cannot read symbolic link: #{e}" end end end diff --git a/lib/colorls/flags.rb b/lib/colorls/flags.rb index c2f1197..c964666 100644 --- a/lib/colorls/flags.rb +++ b/lib/colorls/flags.rb @@ -15,7 +15,7 @@ module ColorLS sort: true, reverse: false, group: nil, - mode: STDOUT.tty? ? :vertical : :one_per_line, + mode: STDOUT.tty? ? :vertical : :one_per_line, # rubocop:disable Style/GlobalStdStream all: false, almost_all: false, report: false, @@ -41,13 +41,13 @@ module ColorLS @args = ['.'] if @args.empty? @args.sort!.each_with_index do |path, i| - next STDERR.puts "\n Specified path '#{path}' doesn't exist.".colorize(:red) unless File.exist?(path) + next $stderr.puts "\n Specified path '#{path}' doesn't exist.".colorize(:red) unless File.exist?(path) puts '' if i.positive? puts "\n#{path}:" if Dir.exist?(path) && @args.size > 1 Core.new(path, **@opts).ls rescue SystemCallError => e - STDERR.puts "#{path}: #{e}".colorize(:red) + $stderr.puts "#{path}: #{e}".colorize(:red) end end diff --git a/spec/color_ls/flags_spec.rb b/spec/color_ls/flags_spec.rb index 8b22d22..94b85ef 100644 --- a/spec/color_ls/flags_spec.rb +++ b/spec/color_ls/flags_spec.rb @@ -83,7 +83,7 @@ RSpec.describe ColorLS::Flags do ) ) - allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", true) { fileInfo } + allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo } expect { subject }.to output(/r-Sr-Sr-T .* a.txt/mx).to_stdout end @@ -111,7 +111,7 @@ RSpec.describe ColorLS::Flags do ) ) - allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", true) { fileInfo } + allow(ColorLS::FileInfo).to receive(:new).with("#{FIXTURES}/a.txt", link_info: true) { fileInfo } expect { subject }.to output(/\S+\s+ 5 .* a.txt/mx).to_stdout end