Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RuboCop warnings #841

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.6
NewCops: disable
SuggestExtensions: false

Layout/ClosingParenthesisIndentation:
Enabled: false
Expand Down
16 changes: 7 additions & 9 deletions lib/overcommit/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,13 @@ def install_or_uninstall
end

@options[:targets].each do |target|
begin
Installer.new(log).run(target, @options)
rescue Overcommit::Exceptions::InvalidGitRepo => e
log.warning "Invalid repo #{target}: #{e}"
halt 69 # EX_UNAVAILABLE
rescue Overcommit::Exceptions::PreExistingHooks => e
log.warning "Unable to install into #{target}: #{e}"
halt 73 # EX_CANTCREAT
end
Installer.new(log).run(target, @options)
rescue Overcommit::Exceptions::InvalidGitRepo => e
log.warning "Invalid repo #{target}: #{e}"
halt 69 # EX_UNAVAILABLE
rescue Overcommit::Exceptions::PreExistingHooks => e
log.warning "Unable to install into #{target}: #{e}"
halt 73 # EX_CANTCREAT
end
end

Expand Down
14 changes: 6 additions & 8 deletions lib/overcommit/hook/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,12 @@ def check_for_libraries
output = []

required_libraries.each do |library|
begin
require library
rescue LoadError
install_command = @config['install_command']
install_command = " -- install via #{install_command}" if install_command

output << "Unable to load '#{library}'#{install_command}"
end
require library
rescue LoadError
install_command = @config['install_command']
install_command = " -- install via #{install_command}" if install_command

output << "Unable to load '#{library}'#{install_command}"
end

return if output.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/commit_msg/text_width.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def find_errors_in_body(lines)

max_body_width = config['max_body_width']

lines[2..-1].each_with_index do |line, index|
lines[2..].each_with_index do |line, index|
if line.chomp.size > max_body_width
@errors << "Line #{index + 3} of commit message has > " \
"#{max_body_width} characters"
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/erb_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def run
return :pass if result.success?

extract_messages(
result.stdout.split("\n\n")[1..-1],
result.stdout.split("\n\n")[1..],
MESSAGE_REGEX
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/html_hint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def run
lines = group.split("\n").map(&:strip)
file = lines[0][/(.+):/, 1]
extract_messages(
lines[1..-1].map { |msg| "#{file}: #{msg}" },
lines[1..].map { |msg| "#{file}: #{msg}" },
/^(?<file>(?:\w:)?[^:]+): line (?<line>\d+)/
)
end.flatten
Expand Down
10 changes: 4 additions & 6 deletions lib/overcommit/hook/pre_commit/json_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ def run
messages = []

applicable_files.each do |file|
begin
JSON.parse(IO.read(file))
rescue JSON::ParserError => e
error = "#{e.message} parsing #{file}"
messages << Overcommit::Hook::Message.new(:error, file, nil, error)
end
JSON.parse(IO.read(file))
rescue JSON::ParserError => e
error = "#{e.message} parsing #{file}"
messages << Overcommit::Hook::Message.new(:error, file, nil, error)
end

messages
Expand Down
10 changes: 4 additions & 6 deletions lib/overcommit/hook/pre_commit/xml_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ def run
messages = []

applicable_files.each do |file|
begin
REXML::Document.new(IO.read(file))
rescue REXML::ParseException => e
error = "Error parsing #{file}: #{e.message}"
messages << Overcommit::Hook::Message.new(:error, file, nil, error)
end
REXML::Document.new(IO.read(file))
rescue REXML::ParseException => e
error = "Error parsing #{file}: #{e.message}"
messages << Overcommit::Hook::Message.new(:error, file, nil, error)
end

messages
Expand Down
16 changes: 7 additions & 9 deletions lib/overcommit/hook/pre_commit/yaml_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ def run
messages = []

applicable_files.each do |file|
YAML.load_file(file, aliases: true)
rescue ArgumentError
begin
YAML.load_file(file, aliases: true)
rescue ArgumentError
begin
YAML.load_file(file)
rescue ArgumentError, Psych::SyntaxError => e
messages << Overcommit::Hook::Message.new(:error, file, nil, e.message)
end
rescue Psych::DisallowedClass => e
messages << error_message(file, e)
YAML.load_file(file)
rescue ArgumentError, Psych::SyntaxError => e
messages << Overcommit::Hook::Message.new(:error, file, nil, e.message)
end
rescue Psych::DisallowedClass => e
messages << error_message(file, e)
end

messages
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/utils/messages_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def extract_messages(output_messages, regex, type_categorizer = nil)
raise Overcommit::Exceptions::MessageProcessingError,
'Unexpected output: unable to determine line number or type ' \
"of error/warning for output:\n" \
"#{output_messages[index..-1].join("\n")}"
"#{output_messages[index..].join("\n")}"
end

file = extract_file(match, message)
Expand Down
2 changes: 1 addition & 1 deletion overcommit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |s|
Dir['libexec/**/*'] +
Dir['template-dir/**/*']

s.required_ruby_version = '>= 2.4'
s.required_ruby_version = '>= 2.6'

s.add_dependency 'childprocess', '>= 0.6.3', '< 6'
s.add_dependency 'iniparse', '~> 1.4'
Expand Down