rubocop 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -246,6 +246,19 @@ describe RuboCop::ConfigLoader do
|
|
246
246
|
.to be_superset(expected.to_set)
|
247
247
|
end
|
248
248
|
end
|
249
|
+
|
250
|
+
context 'when a file inherits from an expanded path' do
|
251
|
+
let(:file_path) { '.rubocop.yml' }
|
252
|
+
|
253
|
+
before do
|
254
|
+
create_file('~/.rubocop.yml', [''])
|
255
|
+
create_file(file_path, ['inherit_from: ~/.rubocop.yml'])
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'does not fail to load expanded path' do
|
259
|
+
expect { configuration_from_file }.not_to raise_error
|
260
|
+
end
|
261
|
+
end
|
249
262
|
end
|
250
263
|
|
251
264
|
describe '.load_file', :isolated_environment do
|
@@ -266,6 +279,13 @@ describe RuboCop::ConfigLoader do
|
|
266
279
|
)
|
267
280
|
end
|
268
281
|
|
282
|
+
it 'fails with a TypeError when loading a malformed configuration file' do
|
283
|
+
create_file(configuration_path, 'This string is not a YAML hash')
|
284
|
+
expect { load_file }.to raise_error(
|
285
|
+
TypeError, /^Malformed configuration in .*\.rubocop\.yml$/
|
286
|
+
)
|
287
|
+
end
|
288
|
+
|
269
289
|
it 'returns an empty configuration loaded from an empty file' do
|
270
290
|
create_file(configuration_path, '')
|
271
291
|
configuration = load_file
|
@@ -62,6 +62,14 @@ describe RuboCop::Cop::Lint::AssignmentInCondition, :config do
|
|
62
62
|
expect(cop.offenses.size).to eq(1)
|
63
63
|
end
|
64
64
|
|
65
|
+
it 'registers an offense for collection element assignment in condition' do
|
66
|
+
inspect_source(cop,
|
67
|
+
['if a[3] = 10',
|
68
|
+
'end'
|
69
|
+
])
|
70
|
+
expect(cop.offenses.size).to eq(1)
|
71
|
+
end
|
72
|
+
|
65
73
|
it 'accepts == in condition' do
|
66
74
|
inspect_source(cop,
|
67
75
|
['if test == 10',
|
@@ -72,13 +80,13 @@ describe RuboCop::Cop::Lint::AssignmentInCondition, :config do
|
|
72
80
|
|
73
81
|
it 'accepts = in a block that is called in a condition' do
|
74
82
|
inspect_source(cop,
|
75
|
-
|
83
|
+
'return 1 if any_errors? { o = inspect(file) }')
|
76
84
|
expect(cop.offenses).to be_empty
|
77
85
|
end
|
78
86
|
|
79
87
|
it 'accepts ||= in condition' do
|
80
88
|
inspect_source(cop,
|
81
|
-
|
89
|
+
'raise StandardError unless foo ||= bar')
|
82
90
|
expect(cop.offenses).to be_empty
|
83
91
|
end
|
84
92
|
|
@@ -90,17 +98,33 @@ describe RuboCop::Cop::Lint::AssignmentInCondition, :config do
|
|
90
98
|
])
|
91
99
|
expect(cop.offenses).to be_empty
|
92
100
|
end
|
101
|
+
|
102
|
+
it 'accepts []= in condition surrounded with braces' do
|
103
|
+
inspect_source(cop,
|
104
|
+
['if (test[0] = 10)',
|
105
|
+
'end'
|
106
|
+
])
|
107
|
+
expect(cop.offenses).to be_empty
|
108
|
+
end
|
93
109
|
end
|
94
110
|
|
95
111
|
context 'safe assignment is not allowed' do
|
96
112
|
let(:cop_config) { { 'AllowSafeAssignment' => false } }
|
97
113
|
|
98
|
-
it 'does not
|
114
|
+
it 'does not accept = in condition surrounded with braces' do
|
99
115
|
inspect_source(cop,
|
100
116
|
['if (test = 10)',
|
101
117
|
'end'
|
102
118
|
])
|
103
119
|
expect(cop.offenses.size).to eq(1)
|
104
120
|
end
|
121
|
+
|
122
|
+
it 'does not accept []= in condition surrounded with braces' do
|
123
|
+
inspect_source(cop,
|
124
|
+
['if (test[0] = 10)',
|
125
|
+
'end'
|
126
|
+
])
|
127
|
+
expect(cop.offenses.size).to eq(1)
|
128
|
+
end
|
105
129
|
end
|
106
130
|
end
|
@@ -93,14 +93,14 @@ describe RuboCop::Cop::Lint::BlockAlignment do
|
|
93
93
|
expect(cop.offenses).to be_empty
|
94
94
|
end
|
95
95
|
|
96
|
-
it 'auto-corrects alignment to the
|
96
|
+
it 'auto-corrects alignment to the first variable' do
|
97
97
|
new_source = autocorrect_source(cop,
|
98
98
|
['a = b = c = test do |ala|',
|
99
99
|
' end'
|
100
100
|
])
|
101
101
|
|
102
102
|
expect(new_source).to eq(['a = b = c = test do |ala|',
|
103
|
-
'
|
103
|
+
'end'
|
104
104
|
].join("\n"))
|
105
105
|
end
|
106
106
|
end
|
@@ -424,8 +424,7 @@ describe RuboCop::Cop::Lint::BlockAlignment do
|
|
424
424
|
|
425
425
|
it 'does not raise an error for nested block in a method call' do
|
426
426
|
inspect_source(cop,
|
427
|
-
|
428
|
-
])
|
427
|
+
'expect(arr.all? { |o| o.valid? })')
|
429
428
|
expect(cop.offenses).to be_empty
|
430
429
|
end
|
431
430
|
|
@@ -6,7 +6,7 @@ describe RuboCop::Cop::Lint::Debugger do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'reports an offense for a debugger call' do
|
9
|
-
src =
|
9
|
+
src = 'debugger'
|
10
10
|
inspect_source(cop, src)
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
expect(cop.messages).to eq(['Remove debugger entry point `debugger`.'])
|
@@ -14,7 +14,7 @@ describe RuboCop::Cop::Lint::Debugger do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'reports an offense for a byebug call' do
|
17
|
-
src =
|
17
|
+
src = 'byebug'
|
18
18
|
inspect_source(cop, src)
|
19
19
|
expect(cop.offenses.size).to eq(1)
|
20
20
|
expect(cop.messages).to eq(['Remove debugger entry point `byebug`.'])
|
@@ -36,23 +36,36 @@ describe RuboCop::Cop::Lint::Debugger do
|
|
36
36
|
'binding.pry_remote'])
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'reports an offense for capybara debug methods' do
|
40
|
+
src = %w(save_and_open_page save_and_open_screenshot)
|
41
|
+
inspect_source(cop, src)
|
42
|
+
expect(cop.offenses.size).to eq(2)
|
43
|
+
expect(cop.messages)
|
44
|
+
.to eq(['Remove debugger entry point `save_and_open_page`.',
|
45
|
+
'Remove debugger entry point `save_and_open_screenshot`.'])
|
46
|
+
expect(cop.highlights)
|
47
|
+
.to eq(%w(save_and_open_page save_and_open_screenshot))
|
48
|
+
end
|
49
|
+
|
39
50
|
it 'does not report an offense for non-pry binding' do
|
40
|
-
src =
|
51
|
+
src = 'binding.pirate'
|
41
52
|
inspect_source(cop, src)
|
42
53
|
expect(cop.offenses).to be_empty
|
43
54
|
end
|
44
55
|
|
45
|
-
%w(debugger byebug pry remote_pry pry_remote
|
56
|
+
%w(debugger byebug pry remote_pry pry_remote
|
57
|
+
save_and_open_page save_and_open_screenshot).each do |comment|
|
46
58
|
it "does not report an offense for #{comment} in comments" do
|
47
|
-
src =
|
59
|
+
src = "# #{comment}"
|
48
60
|
inspect_source(cop, src)
|
49
61
|
expect(cop.offenses).to be_empty
|
50
62
|
end
|
51
63
|
end
|
52
64
|
|
53
|
-
%w(debugger byebug pry remote_pry pry_remote
|
65
|
+
%w(debugger byebug pry remote_pry pry_remote
|
66
|
+
save_and_open_page save_and_open_screenshot).each do |method_name|
|
54
67
|
it "does not report an offense for a #{method_name} method" do
|
55
|
-
src =
|
68
|
+
src = "code.#{method_name}"
|
56
69
|
inspect_source(cop, src)
|
57
70
|
expect(cop.offenses).to be_empty
|
58
71
|
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RuboCop::Cop::Lint::DuplicateMethods do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offense for duplicate method in class' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['class A',
|
11
|
+
' def some_method',
|
12
|
+
' implement 1',
|
13
|
+
' end',
|
14
|
+
' def some_method',
|
15
|
+
' implement 2',
|
16
|
+
' end',
|
17
|
+
'end'])
|
18
|
+
expect(cop.offenses.size).to eq(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'does not register an offense for non-duplicate method in class' do
|
22
|
+
inspect_source(cop,
|
23
|
+
['class A',
|
24
|
+
' def some_method',
|
25
|
+
' implement 1',
|
26
|
+
' end',
|
27
|
+
' def any_method',
|
28
|
+
' implement 2',
|
29
|
+
' end',
|
30
|
+
'end'])
|
31
|
+
expect(cop.offenses).to be_empty
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'registers an offense for duplicate method in module' do
|
35
|
+
inspect_source(cop,
|
36
|
+
['module A',
|
37
|
+
' def some_method',
|
38
|
+
' implement 1',
|
39
|
+
' end',
|
40
|
+
' def some_method',
|
41
|
+
' implement 2',
|
42
|
+
' end',
|
43
|
+
'end'])
|
44
|
+
expect(cop.offenses.size).to eq(1)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'does not register an offense for non-duplicate method in module' do
|
48
|
+
inspect_source(cop,
|
49
|
+
['module A',
|
50
|
+
' def some_method',
|
51
|
+
' implement 1',
|
52
|
+
' end',
|
53
|
+
' def any_method',
|
54
|
+
' implement 2',
|
55
|
+
' end',
|
56
|
+
'end'])
|
57
|
+
expect(cop.offenses).to be_empty
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'registers an offense for duplicate class methods in module' do
|
61
|
+
inspect_source(cop,
|
62
|
+
['module A',
|
63
|
+
' def self.some_method',
|
64
|
+
' implement 1',
|
65
|
+
' end',
|
66
|
+
' def self.some_method',
|
67
|
+
' implement 2',
|
68
|
+
' end',
|
69
|
+
'end'])
|
70
|
+
expect(cop.offenses.size).to eq(1)
|
71
|
+
end
|
72
|
+
it 'doesn`t registers an offense for non-duplicate class methods in module' do
|
73
|
+
inspect_source(cop,
|
74
|
+
['module A',
|
75
|
+
' def self.some_method',
|
76
|
+
' implement 1',
|
77
|
+
' end',
|
78
|
+
' def self.any_method',
|
79
|
+
' implement 2',
|
80
|
+
' end',
|
81
|
+
'end'])
|
82
|
+
expect(cop.offenses.size).to eq(0)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'differ instance and class methods in module' do
|
86
|
+
inspect_source(cop,
|
87
|
+
['module A',
|
88
|
+
' def some_method',
|
89
|
+
' implement 1',
|
90
|
+
' end',
|
91
|
+
' def self.some_method',
|
92
|
+
' implement 2',
|
93
|
+
' end',
|
94
|
+
'end'])
|
95
|
+
expect(cop.offenses.size).to eq(0)
|
96
|
+
end
|
97
|
+
|
98
|
+
it %(registers an offense for duplicate private methods in class) do
|
99
|
+
inspect_source(cop,
|
100
|
+
['class A',
|
101
|
+
' private def some_method',
|
102
|
+
' implement 1',
|
103
|
+
' end',
|
104
|
+
' private def some_method',
|
105
|
+
' implement 2',
|
106
|
+
' end',
|
107
|
+
'end'])
|
108
|
+
expect(cop.offenses.size).to eq(1)
|
109
|
+
end
|
110
|
+
|
111
|
+
it %(registers an offense for duplicate private self methods in class) do
|
112
|
+
inspect_source(cop,
|
113
|
+
['class A',
|
114
|
+
' private def self.some_method',
|
115
|
+
' implement 1',
|
116
|
+
' end',
|
117
|
+
' private def self.some_method',
|
118
|
+
' implement 2',
|
119
|
+
' end',
|
120
|
+
'end'])
|
121
|
+
expect(cop.offenses.size).to eq(1)
|
122
|
+
end
|
123
|
+
|
124
|
+
it %(don`t registers an offense for different private methods in class) do
|
125
|
+
inspect_source(cop,
|
126
|
+
['class A',
|
127
|
+
' private def some_method',
|
128
|
+
' implement 1',
|
129
|
+
' end',
|
130
|
+
' private def any_method',
|
131
|
+
' implement 2',
|
132
|
+
' end',
|
133
|
+
'end'])
|
134
|
+
expect(cop.offenses.size).to eq(0)
|
135
|
+
end
|
136
|
+
|
137
|
+
it %(registers an offense for duplicate protected methods in class) do
|
138
|
+
inspect_source(cop,
|
139
|
+
['class A',
|
140
|
+
' protected def some_method',
|
141
|
+
' implement 1',
|
142
|
+
' end',
|
143
|
+
' protected def some_method',
|
144
|
+
' implement 2',
|
145
|
+
' end',
|
146
|
+
'end'])
|
147
|
+
expect(cop.offenses.size).to eq(1)
|
148
|
+
end
|
149
|
+
|
150
|
+
it %(registers 2 offenses for pair of duplicate methods in class) do
|
151
|
+
inspect_source(cop,
|
152
|
+
['class A',
|
153
|
+
' def some_method',
|
154
|
+
' implement 1',
|
155
|
+
' end',
|
156
|
+
' def some_method',
|
157
|
+
' implement 2',
|
158
|
+
' end',
|
159
|
+
' def any_method',
|
160
|
+
' implement 1',
|
161
|
+
' end',
|
162
|
+
' def any_method',
|
163
|
+
' implement 2',
|
164
|
+
' end',
|
165
|
+
'end'])
|
166
|
+
expect(cop.offenses.size).to eq(2)
|
167
|
+
end
|
168
|
+
|
169
|
+
it %(generate 2 offenses with specified messages) do
|
170
|
+
inspect_source(cop,
|
171
|
+
['class A',
|
172
|
+
' def some_method',
|
173
|
+
' implement 1',
|
174
|
+
' end',
|
175
|
+
' def some_method',
|
176
|
+
' implement 2',
|
177
|
+
' end',
|
178
|
+
' def any_method',
|
179
|
+
' implement 1',
|
180
|
+
' end',
|
181
|
+
' def any_method',
|
182
|
+
' implement 2',
|
183
|
+
' end',
|
184
|
+
'end'])
|
185
|
+
expect(cop.messages).to match_array([
|
186
|
+
%(Duplicate methods `some_method` at lines `2, 5` detected.),
|
187
|
+
%(Duplicate methods `any_method` at lines `8, 11` detected.)])
|
188
|
+
end
|
189
|
+
end
|
@@ -6,7 +6,7 @@ describe RuboCop::Cop::Lint::EmptyInterpolation do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'registers an offense for #{} in interpolation' do
|
9
|
-
inspect_source(cop,
|
9
|
+
inspect_source(cop, '"this is the #{}"')
|
10
10
|
expect(cop.offenses.size).to eq(1)
|
11
11
|
expect(cop.highlights).to eq(['#{}'])
|
12
12
|
end
|
@@ -7,27 +7,27 @@ describe RuboCop::Cop::Lint::Eval do
|
|
7
7
|
|
8
8
|
it 'registers an offense for eval as function' do
|
9
9
|
inspect_source(cop,
|
10
|
-
|
10
|
+
'eval(something)')
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
expect(cop.highlights) .to eq(['eval'])
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'registers an offense for eval as command' do
|
16
16
|
inspect_source(cop,
|
17
|
-
|
17
|
+
'eval something')
|
18
18
|
expect(cop.offenses.size).to eq(1)
|
19
19
|
expect(cop.highlights) .to eq(['eval'])
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'does not register an offense for eval as variable' do
|
23
23
|
inspect_source(cop,
|
24
|
-
|
24
|
+
'eval = something')
|
25
25
|
expect(cop.offenses).to be_empty
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'does not register an offense for eval as method' do
|
29
29
|
inspect_source(cop,
|
30
|
-
|
30
|
+
'something.eval')
|
31
31
|
expect(cop.offenses).to be_empty
|
32
32
|
end
|
33
33
|
end
|
@@ -24,6 +24,15 @@ describe RuboCop::Cop::Lint::LiteralInCondition do
|
|
24
24
|
expect(cop.offenses.size).to eq(1)
|
25
25
|
end
|
26
26
|
|
27
|
+
it "registers an offense for literal #{lit} in post-loop while" do
|
28
|
+
inspect_source(cop,
|
29
|
+
['begin',
|
30
|
+
' top',
|
31
|
+
"end while(#{lit})"
|
32
|
+
])
|
33
|
+
expect(cop.offenses.size).to eq(1)
|
34
|
+
end
|
35
|
+
|
27
36
|
it "registers an offense for literal #{lit} in until" do
|
28
37
|
inspect_source(cop,
|
29
38
|
["until #{lit}",
|
@@ -33,6 +42,15 @@ describe RuboCop::Cop::Lint::LiteralInCondition do
|
|
33
42
|
expect(cop.offenses.size).to eq(1)
|
34
43
|
end
|
35
44
|
|
45
|
+
it "registers an offense for literal #{lit} in post-loop until" do
|
46
|
+
inspect_source(cop,
|
47
|
+
['begin',
|
48
|
+
' top',
|
49
|
+
"end until #{lit}"
|
50
|
+
])
|
51
|
+
expect(cop.offenses.size).to eq(1)
|
52
|
+
end
|
53
|
+
|
36
54
|
it "registers an offense for literal #{lit} in case" do
|
37
55
|
inspect_source(cop,
|
38
56
|
["case #{lit}",
|