Skip to content

Commit 18c2ab9

Browse files
author
Shane da Silva
committed
Fix some Rubocop lints
Major offense is the use of redundant `return` in order to avoid having to specify square brackets for the tuple that gets returned. Change-Id: Ied0f10a81f2753ca721d5961c08bfb5f93f587cf Reviewed-on: http://gerrit.causes.com/36062 Tested-by: jenkins <jenkins@causes.com> Reviewed-by: Shane da Silva <shane@causes.com>
1 parent cc9d4ce commit 18c2ab9

File tree

15 files changed

+37
-22
lines changed

15 files changed

+37
-22
lines changed

lib/overcommit/hook/commit_msg/gerrit_change_id.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module Overcommit::Hook::CommitMsg
88
class GerritChangeId < Base
99
def run
1010
result = execute([SCRIPT_LOCATION, commit_message_file])
11-
return (result.success? ? :good : :bad), result.stdout
11+
return :good if result.success?
12+
13+
[:bad, result.stdout]
1214
end
1315

1416
private

lib/overcommit/hook/pre_commit/coffee_lint.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ def run
88

99
result = execute(%w[coffeelint --quiet] + applicable_files)
1010
return :good if result.success?
11-
return :bad, result.stdout
11+
12+
[:bad, result.stdout]
1213
end
1314
end
1415
end

lib/overcommit/hook/pre_commit/css_lint.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ def run
77
end
88

99
result = execute(%w[csslint --quiet --format=compact] + applicable_files)
10-
output = result.stdout
11-
return (output !~ /Error - (?!Unknown @ rule)/ ? :good : :bad), output
10+
return :good if result.stdout !~ /Error - (?!Unknown @ rule)/
11+
12+
[:bad, result.stdout]
1213
end
1314
end
1415
end

lib/overcommit/hook/pre_commit/haml_lint.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ def run
1919
end
2020

2121
return :bad, error_lines.join("\n") unless error_lines.empty?
22-
return :warn, "Modified files have lints (on lines you didn't modify)\n" <<
23-
warning_lines.join("\n")
22+
23+
[:warn, "Modified files have lints (on lines you didn't modify)\n" <<
24+
warning_lines.join("\n")]
2425
end
2526
end
2627
end

lib/overcommit/hook/pre_commit/js_hint.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ def run
99
result = execute(%w[jshint] + applicable_files)
1010
output = result.stdout
1111

12-
return (output.empty? ? :good : :bad), output
12+
return :good if output.empty?
13+
14+
[:bad, output]
1315
end
1416
end
1517
end

lib/overcommit/hook/pre_commit/jscs.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def run
2424
end
2525

2626
return :bad, error_lines.join("\n") unless error_lines.empty?
27-
return :warn, "Modified files have lints (on lines you didn't modify)\n" <<
28-
warning_lines.join("\n")
27+
28+
[:warn, "Modified files have lints (on lines you didn't modify)\n" <<
29+
warning_lines.join("\n")]
2930
end
3031
end
3132
end

lib/overcommit/hook/pre_commit/python_flake8.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ def run
77
end
88

99
result = execute(%w[flake8] + applicable_files)
10+
return :good if result.success?
1011

11-
return (result.success? ? :good : :bad), result.stdout
12+
[:bad, result.stdout]
1213
end
1314
end
1415
end

lib/overcommit/hook/pre_commit/rubocop.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ def run
2121
end
2222

2323
return :bad, error_lines.join("\n") unless error_lines.empty?
24-
return :warn, "Modified files have lints (on lines you didn't modify)\n" <<
25-
warning_lines.join("\n")
24+
25+
[:warn, "Modified files have lints (on lines you didn't modify)\n" <<
26+
warning_lines.join("\n")]
2627
end
2728
end
2829
end

lib/overcommit/hook/pre_commit/scss_lint.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ def run
1919
end
2020

2121
return :bad, error_lines.join("\n") unless error_lines.empty?
22-
return :warn, "Modified files have lints (on lines you didn't modify)\n" <<
23-
warning_lines.join("\n")
22+
23+
[:warn, "Modified files have lints (on lines you didn't modify)\n" <<
24+
warning_lines.join("\n")]
2425
end
2526
end
2627
end

lib/overcommit/hook/pre_commit/travis_lint.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ def run
88

99
result = execute(%w[travis-lint] + applicable_files)
1010
return :good if result.success?
11-
return :bad, result.stdout.strip
11+
12+
[:bad, result.stdout.strip]
1213
end
1314
end
1415
end

lib/overcommit/hook/pre_commit/yaml_syntax.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ module Overcommit::Hook::PreCommit
44
# Checks the syntax of any modified YAML files.
55
class YamlSyntax < Base
66
def run
7-
clean = true
87
output = []
98

109
applicable_files.each do |file|
1110
begin
1211
YAML.load_file(file)
1312
rescue ArgumentError => e
1413
output << "#{e.message} parsing #{file}"
15-
clean = false
1614
end
1715
end
1816

19-
return (clean ? :good : :bad), output
17+
return :good if output.empty?
18+
19+
[:bad, output]
2020
end
2121
end
2222
end

lib/overcommit/hook_context/post_checkout.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module Overcommit::HookContext
2+
# Contains helpers related to contextual information used by post-checkout
3+
# hooks.
24
class PostCheckout < Base
35
# Returns the ref of the HEAD that we transitioned from.
46
def previous_head

lib/overcommit/installer.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def install_hook_symlinks
7878
Overcommit::Utils.supported_hook_types.each do |hook_type|
7979
unless can_replace_file?(hook_type)
8080
raise Overcommit::Exceptions::PreExistingHooks,
81-
"Hook '#{File.expand_path(hook_type)}' already exists and was not installed by Overcommit"
81+
"Hook '#{File.expand_path(hook_type)}' already exists and " <<
82+
'was not installed by Overcommit'
8283
end
8384
FileUtils.ln_sf('overcommit-hook', hook_type)
8485
end

spec/overcommit/hook/commit_msg/text_width_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
let(:commit_msg) { <<-MSG }
8282
Some summary
8383
84-
This line is longer than 80 characters which can clearly be seen by counting the number of characters.
84+
This line is longer than #{'A' * 80} characters.
8585
MSG
8686

8787
it { should warn 'Line 3 of commit message has > 80 characters' }
@@ -103,7 +103,7 @@
103103
let(:commit_msg) { <<-MSG }
104104
A subject line that is way too long. A subject line that is way too long.
105105
106-
A message line that is way too long. A message line that is way too long. A message line that is way too long.
106+
This line is longer than #{'A' * 80} characters.
107107
MSG
108108

109109
it { should warn /keep.*subject <= 70.*\n.*line 3.*> 80.*/im }

template-dir/hooks/overcommit-hook

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# to manage your hooks for you.
66

77
# Required for Ruby 1.8 compatibility (for older OSX versions)
8-
if RUBY_VERSION.split('.')[0..1] == ['1', '8']
8+
if RUBY_VERSION.split('.')[0..1] == %w[1 8]
99
require 'rubygems'
1010
end
1111

0 commit comments

Comments
 (0)