Skip to content

Commit

Permalink
Fix RuboCop warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sds committed Feb 25, 2024
1 parent a2fb742 commit ac9fde1
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 44 deletions.
4 changes: 3 additions & 1 deletion .rubocop.yml
@@ -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
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
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
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
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
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
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
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
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
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
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

0 comments on commit ac9fde1

Please sign in to comment.