rubocop 0.25.0 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +37 -0
- data/README.md +2 -2
- data/assets/output.html.erb +190 -0
- data/config/default.yml +14 -2
- data/config/disabled.yml +7 -0
- data/config/enabled.yml +132 -5
- data/lib/rubocop.rb +5 -0
- data/lib/rubocop/cop/commissioner.rb +4 -10
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/end_in_method.rb +3 -8
- data/lib/rubocop/cop/lint/ensure_return.rb +2 -2
- data/lib/rubocop/cop/lint/space_before_first_arg.rb +8 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +35 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -3
- data/lib/rubocop/cop/metrics/block_nesting.rb +3 -3
- data/lib/rubocop/cop/metrics/class_length.rb +1 -2
- data/lib/rubocop/cop/mixin/access_modifier_node.rb +5 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/configurable_naming.rb +2 -2
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -4
- data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -3
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +25 -2
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/and_or.rb +12 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +19 -12
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/dot_position.rb +20 -0
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +5 -1
- data/lib/rubocop/cop/style/encoding.rb +4 -4
- data/lib/rubocop/cop/style/format_string.rb +12 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +8 -11
- data/lib/rubocop/cop/style/infinite_loop.rb +57 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +15 -16
- data/lib/rubocop/cop/style/multiline_if_then.rb +10 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +3 -3
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -1
- data/lib/rubocop/cop/style/predicate_name.rb +23 -5
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +4 -8
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +9 -11
- data/lib/rubocop/cop/style/space_inside_range_literal.rb +58 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +71 -0
- data/lib/rubocop/cop/style/tab.rb +11 -3
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +6 -2
- data/lib/rubocop/cop/style/variable_name.rb +4 -14
- data/lib/rubocop/cop/style/while_until_modifier.rb +12 -8
- data/lib/rubocop/cop/variable_force.rb +17 -30
- data/lib/rubocop/cop/variable_force/assignment.rb +15 -23
- data/lib/rubocop/cop/variable_force/locatable.rb +29 -8
- data/lib/rubocop/cop/variable_force/scope.rb +34 -23
- data/lib/rubocop/cop/variable_force/variable.rb +7 -10
- data/lib/rubocop/formatter/disabled_config_formatter.rb +3 -2
- data/lib/rubocop/formatter/formatter_set.rb +1 -0
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/html_formatter.rb +90 -0
- data/lib/rubocop/formatter/progress_formatter.rb +1 -1
- data/lib/rubocop/options.rb +1 -0
- data/lib/rubocop/processed_source.rb +10 -1
- data/lib/rubocop/string_util.rb +153 -0
- data/lib/rubocop/target_finder.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.26.0.md +89 -0
- data/rubocop.gemspec +1 -0
- data/spec/rubocop/cli_spec.rb +60 -34
- data/spec/rubocop/config_loader_spec.rb +19 -15
- data/spec/rubocop/cop/commissioner_spec.rb +2 -2
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +74 -58
- data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +7 -0
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +173 -0
- data/spec/rubocop/cop/rails/validation_spec.rb +9 -2
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +26 -0
- data/spec/rubocop/cop/style/and_or_spec.rb +52 -61
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +26 -8
- data/spec/rubocop/cop/style/case_indentation_spec.rb +8 -8
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +6 -2
- data/spec/rubocop/cop/style/dot_position_spec.rb +39 -0
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +12 -2
- data/spec/rubocop/cop/style/encoding_spec.rb +16 -28
- data/spec/rubocop/cop/style/format_string_spec.rb +12 -0
- data/spec/rubocop/cop/style/infinite_loop_spec.rb +48 -0
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +3 -1
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +9 -0
- data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +21 -1
- data/spec/rubocop/cop/style/predicate_name_spec.rb +44 -13
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +32 -0
- data/spec/rubocop/cop/style/space_inside_range_literal_spec.rb +52 -0
- data/spec/rubocop/cop/style/symbol_proc_spec.rb +76 -0
- data/spec/rubocop/cop/style/tab_spec.rb +30 -0
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +2 -1
- data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +18 -5
- data/spec/rubocop/cop/style/variable_name_spec.rb +5 -5
- data/spec/rubocop/cop/style/when_then_spec.rb +3 -1
- data/spec/rubocop/cop/style/while_until_do_spec.rb +4 -2
- data/spec/rubocop/cop/util_spec.rb +1 -9
- data/spec/rubocop/cop/variable_force/assignment_spec.rb +2 -15
- data/spec/rubocop/cop/variable_force/locatable_spec.rb +2 -37
- data/spec/rubocop/cop/variable_force/scope_spec.rb +156 -49
- data/spec/rubocop/cop/variable_force/variable_spec.rb +2 -1
- data/spec/rubocop/cop/variable_force_spec.rb +2 -1
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +2 -1
- data/spec/rubocop/formatter/html_formatter_spec.rb +145 -0
- data/spec/rubocop/formatter/simple_text_formatter_spec.rb +18 -6
- data/spec/rubocop/options_spec.rb +1 -0
- data/spec/rubocop/path_util_spec.rb +6 -4
- data/spec/rubocop/processed_source_spec.rb +17 -1
- data/spec/rubocop/string_util_spec.rb +46 -0
- metadata +33 -4
- data/spec/support/ast_helper.rb +0 -15
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
module RuboCop
|
7
|
+
module Formatter
|
8
|
+
# This formatter saves the output as a html file.
|
9
|
+
class HTMLFormatter < BaseFormatter
|
10
|
+
include PathUtil
|
11
|
+
|
12
|
+
attr_reader :output_hash
|
13
|
+
|
14
|
+
def initialize(output)
|
15
|
+
super
|
16
|
+
@output_hash = {
|
17
|
+
metadata: metadata_hash,
|
18
|
+
files: [],
|
19
|
+
summary: { offense_count: 0 }
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def started(target_files)
|
24
|
+
output_hash[:summary][:target_file_count] = target_files.count
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_finished(file, offenses)
|
28
|
+
output_hash[:files] << hash_for_file(file, offenses)
|
29
|
+
output_hash[:summary][:offense_count] += offenses.count
|
30
|
+
end
|
31
|
+
|
32
|
+
def finished(inspected_files)
|
33
|
+
output_hash[:summary][:inspected_file_count] = inspected_files.count
|
34
|
+
template = File.read(File
|
35
|
+
.expand_path('../../../../assets/output.html.erb', __FILE__))
|
36
|
+
erb = ERB.new(template)
|
37
|
+
html_content = erb.result(binding)
|
38
|
+
output.write html_content
|
39
|
+
end
|
40
|
+
|
41
|
+
def metadata_hash
|
42
|
+
{
|
43
|
+
rubocop_version: RuboCop::Version::STRING,
|
44
|
+
ruby_engine: RUBY_ENGINE,
|
45
|
+
ruby_version: RUBY_VERSION,
|
46
|
+
ruby_patchlevel: RUBY_PATCHLEVEL.to_s,
|
47
|
+
ruby_platform: RUBY_PLATFORM
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def hash_for_file(file, offenses)
|
52
|
+
{
|
53
|
+
path: relative_path(file),
|
54
|
+
offenses: offenses.map { |o| hash_for_offense(o) }
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def hash_for_offense(offense)
|
59
|
+
{
|
60
|
+
severity: offense.severity.name,
|
61
|
+
message: offense.message,
|
62
|
+
cop_name: offense.cop_name,
|
63
|
+
corrected: offense.corrected?,
|
64
|
+
location: hash_for_location(offense)
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# TODO: Consider better solution for Offense#real_column.
|
69
|
+
def hash_for_location(offense)
|
70
|
+
{
|
71
|
+
line: offense.line,
|
72
|
+
column: offense.real_column,
|
73
|
+
length: offense.location.length,
|
74
|
+
source_line: offense.location.source_line,
|
75
|
+
highlight: highlight_line(offense.location)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def highlight_line(location)
|
80
|
+
column_length = if location.begin.line == location.end.line
|
81
|
+
location.column_range.count
|
82
|
+
else
|
83
|
+
location.source_line.length - location.column
|
84
|
+
end
|
85
|
+
|
86
|
+
' ' * location.column + '^' * column_length
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/rubocop/options.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'astrolabe/builder'
|
4
|
+
|
3
5
|
module RuboCop
|
4
6
|
# ProcessedSource contains objects which are generated by Parser
|
5
7
|
# and other information such as disabled lines for cops.
|
@@ -14,6 +16,11 @@ module RuboCop
|
|
14
16
|
end
|
15
17
|
|
16
18
|
def initialize(source, path = nil)
|
19
|
+
# In Ruby 2, source code encoding defaults to UTF-8. We follow the same
|
20
|
+
# principle regardless of which Ruby version we're running under.
|
21
|
+
# Encoding comments will override this setting.
|
22
|
+
source.force_encoding(Encoding::UTF_8)
|
23
|
+
|
17
24
|
@raw_source = source
|
18
25
|
@path = path
|
19
26
|
@diagnostics = []
|
@@ -66,7 +73,9 @@ module RuboCop
|
|
66
73
|
end
|
67
74
|
|
68
75
|
def create_parser
|
69
|
-
|
76
|
+
builder = Astrolabe::Builder.new
|
77
|
+
|
78
|
+
Parser::CurrentRuby.new(builder).tap do |parser|
|
70
79
|
# On JRuby and Rubinius, there's a risk that we hang in tokenize() if we
|
71
80
|
# don't set the all errors as fatal flag. The problem is caused by a bug
|
72
81
|
# in Racc that is discussed in issue #93 of the whitequark/parser
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# This module provides approximate string matching methods.
|
5
|
+
module StringUtil
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def similarity(string_a, string_b)
|
9
|
+
JaroWinkler.distance(string_a.to_s, string_b.to_s)
|
10
|
+
end
|
11
|
+
|
12
|
+
# This class computes Jaro distance, which is a measure of similarity
|
13
|
+
# between two strings.
|
14
|
+
class Jaro
|
15
|
+
attr_reader :shorter, :longer
|
16
|
+
|
17
|
+
def self.distance(*args)
|
18
|
+
new(*args).distance
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(a, b)
|
22
|
+
if a.size < b.size
|
23
|
+
@shorter, @longer = a, b
|
24
|
+
else
|
25
|
+
@shorter, @longer = b, a
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def distance
|
30
|
+
@distance ||= compute_distance
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def compute_distance
|
36
|
+
common_chars_a, common_chars_b = find_common_characters
|
37
|
+
matched_count = common_chars_a.size
|
38
|
+
|
39
|
+
return 0.0 if matched_count.zero?
|
40
|
+
|
41
|
+
transposition_count =
|
42
|
+
count_transpositions(common_chars_a, common_chars_b)
|
43
|
+
|
44
|
+
sum = (matched_count / shorter.size.to_f) +
|
45
|
+
(matched_count / longer.size.to_f) +
|
46
|
+
((matched_count - transposition_count / 2) / matched_count.to_f)
|
47
|
+
|
48
|
+
sum / 3.0
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_common_characters
|
52
|
+
common_chars_of_shorter = Array.new(shorter.size)
|
53
|
+
common_chars_of_longer = Array.new(longer.size)
|
54
|
+
|
55
|
+
# In Ruby 1.9 String#chars returns Enumerator rather than Array.
|
56
|
+
longer_chars = longer.each_char.to_a
|
57
|
+
|
58
|
+
shorter.each_char.with_index do |shorter_char, shorter_index|
|
59
|
+
matching_index_range(shorter_index).each do |longer_index|
|
60
|
+
longer_char = longer_chars[longer_index]
|
61
|
+
|
62
|
+
next unless shorter_char == longer_char
|
63
|
+
|
64
|
+
common_chars_of_shorter[shorter_index] = shorter_char
|
65
|
+
common_chars_of_longer[longer_index] = longer_char
|
66
|
+
|
67
|
+
# Mark the matching character as already used
|
68
|
+
longer_chars[longer_index] = nil
|
69
|
+
|
70
|
+
break
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
[common_chars_of_shorter, common_chars_of_longer].map(&:compact)
|
75
|
+
end
|
76
|
+
|
77
|
+
def count_transpositions(common_chars_a, common_chars_b)
|
78
|
+
common_chars_a.size.times.count do |index|
|
79
|
+
common_chars_a[index] != common_chars_b[index]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def matching_index_range(origin)
|
84
|
+
min = origin - matching_window
|
85
|
+
min = 0 if min < 0
|
86
|
+
|
87
|
+
max = origin + matching_window
|
88
|
+
|
89
|
+
min..max
|
90
|
+
end
|
91
|
+
|
92
|
+
def matching_window
|
93
|
+
@matching_window ||= (longer.size / 2).to_i - 1
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# This class computes Jaro-Winkler distance, which adds prefix-matching
|
98
|
+
# bonus to Jaro distance.
|
99
|
+
class JaroWinkler < Jaro
|
100
|
+
# Add the prefix bonus only when the Jaro distance is above this value.
|
101
|
+
# In other words, if the Jaro distance is less than this value,
|
102
|
+
# JaroWinkler.distance returns the raw Jaro distance.
|
103
|
+
DEFAULT_BOOST_THRESHOLD = 0.7
|
104
|
+
|
105
|
+
# How much the prefix bonus is weighted.
|
106
|
+
# This should not exceed 0.25.
|
107
|
+
DEFAULT_SCALING_FACTOR = 0.1
|
108
|
+
|
109
|
+
# Cutoff the common prefix length to this value if it's longer than this.
|
110
|
+
MAX_COMMON_PREFIX_LENGTH = 4
|
111
|
+
|
112
|
+
attr_reader :boost_threshold, :scaling_factor
|
113
|
+
|
114
|
+
def initialize(a, b, boost_threshold = nil, scaling_factor = nil)
|
115
|
+
super(a, b)
|
116
|
+
@boost_threshold = boost_threshold || DEFAULT_BOOST_THRESHOLD
|
117
|
+
@scaling_factor = scaling_factor || DEFAULT_SCALING_FACTOR
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def compute_distance
|
123
|
+
jaro_distance = super
|
124
|
+
|
125
|
+
if jaro_distance >= boost_threshold
|
126
|
+
bonus = limited_common_prefix_length.to_f * scaling_factor.to_f *
|
127
|
+
(1.0 - jaro_distance)
|
128
|
+
jaro_distance + bonus
|
129
|
+
else
|
130
|
+
jaro_distance
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def limited_common_prefix_length
|
135
|
+
length = common_prefix_length
|
136
|
+
|
137
|
+
if length > MAX_COMMON_PREFIX_LENGTH
|
138
|
+
MAX_COMMON_PREFIX_LENGTH
|
139
|
+
else
|
140
|
+
length
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def common_prefix_length
|
145
|
+
shorter.size.times do |index|
|
146
|
+
return index unless shorter[index] == longer[index]
|
147
|
+
end
|
148
|
+
|
149
|
+
shorter.size
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -42,7 +42,7 @@ module RuboCop
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# Finds all Ruby source files under the current or other supplied
|
45
|
-
# directory.
|
45
|
+
# directory. A Ruby source file is defined as a file with the `.rb`
|
46
46
|
# extension or a file with no extension that has a ruby shebang line
|
47
47
|
# as its first line.
|
48
48
|
# It is possible to specify includes and excludes using the config file,
|
data/lib/rubocop/version.rb
CHANGED
data/relnotes/v0.26.0.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
Nothing particularly exciting this time around. The new release comes
|
2
|
+
with lots of bug fixes, more auto-corrections and several new cops.
|
3
|
+
|
4
|
+
Note that the `Style/Encoding` cop is now disabled by default. See
|
5
|
+
[#1304](https://github.com/bbatsov/rubocop/issues/1304) for the
|
6
|
+
rationale behind this change.
|
7
|
+
|
8
|
+
Below is the list of all the gory details. Enjoy!
|
9
|
+
|
10
|
+
### New features
|
11
|
+
|
12
|
+
* New formatter `HTMLFormatter` generates a html file with a list of files with offences in them. ([@SkuliOskarsson][])
|
13
|
+
* New cop `SpaceInsideRangeLiteral` checks for spaces around `..` and `...` in range literals. ([@bbatsov][])
|
14
|
+
* New cop `InfiniteLoop` checks for places where `Kernel#loop` should have been used. ([@bbatsov][])
|
15
|
+
* New cop `SymbolProc` checks for places where a symbol can be used as proc instead of a block. ([@bbatsov][])
|
16
|
+
* `UselessAssignment` cop now suggests a variable name for possible typos if there's a variable-ish identifier similar to the unused variable name in the same scope. ([@yujinakayama][])
|
17
|
+
* `PredicateName` cop now has separate configurations for prefices that denote predicate method names and predicate prefices that should be removed. ([@bbatsov][])
|
18
|
+
* [#1272](https://github.com/bbatsov/rubocop/issues/1272): `Tab` cop does auto-correction. ([@yous][])
|
19
|
+
* [#1274](https://github.com/bbatsov/rubocop/issues/1274): `MultilineIfThen` cop does auto-correction. ([@bbatsov][])
|
20
|
+
* [#1279](https://github.com/bbatsov/rubocop/issues/1279): `DotPosition` cop does auto-correction. ([@yous][])
|
21
|
+
* [#1277](https://github.com/bbatsov/rubocop/issues/1277): `SpaceBeforeFirstArg` cop does auto-correction. ([@yous][])
|
22
|
+
* [#1310](https://github.com/bbatsov/rubocop/issues/1310): Handle `module_function` in `Style/AccessModifierIndentation` and `Style/EmptyLinesAroundAccessModifier`. ([@bbatsov][])
|
23
|
+
|
24
|
+
### Changes
|
25
|
+
|
26
|
+
* [#1289](https://github.com/bbatsov/rubocop/issues/1289): Use utf-8 as default encoding for inspected files. ([@jonas054][])
|
27
|
+
* [#1304](https://github.com/bbatsov/rubocop/issues/1304): `Style/Encoding` is no longer a no-op on Ruby 2.x. It's also disabled by default, as projects not supporting 1.9 don't need to run it. ([@bbatsov][])
|
28
|
+
|
29
|
+
### Bugs fixed
|
30
|
+
|
31
|
+
* [#1263](https://github.com/bbatsov/rubocop/issues/1263): Do not report `%W` literals with special escaped characters in `UnneededCapitalW`. ([@jonas054][])
|
32
|
+
* [#1286](https://github.com/bbatsov/rubocop/issues/1286): Fix a false positive in `VariableName`. ([@bbatsov][])
|
33
|
+
* [#1211](https://github.com/bbatsov/rubocop/issues/1211): Fix false negative in `UselessAssignment` when there's a reference for the variable in an exclusive branch. ([@yujinakayama][])
|
34
|
+
* [#1307](https://github.com/bbatsov/rubocop/issues/1307): Fix auto-correction of `RedundantBegin` cop deletes new line. ([@yous][])
|
35
|
+
* [#1283](https://github.com/bbatsov/rubocop/issues/1283): Fix auto-correction of indented expressions in `PercentLiteralDelimiters`. ([@jonas054][])
|
36
|
+
* [#1315](https://github.com/bbatsov/rubocop/pull/1315): `BracesAroundHashParameters` auto-correction removes whitespace around content inside braces. ([@jspanjers][])
|
37
|
+
* [#1313](https://github.com/bbatsov/rubocop/issues/1313): Fix a false positive in `AndOr` when enforced style is `conditionals`. ([@bbatsov][])
|
38
|
+
* Handle post-conditional `while` and `until` in `AndOr` when enforced style is `conditionals`. ([@yujinakayama][])
|
39
|
+
* [#1319](https://github.com/bbatsov/rubocop/issues/1319): Fix a false positive in `FormatString`. ([@bbatsov][])
|
40
|
+
* [#1287](https://github.com/bbatsov/rubocop/issues/1287): Allow missing blank line for EmptyLinesAroundAccessModifier if next line closes a block. ([@sch1zo][])
|
41
|
+
|
42
|
+
[@bbatsov]: https://github.com/bbatsov
|
43
|
+
[@jonas054]: https://github.com/jonas054
|
44
|
+
[@yujinakayama]: https://github.com/yujinakayama
|
45
|
+
[@dblock]: https://github.com/dblock
|
46
|
+
[@nevir]: https://github.com/nevir
|
47
|
+
[@daviddavis]: https://github.com/daviddavis
|
48
|
+
[@sds]: https://github.com/sds
|
49
|
+
[@fancyremarker]: https://github.com/fancyremarker
|
50
|
+
[@sinisterchipmunk]: https://github.com/sinisterchipmunk
|
51
|
+
[@vonTronje]: https://github.com/vonTronje
|
52
|
+
[@agrimm]: https://github.com/agrimm
|
53
|
+
[@pmenglund]: https://github.com/pmenglund
|
54
|
+
[@chulkilee]: https://github.com/chulkilee
|
55
|
+
[@codez]: https://github.com/codez
|
56
|
+
[@emou]: https://github.com/emou
|
57
|
+
[@skanev]: http://github.com/skanev
|
58
|
+
[@claco]: http://github.com/claco
|
59
|
+
[@rifraf]: http://github.com/rifraf
|
60
|
+
[@scottmatthewman]: https://github.com/scottmatthewman
|
61
|
+
[@ma2gedev]: http://github.com/ma2gedev
|
62
|
+
[@jeremyolliver]: https://github.com/jeremyolliver
|
63
|
+
[@hannestyden]: https://github.com/hannestyden
|
64
|
+
[@geniou]: https://github.com/geniou
|
65
|
+
[@jkogara]: https://github.com/jkogara
|
66
|
+
[@tmorris-fiksu]: https://github.com/tmorris-fiksu
|
67
|
+
[@mockdeep]: https://github.com/mockdeep
|
68
|
+
[@hiroponz]: https://github.com/hiroponz
|
69
|
+
[@tamird]: https://github.com/tamird
|
70
|
+
[@fshowalter]: https://github.com/fshowalter
|
71
|
+
[@cschramm]: https://github.com/cschramm
|
72
|
+
[@bquorning]: https://github.com/bquorning
|
73
|
+
[@bcobb]: https://github.com/bcobb
|
74
|
+
[@irrationalfab]: https://github.com/irrationalfab
|
75
|
+
[@tommeier]: https://github.com/tommeier
|
76
|
+
[@sfeldon]: https://github.com/sfeldon
|
77
|
+
[@biinari]: https://github.com/biinari
|
78
|
+
[@barunio]: https://github.com/barunio
|
79
|
+
[@molawson]: https://github.com/molawson
|
80
|
+
[@wndhydrnt]: https://github.com/wndhydrnt
|
81
|
+
[@ggilder]: https://github.com/ggilder
|
82
|
+
[@salbertson]: https://github.com/salbertson
|
83
|
+
[@camilleldn]: https://github.com/camilleldn
|
84
|
+
[@mcls]: https://github.com/mcls
|
85
|
+
[@yous]: https://github.com/yous
|
86
|
+
[@vrthra]: https://github.com/vrthra
|
87
|
+
[@SkuliOskarsson]: https://github.com/SkuliOskarsson
|
88
|
+
[@jspanjers]: https://github.com/jspanjers
|
89
|
+
[@sch1zo]: https://github.com/sch1zo
|
data/rubocop.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.add_runtime_dependency('rainbow', '>= 1.99.1', '< 3.0')
|
30
30
|
s.add_runtime_dependency('parser', '>= 2.2.0.pre.4', '< 3.0')
|
31
31
|
s.add_runtime_dependency('powerpack', '~> 0.0.6')
|
32
|
+
s.add_runtime_dependency('astrolabe', '~> 1.3')
|
32
33
|
s.add_runtime_dependency('ruby-progressbar', '~> 1.4')
|
33
34
|
s.add_development_dependency('rake', '~> 10.1')
|
34
35
|
s.add_development_dependency('rspec', '~> 3.0')
|
data/spec/rubocop/cli_spec.rb
CHANGED
@@ -103,7 +103,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
103
103
|
' }',
|
104
104
|
' ]',
|
105
105
|
' end',
|
106
|
-
'end'
|
106
|
+
'end',
|
107
|
+
''].join("\n"))
|
107
108
|
end
|
108
109
|
|
109
110
|
it 'can change block comments and indent them' do
|
@@ -132,7 +133,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
132
133
|
' do_something',
|
133
134
|
' end',
|
134
135
|
' end',
|
135
|
-
'end'
|
136
|
+
'end',
|
137
|
+
''].join("\n"))
|
136
138
|
end
|
137
139
|
|
138
140
|
it 'can correct two problems with blocks' do
|
@@ -146,7 +148,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
146
148
|
.to eq(['# encoding: utf-8',
|
147
149
|
'(1..10).each do |i|',
|
148
150
|
' puts i',
|
149
|
-
'end'
|
151
|
+
'end',
|
152
|
+
''].join("\n"))
|
150
153
|
end
|
151
154
|
|
152
155
|
it 'can handle spaces when removing braces' do
|
@@ -188,7 +191,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
188
191
|
expect(IO.read('example.rb')).to eq(['class Test',
|
189
192
|
' def f',
|
190
193
|
' end',
|
191
|
-
'end'
|
194
|
+
'end',
|
195
|
+
''].join("\n"))
|
192
196
|
end
|
193
197
|
|
194
198
|
# A case where WordArray's correction can be clobbered by
|
@@ -205,7 +209,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
205
209
|
' private',
|
206
210
|
'',
|
207
211
|
' A = %w(git path)',
|
208
|
-
'end'
|
212
|
+
'end',
|
213
|
+
''].join("\n"))
|
209
214
|
e = abs('example.rb')
|
210
215
|
expect($stdout.string)
|
211
216
|
.to eq(["#{e}:2:1: C: Missing top-level class documentation " \
|
@@ -248,7 +253,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
248
253
|
'end end'])
|
249
254
|
expect(cli.run(['--auto-correct'])).to eq(1)
|
250
255
|
expect(IO.read('example.rb')).to eq(['module A module B',
|
251
|
-
'end end'
|
256
|
+
'end end',
|
257
|
+
''].join("\n"))
|
252
258
|
end
|
253
259
|
|
254
260
|
it 'can correct single line methods' do
|
@@ -291,8 +297,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
291
297
|
expect(IO.read('example.rb'))
|
292
298
|
.to eq(['# encoding: utf-8',
|
293
299
|
'fail NotImplementedError,',
|
294
|
-
" 'Method should be overridden in child classes'"
|
295
|
-
|
300
|
+
" 'Method should be overridden in child classes'",
|
301
|
+
''].join("\n"))
|
296
302
|
expect($stdout.string)
|
297
303
|
.to eq(['Inspecting 1 file',
|
298
304
|
'C',
|
@@ -331,7 +337,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
331
337
|
'class Klass',
|
332
338
|
' def f',
|
333
339
|
' end',
|
334
|
-
'end'
|
340
|
+
'end',
|
341
|
+
''].join("\n"))
|
335
342
|
expect($stderr.string).to eq('')
|
336
343
|
expect($stdout.string)
|
337
344
|
.to eq(['Inspecting 1 file',
|
@@ -361,7 +368,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
361
368
|
.to eq(['# encoding: utf-8',
|
362
369
|
'def primes(limit)',
|
363
370
|
' 1.upto(limit).select { |i| is_prime[i] }',
|
364
|
-
'end'
|
371
|
+
'end',
|
372
|
+
''].join("\n"))
|
365
373
|
expect($stdout.string)
|
366
374
|
.to eq(['Inspecting 1 file',
|
367
375
|
'C',
|
@@ -462,7 +470,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
462
470
|
'',
|
463
471
|
''])
|
464
472
|
expect(cli.run(%w(--auto-correct --format emacs))).to eq(1)
|
465
|
-
expect(IO.read('example.rb')).to eq(
|
473
|
+
expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
|
474
|
+
''].join("\n"))
|
466
475
|
expect($stdout.string)
|
467
476
|
.to eq(["#{abs('example.rb')}:2:1: C: [Corrected] 3 trailing " \
|
468
477
|
'blank lines detected.',
|
@@ -609,8 +618,9 @@ describe RuboCop::CLI, :isolated_environment do
|
|
609
618
|
expect { cli.run(['--auto-gen-config', 'example1.rb']) }
|
610
619
|
.to exit_with_code(1)
|
611
620
|
expect($stderr.string)
|
612
|
-
.to eq('--auto-gen-config can not be combined with any other ' \
|
613
|
-
|
621
|
+
.to eq(['--auto-gen-config can not be combined with any other ' \
|
622
|
+
'arguments.',
|
623
|
+
''].join("\n"))
|
614
624
|
expect($stdout.string).to eq('')
|
615
625
|
end
|
616
626
|
|
@@ -667,6 +677,7 @@ describe RuboCop::CLI, :isolated_environment do
|
|
667
677
|
' Enabled: false',
|
668
678
|
'',
|
669
679
|
'# Offense count: 1',
|
680
|
+
'# Cop supports --auto-correct.',
|
670
681
|
'Style/Tab:',
|
671
682
|
' Enabled: false',
|
672
683
|
'',
|
@@ -713,6 +724,7 @@ describe RuboCop::CLI, :isolated_environment do
|
|
713
724
|
' Enabled: false',
|
714
725
|
'',
|
715
726
|
'# Offense count: 1',
|
727
|
+
'# Cop supports --auto-correct.',
|
716
728
|
'Style/Tab:',
|
717
729
|
' Enabled: false']
|
718
730
|
actual = IO.read('.rubocop_todo.yml').split($RS)
|
@@ -1041,7 +1053,7 @@ describe RuboCop::CLI, :isolated_environment do
|
|
1041
1053
|
lines = stdout.lines
|
1042
1054
|
lines.slice_before(/Type /).each do |slice|
|
1043
1055
|
types = cops.types.map(&:to_s).map(&:capitalize)
|
1044
|
-
current = types.delete(slice.shift[/Type '(?<c>[^'
|
1056
|
+
current = types.delete(slice.shift[/Type '(?<c>[^']+)'/, 'c'])
|
1045
1057
|
# all cops in their type listing
|
1046
1058
|
cops.with_type(current).each do |cop|
|
1047
1059
|
expect(slice.any? { |l| l.include? cop.cop_name }).to be_truthy
|
@@ -1063,11 +1075,15 @@ describe RuboCop::CLI, :isolated_environment do
|
|
1063
1075
|
let(:cop_list) { ['Style/Tab'] }
|
1064
1076
|
|
1065
1077
|
it 'prints that cop and nothing else' do
|
1066
|
-
expect(stdout).to eq(
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1078
|
+
expect(stdout).to eq(
|
1079
|
+
['# Supports --auto-correct',
|
1080
|
+
'Style/Tab:',
|
1081
|
+
' Description: No hard tabs.',
|
1082
|
+
' StyleGuide: ' \
|
1083
|
+
'https://github.com/bbatsov/ruby-style-guide#spaces-indentation',
|
1084
|
+
' Enabled: true',
|
1085
|
+
'',
|
1086
|
+
''].join("\n"))
|
1071
1087
|
end
|
1072
1088
|
|
1073
1089
|
include_examples :prints_config
|
@@ -1082,11 +1098,15 @@ describe RuboCop::CLI, :isolated_environment do
|
|
1082
1098
|
let(:cop_list) { ['Style/Tab,Lint/X123'] }
|
1083
1099
|
|
1084
1100
|
it 'skips the unknown cop' do
|
1085
|
-
expect(stdout).to eq(
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1101
|
+
expect(stdout).to eq(
|
1102
|
+
['# Supports --auto-correct',
|
1103
|
+
'Style/Tab:',
|
1104
|
+
' Description: No hard tabs.',
|
1105
|
+
' StyleGuide: ' \
|
1106
|
+
'https://github.com/bbatsov/ruby-style-guide#spaces-indentation',
|
1107
|
+
' Enabled: true',
|
1108
|
+
'',
|
1109
|
+
''].join("\n"))
|
1090
1110
|
end
|
1091
1111
|
end
|
1092
1112
|
end
|
@@ -1297,7 +1317,8 @@ describe RuboCop::CLI, :isolated_environment do
|
|
1297
1317
|
''].join("\n"))
|
1298
1318
|
|
1299
1319
|
expect(File.read('emacs_output.txt'))
|
1300
|
-
.to eq("#{abs(target_file)}:2:81: C: Line is too long. [90/80]
|
1320
|
+
.to eq(["#{abs(target_file)}:2:81: C: Line is too long. [90/80]",
|
1321
|
+
''].join("\n"))
|
1301
1322
|
end
|
1302
1323
|
end
|
1303
1324
|
|
@@ -1398,7 +1419,9 @@ describe RuboCop::CLI, :isolated_environment do
|
|
1398
1419
|
'puts x'])
|
1399
1420
|
expect(cli.run(['--format', 'simple', 'example.rb'])).to eq(0)
|
1400
1421
|
expect($stdout.string)
|
1401
|
-
.to eq(
|
1422
|
+
.to eq(['',
|
1423
|
+
'1 file inspected, no offenses detected',
|
1424
|
+
''].join("\n"))
|
1402
1425
|
end
|
1403
1426
|
|
1404
1427
|
it 'checks a given file with faults and returns 1' do
|
@@ -1509,8 +1532,9 @@ describe RuboCop::CLI, :isolated_environment do
|
|
1509
1532
|
'end'])
|
1510
1533
|
expect(cli.run(['--format', 'emacs', 'example.rb'])).to eq(1)
|
1511
1534
|
expect($stderr.string)
|
1512
|
-
.to eq("#{abs('example.rb')}: Style/LineLength has the wrong " \
|
1513
|
-
|
1535
|
+
.to eq(["#{abs('example.rb')}: Style/LineLength has the wrong " \
|
1536
|
+
'namespace - should be Metrics',
|
1537
|
+
''].join("\n"))
|
1514
1538
|
# 3 cops were disabled, then 2 were enabled again, so we
|
1515
1539
|
# should get 2 offenses reported.
|
1516
1540
|
expect($stdout.string)
|
@@ -1890,7 +1914,7 @@ describe RuboCop::CLI, :isolated_environment do
|
|
1890
1914
|
'special case' do
|
1891
1915
|
create_file('example1.rb',
|
1892
1916
|
['# encoding: utf-8',
|
1893
|
-
'arr.select { |e| e > 0 }.collect { |e|
|
1917
|
+
'arr.select { |e| e > 0 }.collect { |e| e * 2 }',
|
1894
1918
|
'a2.find_all { |e| e > 0 }'])
|
1895
1919
|
# We prefer find_all over select. This setting overrides the default
|
1896
1920
|
# select over find_all. Other preferred methods appearing in the default
|
@@ -2193,9 +2217,10 @@ describe RuboCop::CLI, :isolated_environment do
|
|
2193
2217
|
|
2194
2218
|
cli.run(%w(--format simple -c rubocop.yml))
|
2195
2219
|
expect($stderr.string)
|
2196
|
-
.to eq("Warning: Invalid severity 'superbad'. " \
|
2197
|
-
|
2198
|
-
|
2220
|
+
.to eq(["Warning: Invalid severity 'superbad'. " \
|
2221
|
+
'Valid severities are refactor, convention, ' \
|
2222
|
+
'warning, error, fatal.',
|
2223
|
+
''].join("\n"))
|
2199
2224
|
end
|
2200
2225
|
|
2201
2226
|
context 'when a file inherits from the old auto generated file' do
|
@@ -2212,8 +2237,9 @@ describe RuboCop::CLI, :isolated_environment do
|
|
2212
2237
|
expect { cli.run(%w(-c .rubocop.yml --auto-gen-config)) }
|
2213
2238
|
.to exit_with_code(1)
|
2214
2239
|
expect($stderr.string)
|
2215
|
-
.to eq('Attention: rubocop-todo.yml has been renamed to ' \
|
2216
|
-
|
2240
|
+
.to eq(['Attention: rubocop-todo.yml has been renamed to ' \
|
2241
|
+
'.rubocop_todo.yml',
|
2242
|
+
''].join("\n"))
|
2217
2243
|
end
|
2218
2244
|
end
|
2219
2245
|
end
|