Skip to content

Commit c4aa796

Browse files
authored
Fix RuboCop warnings (#841)
1 parent a2fb742 commit c4aa796

File tree

11 files changed

+36
-44
lines changed

11 files changed

+36
-44
lines changed

.rubocop.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
inherit_from: .rubocop_todo.yml
22

33
AllCops:
4-
TargetRubyVersion: 2.4
4+
TargetRubyVersion: 2.6
5+
NewCops: disable
6+
SuggestExtensions: false
57

68
Layout/ClosingParenthesisIndentation:
79
Enabled: false

lib/overcommit/cli.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,13 @@ def install_or_uninstall
124124
end
125125

126126
@options[:targets].each do |target|
127-
begin
128-
Installer.new(log).run(target, @options)
129-
rescue Overcommit::Exceptions::InvalidGitRepo => e
130-
log.warning "Invalid repo #{target}: #{e}"
131-
halt 69 # EX_UNAVAILABLE
132-
rescue Overcommit::Exceptions::PreExistingHooks => e
133-
log.warning "Unable to install into #{target}: #{e}"
134-
halt 73 # EX_CANTCREAT
135-
end
127+
Installer.new(log).run(target, @options)
128+
rescue Overcommit::Exceptions::InvalidGitRepo => e
129+
log.warning "Invalid repo #{target}: #{e}"
130+
halt 69 # EX_UNAVAILABLE
131+
rescue Overcommit::Exceptions::PreExistingHooks => e
132+
log.warning "Unable to install into #{target}: #{e}"
133+
halt 73 # EX_CANTCREAT
136134
end
137135
end
138136

lib/overcommit/hook/base.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,12 @@ def check_for_libraries
228228
output = []
229229

230230
required_libraries.each do |library|
231-
begin
232-
require library
233-
rescue LoadError
234-
install_command = @config['install_command']
235-
install_command = " -- install via #{install_command}" if install_command
236-
237-
output << "Unable to load '#{library}'#{install_command}"
238-
end
231+
require library
232+
rescue LoadError
233+
install_command = @config['install_command']
234+
install_command = " -- install via #{install_command}" if install_command
235+
236+
output << "Unable to load '#{library}'#{install_command}"
239237
end
240238

241239
return if output.empty?

lib/overcommit/hook/commit_msg/text_width.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def find_errors_in_body(lines)
4141

4242
max_body_width = config['max_body_width']
4343

44-
lines[2..-1].each_with_index do |line, index|
44+
lines[2..].each_with_index do |line, index|
4545
if line.chomp.size > max_body_width
4646
@errors << "Line #{index + 3} of commit message has > " \
4747
"#{max_body_width} characters"

lib/overcommit/hook/pre_commit/erb_lint.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def run
1212
return :pass if result.success?
1313

1414
extract_messages(
15-
result.stdout.split("\n\n")[1..-1],
15+
result.stdout.split("\n\n")[1..],
1616
MESSAGE_REGEX
1717
)
1818
end

lib/overcommit/hook/pre_commit/html_hint.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def run
1414
lines = group.split("\n").map(&:strip)
1515
file = lines[0][/(.+):/, 1]
1616
extract_messages(
17-
lines[1..-1].map { |msg| "#{file}: #{msg}" },
17+
lines[1..].map { |msg| "#{file}: #{msg}" },
1818
/^(?<file>(?:\w:)?[^:]+): line (?<line>\d+)/
1919
)
2020
end.flatten

lib/overcommit/hook/pre_commit/json_syntax.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ def run
77
messages = []
88

99
applicable_files.each do |file|
10-
begin
11-
JSON.parse(IO.read(file))
12-
rescue JSON::ParserError => e
13-
error = "#{e.message} parsing #{file}"
14-
messages << Overcommit::Hook::Message.new(:error, file, nil, error)
15-
end
10+
JSON.parse(IO.read(file))
11+
rescue JSON::ParserError => e
12+
error = "#{e.message} parsing #{file}"
13+
messages << Overcommit::Hook::Message.new(:error, file, nil, error)
1614
end
1715

1816
messages

lib/overcommit/hook/pre_commit/xml_syntax.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ def run
77
messages = []
88

99
applicable_files.each do |file|
10-
begin
11-
REXML::Document.new(IO.read(file))
12-
rescue REXML::ParseException => e
13-
error = "Error parsing #{file}: #{e.message}"
14-
messages << Overcommit::Hook::Message.new(:error, file, nil, error)
15-
end
10+
REXML::Document.new(IO.read(file))
11+
rescue REXML::ParseException => e
12+
error = "Error parsing #{file}: #{e.message}"
13+
messages << Overcommit::Hook::Message.new(:error, file, nil, error)
1614
end
1715

1816
messages

lib/overcommit/hook/pre_commit/yaml_syntax.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ def run
77
messages = []
88

99
applicable_files.each do |file|
10+
YAML.load_file(file, aliases: true)
11+
rescue ArgumentError
1012
begin
11-
YAML.load_file(file, aliases: true)
12-
rescue ArgumentError
13-
begin
14-
YAML.load_file(file)
15-
rescue ArgumentError, Psych::SyntaxError => e
16-
messages << Overcommit::Hook::Message.new(:error, file, nil, e.message)
17-
end
18-
rescue Psych::DisallowedClass => e
19-
messages << error_message(file, e)
13+
YAML.load_file(file)
14+
rescue ArgumentError, Psych::SyntaxError => e
15+
messages << Overcommit::Hook::Message.new(:error, file, nil, e.message)
2016
end
17+
rescue Psych::DisallowedClass => e
18+
messages << error_message(file, e)
2119
end
2220

2321
messages

lib/overcommit/utils/messages_utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def extract_messages(output_messages, regex, type_categorizer = nil)
2626
raise Overcommit::Exceptions::MessageProcessingError,
2727
'Unexpected output: unable to determine line number or type ' \
2828
"of error/warning for output:\n" \
29-
"#{output_messages[index..-1].join("\n")}"
29+
"#{output_messages[index..].join("\n")}"
3030
end
3131

3232
file = extract_file(match, message)

0 commit comments

Comments
 (0)