rubocop 0.28.0 → 0.29.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_todo.yml +7 -7
- data/.travis.yml +4 -0
- data/CHANGELOG.md +59 -0
- data/README.md +62 -28
- data/config/default.yml +31 -0
- data/config/disabled.yml +1 -1
- data/config/enabled.yml +17 -0
- data/lib/rubocop.rb +4 -0
- data/lib/rubocop/cli.rb +1 -1
- data/lib/rubocop/config.rb +12 -8
- data/lib/rubocop/config_loader.rb +20 -10
- data/lib/rubocop/cop/cop.rb +13 -7
- data/lib/rubocop/cop/corrector.rb +10 -10
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +6 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +9 -2
- data/lib/rubocop/cop/lint/debugger.rb +13 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +104 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/require_parentheses.rb +3 -3
- data/lib/rubocop/cop/mixin/access_modifier_node.rb +27 -0
- data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +0 -4
- data/lib/rubocop/cop/rails/delegate.rb +4 -5
- data/lib/rubocop/cop/rails/read_write_attribute.rb +33 -0
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +0 -7
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +4 -2
- data/lib/rubocop/cop/style/class_methods.rb +25 -9
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +7 -1
- data/lib/rubocop/cop/style/empty_literal.rb +25 -10
- data/lib/rubocop/cop/style/even_odd.rb +32 -14
- data/lib/rubocop/cop/style/first_parameter_indentation.rb +106 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -2
- data/lib/rubocop/cop/style/global_vars.rb +1 -5
- data/lib/rubocop/cop/style/hash_syntax.rb +0 -4
- data/lib/rubocop/cop/style/indentation_consistency.rb +5 -5
- data/lib/rubocop/cop/style/indentation_width.rb +13 -14
- data/lib/rubocop/cop/style/lambda.rb +48 -2
- data/lib/rubocop/cop/style/line_end_concatenation.rb +43 -47
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +3 -3
- data/lib/rubocop/cop/style/module_function.rb +3 -3
- data/lib/rubocop/cop/style/multiline_block_layout.rb +65 -17
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +2 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
- data/lib/rubocop/cop/style/redundant_exception.rb +12 -0
- data/lib/rubocop/cop/style/self_assignment.rb +27 -0
- data/lib/rubocop/cop/style/semicolon.rb +2 -1
- data/lib/rubocop/cop/style/space_around_block_parameters.rb +92 -0
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +0 -8
- data/lib/rubocop/cop/style/struct_inheritance.rb +42 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +10 -4
- data/lib/rubocop/cop/util.rb +32 -7
- data/lib/rubocop/formatter/simple_text_formatter.rb +0 -15
- data/lib/rubocop/options.rb +28 -41
- data/lib/rubocop/processed_source.rb +6 -0
- data/lib/rubocop/rake_task.rb +6 -3
- data/lib/rubocop/runner.rb +55 -15
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.29.0.md +116 -0
- data/rubocop.gemspec +3 -3
- data/spec/rubocop/cli_spec.rb +329 -25
- data/spec/rubocop/config_loader_spec.rb +20 -0
- data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +27 -3
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +3 -4
- data/spec/rubocop/cop/lint/condition_position_spec.rb +1 -1
- data/spec/rubocop/cop/lint/debugger_spec.rb +20 -7
- data/spec/rubocop/cop/lint/duplicate_methods_spec.rb +189 -0
- data/spec/rubocop/cop/lint/empty_interpolation_spec.rb +1 -1
- data/spec/rubocop/cop/lint/end_in_method_spec.rb +1 -1
- data/spec/rubocop/cop/lint/eval_spec.rb +4 -4
- data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +18 -0
- data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +2 -2
- data/spec/rubocop/cop/lint/loop_spec.rb +4 -4
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +7 -7
- data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +5 -4
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +3 -9
- data/spec/rubocop/cop/lint/useless_comparison_spec.rb +1 -1
- data/spec/rubocop/cop/lint/void_spec.rb +1 -1
- data/spec/rubocop/cop/metrics/abc_size_spec.rb +10 -0
- data/spec/rubocop/cop/metrics/line_length_spec.rb +2 -2
- data/spec/rubocop/cop/metrics/parameter_lists_spec.rb +2 -2
- data/spec/rubocop/cop/rails/action_filter_spec.rb +6 -12
- data/spec/rubocop/cop/rails/default_scope_spec.rb +5 -5
- data/spec/rubocop/cop/rails/delegate_spec.rb +8 -0
- data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +1 -1
- data/spec/rubocop/cop/rails/read_write_attribute_spec.rb +119 -8
- data/spec/rubocop/cop/rails/scope_args_spec.rb +3 -3
- data/spec/rubocop/cop/rails/validation_spec.rb +3 -3
- data/spec/rubocop/cop/style/alias_spec.rb +5 -5
- data/spec/rubocop/cop/style/align_hash_spec.rb +1 -1
- data/spec/rubocop/cop/style/align_parameters_spec.rb +8 -8
- data/spec/rubocop/cop/style/and_or_spec.rb +15 -30
- data/spec/rubocop/cop/style/array_join_spec.rb +4 -4
- data/spec/rubocop/cop/style/ascii_comments_spec.rb +1 -2
- data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +2 -2
- data/spec/rubocop/cop/style/begin_block_spec.rb +1 -1
- data/spec/rubocop/cop/style/block_comments_spec.rb +1 -1
- data/spec/rubocop/cop/style/block_end_newline_spec.rb +1 -1
- data/spec/rubocop/cop/style/blocks_spec.rb +2 -2
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +38 -33
- data/spec/rubocop/cop/style/case_equality_spec.rb +1 -1
- data/spec/rubocop/cop/style/character_literal_spec.rb +4 -4
- data/spec/rubocop/cop/style/class_and_module_children_spec.rb +4 -2
- data/spec/rubocop/cop/style/class_methods_spec.rb +12 -0
- data/spec/rubocop/cop/style/class_vars_spec.rb +2 -2
- data/spec/rubocop/cop/style/collection_methods_spec.rb +4 -4
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +8 -8
- data/spec/rubocop/cop/style/comment_annotation_spec.rb +10 -10
- data/spec/rubocop/cop/style/constant_name_spec.rb +7 -7
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/deprecated_hash_methods_spec.rb +4 -4
- data/spec/rubocop/cop/style/dot_position_spec.rb +8 -6
- data/spec/rubocop/cop/style/each_with_object_spec.rb +2 -2
- data/spec/rubocop/cop/style/else_alignment_spec.rb +2 -4
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +78 -0
- data/spec/rubocop/cop/style/empty_lines_around_class_body_spec.rb +60 -0
- data/spec/rubocop/cop/style/empty_lines_spec.rb +3 -3
- data/spec/rubocop/cop/style/empty_literal_spec.rb +29 -12
- data/spec/rubocop/cop/style/encoding_spec.rb +3 -3
- data/spec/rubocop/cop/style/end_block_spec.rb +1 -1
- data/spec/rubocop/cop/style/end_of_line_spec.rb +2 -2
- data/spec/rubocop/cop/style/even_odd_spec.rb +109 -20
- data/spec/rubocop/cop/style/extra_spacing_spec.rb +3 -3
- data/spec/rubocop/cop/style/first_parameter_indentation_spec.rb +293 -0
- data/spec/rubocop/cop/style/for_spec.rb +2 -2
- data/spec/rubocop/cop/style/format_string_spec.rb +45 -21
- data/spec/rubocop/cop/style/global_vars_spec.rb +4 -4
- data/spec/rubocop/cop/style/guard_clause_spec.rb +17 -0
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +15 -15
- data/spec/rubocop/cop/{metrics → style}/if_unless_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +2 -2
- data/spec/rubocop/cop/style/indent_array_spec.rb +3 -6
- data/spec/rubocop/cop/style/indent_hash_spec.rb +4 -4
- data/spec/rubocop/cop/style/indentation_consistency_spec.rb +1 -2
- data/spec/rubocop/cop/style/indentation_width_spec.rb +1 -2
- data/spec/rubocop/cop/style/infinite_loop_spec.rb +1 -1
- data/spec/rubocop/cop/style/lambda_call_spec.rb +4 -4
- data/spec/rubocop/cop/style/lambda_spec.rb +37 -2
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +7 -12
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +41 -1
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +4 -4
- data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +3 -3
- data/spec/rubocop/cop/style/method_name_spec.rb +1 -1
- data/spec/rubocop/cop/style/multiline_block_layout_spec.rb +61 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +1 -3
- data/spec/rubocop/cop/style/multiline_operation_indentation_spec.rb +8 -0
- data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +1 -1
- data/spec/rubocop/cop/style/nested_ternary_operator_spec.rb +1 -1
- data/spec/rubocop/cop/style/next_spec.rb +16 -0
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +5 -5
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +1 -1
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +22 -4
- data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +31 -31
- data/spec/rubocop/cop/style/percent_q_literals_spec.rb +12 -12
- data/spec/rubocop/cop/style/perl_backrefs_spec.rb +3 -3
- data/spec/rubocop/cop/style/proc_spec.rb +3 -3
- data/spec/rubocop/cop/style/raise_args_spec.rb +9 -9
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +1 -1
- data/spec/rubocop/cop/style/redundant_exception_spec.rb +36 -4
- data/spec/rubocop/cop/style/redundant_self_spec.rb +89 -45
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +9 -9
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/style/self_assignment_spec.rb +16 -10
- data/spec/rubocop/cop/style/semicolon_spec.rb +9 -9
- data/spec/rubocop/cop/style/single_line_block_params_spec.rb +2 -2
- data/spec/rubocop/cop/style/single_space_before_first_arg_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +5 -5
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_after_not_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_around_block_parameters_spec.rb +150 -0
- data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +18 -9
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +24 -21
- data/spec/rubocop/cop/style/space_before_block_braces_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_before_comma_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_before_comment_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_before_semicolon_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +33 -24
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +9 -9
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +1 -1
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +6 -6
- data/spec/rubocop/cop/style/string_literals_in_interpolation_spec.rb +3 -3
- data/spec/rubocop/cop/style/string_literals_spec.rb +16 -16
- data/spec/rubocop/cop/style/struct_inheritance_spec.rb +44 -0
- data/spec/rubocop/cop/style/symbol_array_spec.rb +9 -9
- data/spec/rubocop/cop/style/symbol_proc_spec.rb +12 -12
- data/spec/rubocop/cop/style/tab_spec.rb +4 -4
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +2 -2
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +2 -2
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +16 -0
- data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +11 -22
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +7 -7
- data/spec/rubocop/cop/style/while_until_do_spec.rb +2 -2
- data/spec/rubocop/cop/{metrics → style}/while_until_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/style/word_array_spec.rb +11 -11
- data/spec/rubocop/cop/util_spec.rb +51 -0
- data/spec/rubocop/cop/variable_force/reference_spec.rb +19 -0
- data/spec/rubocop/cop/variable_force/variable_table_spec.rb +7 -0
- data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +7 -8
- data/spec/rubocop/formatter/text_util_spec.rb +55 -0
- data/spec/rubocop/options_spec.rb +26 -20
- data/spec/rubocop/rake_task_spec.rb +122 -0
- data/spec/rubocop/runner_spec.rb +37 -2
- data/spec/rubocop/token_spec.rb +5 -1
- data/spec/spec_helper.rb +5 -2
- data/spec/support/cop_helper.rb +3 -0
- data/spec/support/cops/class_must_be_a_module_cop.rb +19 -0
- data/spec/support/cops/module_must_be_a_class_cop.rb +19 -0
- data/spec/support/custom_matchers.rb +1 -1
- metadata +35 -12
@@ -7,19 +7,19 @@ describe RuboCop::Cop::Rails::ScopeArgs do
|
|
7
7
|
|
8
8
|
it 'registers an offense a scope with a method arg' do
|
9
9
|
inspect_source(cop,
|
10
|
-
|
10
|
+
'scope :active, where(active: true)')
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'accepts a lambda arg' do
|
15
15
|
inspect_source(cop,
|
16
|
-
|
16
|
+
'scope :active, -> { where(active: true) }')
|
17
17
|
expect(cop.offenses).to be_empty
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'accepts a proc arg' do
|
21
21
|
inspect_source(cop,
|
22
|
-
|
22
|
+
'scope :active, proc { where(active: true) }')
|
23
23
|
expect(cop.offenses).to be_empty
|
24
24
|
end
|
25
25
|
end
|
@@ -8,13 +8,13 @@ describe RuboCop::Cop::Rails::Validation do
|
|
8
8
|
described_class::BLACKLIST.each_with_index do |validation, number|
|
9
9
|
it "registers an offense for #{validation}" do
|
10
10
|
inspect_source(cop,
|
11
|
-
|
11
|
+
"#{validation} :name")
|
12
12
|
expect(cop.offenses.size).to eq(1)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "outputs the correct message for #{validation}" do
|
16
16
|
inspect_source(cop,
|
17
|
-
|
17
|
+
"#{validation} :name")
|
18
18
|
expect(cop.offenses.first.message)
|
19
19
|
.to include(described_class::WHITELIST[number])
|
20
20
|
end
|
@@ -22,7 +22,7 @@ describe RuboCop::Cop::Rails::Validation do
|
|
22
22
|
|
23
23
|
it 'accepts new style validations' do
|
24
24
|
inspect_source(cop,
|
25
|
-
|
25
|
+
'validates :name')
|
26
26
|
expect(cop.offenses).to be_empty
|
27
27
|
end
|
28
28
|
end
|
@@ -7,7 +7,7 @@ describe RuboCop::Cop::Style::Alias do
|
|
7
7
|
|
8
8
|
it 'registers an offense for alias with symbol args' do
|
9
9
|
inspect_source(cop,
|
10
|
-
|
10
|
+
'alias :ala :bala')
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
expect(cop.messages)
|
13
13
|
.to eq(['Use `alias_method` instead of `alias`.'])
|
@@ -20,7 +20,7 @@ describe RuboCop::Cop::Style::Alias do
|
|
20
20
|
|
21
21
|
it 'registers an offense for alias with bareword args' do
|
22
22
|
inspect_source(cop,
|
23
|
-
|
23
|
+
'alias ala bala')
|
24
24
|
expect(cop.offenses.size).to eq(1)
|
25
25
|
expect(cop.messages)
|
26
26
|
.to eq(['Use `alias_method` instead of `alias`.'])
|
@@ -33,19 +33,19 @@ describe RuboCop::Cop::Style::Alias do
|
|
33
33
|
|
34
34
|
it 'does not register an offense for alias_method' do
|
35
35
|
inspect_source(cop,
|
36
|
-
|
36
|
+
'alias_method :ala, :bala')
|
37
37
|
expect(cop.offenses).to be_empty
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'does not register an offense for :alias' do
|
41
41
|
inspect_source(cop,
|
42
|
-
|
42
|
+
'[:alias, :ala, :bala]')
|
43
43
|
expect(cop.offenses).to be_empty
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'does not register an offense for alias with gvars' do
|
47
47
|
inspect_source(cop,
|
48
|
-
|
48
|
+
'alias $ala $bala')
|
49
49
|
expect(cop.offenses).to be_empty
|
50
50
|
end
|
51
51
|
|
@@ -296,7 +296,7 @@ describe RuboCop::Cop::Style::AlignHash, :config do
|
|
296
296
|
end
|
297
297
|
|
298
298
|
it 'accepts a single method argument entry with colon' do
|
299
|
-
inspect_source(cop,
|
299
|
+
inspect_source(cop, 'merge(parent: nil)')
|
300
300
|
expect(cop.offenses).to be_empty
|
301
301
|
end
|
302
302
|
end
|
@@ -47,7 +47,7 @@ describe RuboCop::Cop::Style::AlignParameters do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'accepts calls that only span one line' do
|
50
|
-
inspect_source(cop,
|
50
|
+
inspect_source(cop, 'find(path, s, @special[sexp[0]])')
|
51
51
|
expect(cop.offenses).to be_empty
|
52
52
|
end
|
53
53
|
|
@@ -100,12 +100,12 @@ describe RuboCop::Cop::Style::AlignParameters do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
it "doesn't get confused by symbols with embedded expressions" do
|
103
|
-
inspect_source(cop,
|
103
|
+
inspect_source(cop, 'send(:"#{name}_comments_path")')
|
104
104
|
expect(cop.offenses).to be_empty
|
105
105
|
end
|
106
106
|
|
107
107
|
it "doesn't get confused by regexen with embedded expressions" do
|
108
|
-
inspect_source(cop,
|
108
|
+
inspect_source(cop, 'a(/#{name}/)')
|
109
109
|
expect(cop.offenses).to be_empty
|
110
110
|
end
|
111
111
|
|
@@ -142,7 +142,7 @@ describe RuboCop::Cop::Style::AlignParameters do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'can handle a call embedded in a string' do
|
145
|
-
inspect_source(cop,
|
145
|
+
inspect_source(cop, 'model("#{index(name)}", child)')
|
146
146
|
expect(cop.offenses).to be_empty
|
147
147
|
end
|
148
148
|
|
@@ -163,12 +163,12 @@ describe RuboCop::Cop::Style::AlignParameters do
|
|
163
163
|
end
|
164
164
|
|
165
165
|
it 'can handle a ternary condition with a block reference' do
|
166
|
-
inspect_source(cop,
|
166
|
+
inspect_source(cop, 'cond ? a : func(&b)')
|
167
167
|
expect(cop.offenses).to be_empty
|
168
168
|
end
|
169
169
|
|
170
170
|
it 'can handle parentheses used with no parameters' do
|
171
|
-
inspect_source(cop,
|
171
|
+
inspect_source(cop, 'func()')
|
172
172
|
expect(cop.offenses).to be_empty
|
173
173
|
end
|
174
174
|
|
@@ -180,12 +180,12 @@ describe RuboCop::Cop::Style::AlignParameters do
|
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'can handle method calls without parentheses' do
|
183
|
-
inspect_source(cop,
|
183
|
+
inspect_source(cop, 'a(b c, d)')
|
184
184
|
expect(cop.offenses).to be_empty
|
185
185
|
end
|
186
186
|
|
187
187
|
it 'can handle other method calls without parentheses' do
|
188
|
-
src =
|
188
|
+
src = 'chars(Unicode.apply_mapping @wrapped_string, :uppercase)'
|
189
189
|
inspect_source(cop, src)
|
190
190
|
expect(cop.offenses).to be_empty
|
191
191
|
end
|
@@ -13,8 +13,7 @@ describe RuboCop::Cop::Style::AndOr, :config do
|
|
13
13
|
|
14
14
|
%w(and or).each do |operator|
|
15
15
|
it "accepts \"#{operator}\" outside of conditional" do
|
16
|
-
inspect_source(cop,
|
17
|
-
["x = a + b #{operator} return x"])
|
16
|
+
inspect_source(cop, "x = a + b #{operator} return x")
|
18
17
|
expect(cop.offenses).to be_empty
|
19
18
|
end
|
20
19
|
|
@@ -51,14 +50,12 @@ describe RuboCop::Cop::Style::AndOr, :config do
|
|
51
50
|
|
52
51
|
%w(&& ||).each do |operator|
|
53
52
|
it "accepts #{operator} inside of conditional" do
|
54
|
-
inspect_source(cop,
|
55
|
-
["test if a #{operator} b"])
|
53
|
+
inspect_source(cop, "test if a #{operator} b")
|
56
54
|
expect(cop.offenses).to be_empty
|
57
55
|
end
|
58
56
|
|
59
57
|
it "accepts #{operator} outside of conditional" do
|
60
|
-
inspect_source(cop,
|
61
|
-
["x = a #{operator} b"])
|
58
|
+
inspect_source(cop, "x = a #{operator} b")
|
62
59
|
expect(cop.offenses).to be_empty
|
63
60
|
end
|
64
61
|
end
|
@@ -73,28 +70,24 @@ describe RuboCop::Cop::Style::AndOr, :config do
|
|
73
70
|
let(:cop_config) { cop_config }
|
74
71
|
|
75
72
|
it 'registers an offense for "or"' do
|
76
|
-
inspect_source(cop,
|
77
|
-
['test if a or b'])
|
73
|
+
inspect_source(cop, 'test if a or b')
|
78
74
|
expect(cop.offenses.size).to eq(1)
|
79
75
|
expect(cop.messages).to eq(['Use `||` instead of `or`.'])
|
80
76
|
end
|
81
77
|
|
82
78
|
it 'registers an offense for "and"' do
|
83
|
-
inspect_source(cop,
|
84
|
-
['test if a and b'])
|
79
|
+
inspect_source(cop, 'test if a and b')
|
85
80
|
expect(cop.offenses.size).to eq(1)
|
86
81
|
expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
|
87
82
|
end
|
88
83
|
|
89
84
|
it 'accepts ||' do
|
90
|
-
inspect_source(cop,
|
91
|
-
['test if a || b'])
|
85
|
+
inspect_source(cop, 'test if a || b')
|
92
86
|
expect(cop.offenses).to be_empty
|
93
87
|
end
|
94
88
|
|
95
89
|
it 'accepts &&' do
|
96
|
-
inspect_source(cop,
|
97
|
-
['test if a && b'])
|
90
|
+
inspect_source(cop, 'test if a && b')
|
98
91
|
expect(cop.offenses).to be_empty
|
99
92
|
end
|
100
93
|
|
@@ -132,57 +125,49 @@ describe RuboCop::Cop::Style::AndOr, :config do
|
|
132
125
|
end
|
133
126
|
|
134
127
|
it 'warns on short-circuit (and)' do
|
135
|
-
inspect_source(cop,
|
136
|
-
['x = a + b and return x'])
|
128
|
+
inspect_source(cop, 'x = a + b and return x')
|
137
129
|
expect(cop.offenses.size).to eq(1)
|
138
130
|
expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
|
139
131
|
end
|
140
132
|
|
141
133
|
it 'also warns on non short-circuit (and)' do
|
142
|
-
inspect_source(cop,
|
143
|
-
['x = a + b if a and b'])
|
134
|
+
inspect_source(cop, 'x = a + b if a and b')
|
144
135
|
expect(cop.offenses.size).to eq(1)
|
145
136
|
expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
|
146
137
|
end
|
147
138
|
|
148
139
|
it 'also warns on non short-circuit (and) (unless)' do
|
149
|
-
inspect_source(cop,
|
150
|
-
['x = a + b unless a and b'])
|
140
|
+
inspect_source(cop, 'x = a + b unless a and b')
|
151
141
|
expect(cop.offenses.size).to eq(1)
|
152
142
|
expect(cop.messages).to eq(['Use `&&` instead of `and`.'])
|
153
143
|
end
|
154
144
|
|
155
145
|
it 'warns on short-circuit (or)' do
|
156
|
-
inspect_source(cop,
|
157
|
-
['x = a + b or return x'])
|
146
|
+
inspect_source(cop, 'x = a + b or return x')
|
158
147
|
expect(cop.offenses.size).to eq(1)
|
159
148
|
expect(cop.messages).to eq(['Use `||` instead of `or`.'])
|
160
149
|
end
|
161
150
|
|
162
151
|
it 'also warns on non short-circuit (or)' do
|
163
|
-
inspect_source(cop,
|
164
|
-
['x = a + b if a or b'])
|
152
|
+
inspect_source(cop, 'x = a + b if a or b')
|
165
153
|
expect(cop.offenses.size).to eq(1)
|
166
154
|
expect(cop.messages).to eq(['Use `||` instead of `or`.'])
|
167
155
|
end
|
168
156
|
|
169
157
|
it 'also warns on non short-circuit (or) (unless)' do
|
170
|
-
inspect_source(cop,
|
171
|
-
['x = a + b unless a or b'])
|
158
|
+
inspect_source(cop, 'x = a + b unless a or b')
|
172
159
|
expect(cop.offenses.size).to eq(1)
|
173
160
|
expect(cop.messages).to eq(['Use `||` instead of `or`.'])
|
174
161
|
end
|
175
162
|
|
176
163
|
it 'also warns on while (or)' do
|
177
|
-
inspect_source(cop,
|
178
|
-
['x = a + b while a or b'])
|
164
|
+
inspect_source(cop, 'x = a + b while a or b')
|
179
165
|
expect(cop.offenses.size).to eq(1)
|
180
166
|
expect(cop.messages).to eq(['Use `||` instead of `or`.'])
|
181
167
|
end
|
182
168
|
|
183
169
|
it 'also warns on until (or)' do
|
184
|
-
inspect_source(cop,
|
185
|
-
['x = a + b until a or b'])
|
170
|
+
inspect_source(cop, 'x = a + b until a or b')
|
186
171
|
expect(cop.offenses.size).to eq(1)
|
187
172
|
expect(cop.messages).to eq(['Use `||` instead of `or`.'])
|
188
173
|
end
|
@@ -7,23 +7,23 @@ describe RuboCop::Cop::Style::ArrayJoin do
|
|
7
7
|
|
8
8
|
it 'registers an offense for an array followed by string' do
|
9
9
|
inspect_source(cop,
|
10
|
-
|
10
|
+
'%w(one two three) * ", "')
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'does not register an offense for numbers' do
|
15
15
|
inspect_source(cop,
|
16
|
-
|
16
|
+
'%w(one two three) * 4')
|
17
17
|
expect(cop.offenses).to be_empty
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'does not register an offense for ambiguous cases' do
|
21
21
|
inspect_source(cop,
|
22
|
-
|
22
|
+
'test * ", "')
|
23
23
|
expect(cop.offenses).to be_empty
|
24
24
|
|
25
25
|
inspect_source(cop,
|
26
|
-
|
26
|
+
'%w(one two three) * test')
|
27
27
|
expect(cop.offenses).to be_empty
|
28
28
|
end
|
29
29
|
end
|
@@ -16,7 +16,7 @@ describe RuboCop::Cop::Style::AsciiIdentifiers do
|
|
16
16
|
|
17
17
|
it 'accepts identifiers with only ascii chars' do
|
18
18
|
inspect_source(cop,
|
19
|
-
|
19
|
+
'x.empty?')
|
20
20
|
expect(cop.offenses).to be_empty
|
21
21
|
end
|
22
22
|
|
@@ -30,7 +30,7 @@ describe RuboCop::Cop::Style::AsciiIdentifiers do
|
|
30
30
|
|
31
31
|
it 'does not get confused by an empty file' do
|
32
32
|
inspect_source(cop,
|
33
|
-
|
33
|
+
'')
|
34
34
|
expect(cop.offenses).to be_empty
|
35
35
|
end
|
36
36
|
end
|
@@ -6,7 +6,7 @@ describe RuboCop::Cop::Style::BlockEndNewline do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'does not register an offense for a one-liner' do
|
9
|
-
inspect_source(cop,
|
9
|
+
inspect_source(cop, 'test do foo end')
|
10
10
|
expect(cop.messages).to be_empty
|
11
11
|
end
|
12
12
|
|
@@ -12,13 +12,13 @@ describe RuboCop::Cop::Style::Blocks do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'registers an offense for a single line block with do-end' do
|
15
|
-
inspect_source(cop,
|
15
|
+
inspect_source(cop, 'each do |x| end')
|
16
16
|
expect(cop.messages)
|
17
17
|
.to eq(['Prefer {...} over do...end for single-line blocks.'])
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'accepts a single line block with braces' do
|
21
|
-
inspect_source(cop,
|
21
|
+
inspect_source(cop, 'each { |x| }')
|
22
22
|
expect(cop.offenses).to be_empty
|
23
23
|
end
|
24
24
|
|
@@ -9,15 +9,15 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
9
9
|
after(:each) { expect(cop.offenses).to be_empty }
|
10
10
|
|
11
11
|
it 'accepts one non-hash parameter' do
|
12
|
-
inspect_source(cop,
|
12
|
+
inspect_source(cop, 'where(2)')
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'accepts multiple non-hash parameters' do
|
16
|
-
inspect_source(cop,
|
16
|
+
inspect_source(cop, 'where(1, "2")')
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'accepts one empty hash parameter' do
|
20
|
-
inspect_source(cop,
|
20
|
+
inspect_source(cop, 'where({})')
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'accepts one empty hash parameter with whitespace' do
|
@@ -30,23 +30,23 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
30
30
|
after(:each) { expect(cop.offenses).to be_empty }
|
31
31
|
|
32
32
|
it 'accepts one hash parameter without braces' do
|
33
|
-
inspect_source(cop,
|
33
|
+
inspect_source(cop, 'where(x: "y")')
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'accepts one hash parameter without braces and with multiple keys' do
|
37
|
-
inspect_source(cop,
|
37
|
+
inspect_source(cop, 'where(x: "y", foo: "bar")')
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'accepts one hash parameter without braces and with one hash value' do
|
41
|
-
inspect_source(cop,
|
41
|
+
inspect_source(cop, 'where(x: { "y" => "z" })')
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'accepts property assignment with braces' do
|
45
|
-
inspect_source(cop,
|
45
|
+
inspect_source(cop, 'x.z = { y: "z" }')
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'accepts operator with a hash parameter with braces' do
|
49
|
-
inspect_source(cop,
|
49
|
+
inspect_source(cop, 'x.z - { y: "z" }')
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -55,34 +55,34 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
55
55
|
|
56
56
|
it 'registers an offense for one non-hash parameter followed by a hash ' \
|
57
57
|
'parameter with braces' do
|
58
|
-
inspect_source(cop,
|
58
|
+
inspect_source(cop, 'where(1, { y: 2 })')
|
59
59
|
expect(cop.messages).to eq([msg])
|
60
60
|
expect(cop.highlights).to eq(['{ y: 2 }'])
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'registers an offense for one object method hash parameter with ' \
|
64
64
|
'braces' do
|
65
|
-
inspect_source(cop,
|
65
|
+
inspect_source(cop, 'x.func({ y: "z" })')
|
66
66
|
expect(cop.messages).to eq([msg])
|
67
67
|
expect(cop.highlights).to eq(['{ y: "z" }'])
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'registers an offense for one hash parameter with braces' do
|
71
|
-
inspect_source(cop,
|
71
|
+
inspect_source(cop, 'where({ x: 1 })')
|
72
72
|
expect(cop.messages).to eq([msg])
|
73
73
|
expect(cop.highlights).to eq(['{ x: 1 }'])
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'registers an offense for one hash parameter with braces and ' \
|
77
77
|
'whitespace' do
|
78
|
-
inspect_source(cop,
|
78
|
+
inspect_source(cop, "where( \n { x: 1 } )")
|
79
79
|
expect(cop.messages).to eq([msg])
|
80
80
|
expect(cop.highlights).to eq(['{ x: 1 }'])
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'registers an offense for one hash parameter with braces and multiple ' \
|
84
84
|
'keys' do
|
85
|
-
inspect_source(cop,
|
85
|
+
inspect_source(cop, 'where({ x: 1, foo: "bar" })')
|
86
86
|
expect(cop.messages).to eq([msg])
|
87
87
|
expect(cop.highlights).to eq(['{ x: 1, foo: "bar" }'])
|
88
88
|
end
|
@@ -92,51 +92,56 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
92
92
|
it 'corrects one non-hash parameter followed by a hash parameter with ' \
|
93
93
|
'braces' do
|
94
94
|
corrected = autocorrect_source(cop, ['where(1, { y: 2 })'])
|
95
|
-
expect(corrected).to eq('where(1,
|
95
|
+
expect(corrected).to eq('where(1, y: 2)')
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'corrects one object method hash parameter with braces' do
|
99
99
|
corrected = autocorrect_source(cop, ['x.func({ y: "z" })'])
|
100
|
-
expect(corrected).to eq('x.func(
|
100
|
+
expect(corrected).to eq('x.func(y: "z")')
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'corrects one hash parameter with braces' do
|
104
104
|
corrected = autocorrect_source(cop, ['where({ x: 1 })'])
|
105
|
-
expect(corrected).to eq('where(
|
105
|
+
expect(corrected).to eq('where(x: 1)')
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'corrects one hash parameter with braces and whitespace' do
|
109
109
|
corrected = autocorrect_source(cop, ['where( ',
|
110
110
|
' { x: 1 } )'])
|
111
111
|
expect(corrected).to eq(['where( ',
|
112
|
-
'
|
112
|
+
' x: 1 )'].join("\n"))
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'corrects one hash parameter with braces and multiple keys' do
|
116
116
|
corrected = autocorrect_source(cop, ['where({ x: 1, foo: "bar" })'])
|
117
|
-
expect(corrected).to eq('where(
|
117
|
+
expect(corrected).to eq('where(x: 1, foo: "bar")')
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'corrects one hash parameter with braces and extra leading whitespace' do
|
121
121
|
corrected = autocorrect_source(cop, ['where({ x: 1, y: 2 })'])
|
122
|
-
expect(corrected).to eq('where(
|
122
|
+
expect(corrected).to eq('where(x: 1, y: 2)')
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'corrects one hash parameter with braces and extra trailing ' \
|
126
126
|
'whitespace' do
|
127
127
|
corrected = autocorrect_source(cop, ['where({ x: 1, y: 2 })'])
|
128
|
-
expect(corrected).to eq('where(
|
128
|
+
expect(corrected).to eq('where(x: 1, y: 2)')
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'corrects one hash parameter with braces and a trailing comma' do
|
132
132
|
corrected = autocorrect_source(cop, ['where({ x: 1, y: 2, })'])
|
133
|
-
expect(corrected).to eq('where(
|
133
|
+
expect(corrected).to eq('where(x: 1, y: 2,)')
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'corrects one hash parameter with braces and trailing comma and ' \
|
137
137
|
'whitespace' do
|
138
138
|
corrected = autocorrect_source(cop, ['where({ x: 1, y: 2, })'])
|
139
|
-
expect(corrected).to eq('where(
|
139
|
+
expect(corrected).to eq('where(x: 1, y: 2,)')
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'corrects one hash parameter with braces without adding extra space' do
|
143
|
+
corrected = autocorrect_source(cop, 'get :i, { q: { x: 1 } }')
|
144
|
+
expect(corrected).to eq('get :i, q: { x: 1 }')
|
140
145
|
end
|
141
146
|
end
|
142
147
|
|
@@ -157,7 +162,7 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
157
162
|
end
|
158
163
|
|
159
164
|
it 'registers an offense for two hash parameters with braces' do
|
160
|
-
inspect_source(cop,
|
165
|
+
inspect_source(cop, 'where({ x: 1 }, { y: 2 })')
|
161
166
|
expect(cop.highlights).to eq(['{ y: 2 }'])
|
162
167
|
end
|
163
168
|
end
|
@@ -167,12 +172,12 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
167
172
|
|
168
173
|
it 'corrects one hash parameter with braces' do
|
169
174
|
corrected = autocorrect_source(cop, ['where(1, { x: 1 })'])
|
170
|
-
expect(corrected).to eq('where(1,
|
175
|
+
expect(corrected).to eq('where(1, x: 1)')
|
171
176
|
end
|
172
177
|
|
173
178
|
it 'corrects two hash parameters with braces' do
|
174
179
|
corrected = autocorrect_source(cop, ['where(1, { x: 1 }, { y: 2 })'])
|
175
|
-
expect(corrected).to eq('where(1, { x: 1 },
|
180
|
+
expect(corrected).to eq('where(1, { x: 1 }, y: 2)')
|
176
181
|
end
|
177
182
|
end
|
178
183
|
end
|
@@ -185,7 +190,7 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
185
190
|
include_examples 'no_braces and context_dependent non-offenses'
|
186
191
|
|
187
192
|
it 'accepts two hash parameters with braces' do
|
188
|
-
inspect_source(cop,
|
193
|
+
inspect_source(cop, 'where({ x: 1 }, { y: 2 })')
|
189
194
|
expect(cop.offenses).to be_empty
|
190
195
|
end
|
191
196
|
end
|
@@ -195,7 +200,7 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
195
200
|
|
196
201
|
it 'registers an offense for one hash parameter with braces and one ' \
|
197
202
|
'without' do
|
198
|
-
inspect_source(cop,
|
203
|
+
inspect_source(cop, 'where({ x: 1 }, y: 2)')
|
199
204
|
expect(cop.messages)
|
200
205
|
.to eq(['Missing curly braces around a hash parameter.'])
|
201
206
|
expect(cop.highlights).to eq(['y: 2'])
|
@@ -212,7 +217,7 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
212
217
|
|
213
218
|
it 'corrects one hash parameter with braces' do
|
214
219
|
corrected = autocorrect_source(cop, ['where(1, { x: 1 })'])
|
215
|
-
expect(corrected).to eq('where(1,
|
220
|
+
expect(corrected).to eq('where(1, x: 1)')
|
216
221
|
end
|
217
222
|
end
|
218
223
|
end
|
@@ -226,11 +231,11 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
226
231
|
after(:each) { expect(cop.offenses).to be_empty }
|
227
232
|
|
228
233
|
it 'accepts one hash parameter with braces' do
|
229
|
-
inspect_source(cop,
|
234
|
+
inspect_source(cop, 'where({ x: 1 })')
|
230
235
|
end
|
231
236
|
|
232
237
|
it 'accepts multiple hash parameters with braces' do
|
233
|
-
inspect_source(cop,
|
238
|
+
inspect_source(cop, 'where({ x: 1 }, { y: 2 })')
|
234
239
|
end
|
235
240
|
|
236
241
|
it 'accepts one hash parameter with braces and whitespace' do
|
@@ -246,19 +251,19 @@ describe RuboCop::Cop::Style::BracesAroundHashParameters, :config do
|
|
246
251
|
end
|
247
252
|
|
248
253
|
it 'registers an offense for one hash parameter without braces' do
|
249
|
-
inspect_source(cop,
|
254
|
+
inspect_source(cop, 'where(x: "y")')
|
250
255
|
expect(cop.highlights).to eq(['x: "y"'])
|
251
256
|
end
|
252
257
|
|
253
258
|
it 'registers an offense for one hash parameter with multiple keys and ' \
|
254
259
|
'without braces' do
|
255
|
-
inspect_source(cop,
|
260
|
+
inspect_source(cop, 'where(x: "y", foo: "bar")')
|
256
261
|
expect(cop.highlights).to eq(['x: "y", foo: "bar"'])
|
257
262
|
end
|
258
263
|
|
259
264
|
it 'registers an offense for one hash parameter without braces with ' \
|
260
265
|
'one hash value' do
|
261
|
-
inspect_source(cop,
|
266
|
+
inspect_source(cop, 'where(x: { "y" => "z" })')
|
262
267
|
expect(cop.highlights).to eq(['x: { "y" => "z" }'])
|
263
268
|
end
|
264
269
|
end
|