rubocop 0.12.0 → 0.13.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.
- data/CHANGELOG.md +40 -0
- data/README.md +49 -8
- data/config/default.yml +40 -0
- data/config/enabled.yml +37 -9
- data/lib/rubocop.rb +24 -10
- data/lib/rubocop/cli.rb +41 -106
- data/lib/rubocop/config.rb +3 -2
- data/lib/rubocop/cop/commissioner.rb +15 -5
- data/lib/rubocop/cop/cop.rb +47 -32
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/block_alignment.rb +30 -9
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +4 -4
- data/lib/rubocop/cop/lint/end_in_method.rb +1 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/eval.rb +1 -3
- data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +6 -4
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +5 -8
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +57 -60
- data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +85 -0
- data/lib/rubocop/cop/lint/void.rb +6 -8
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
- data/lib/rubocop/cop/rails/read_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/style/access_control.rb +4 -6
- data/lib/rubocop/cop/style/alias.rb +1 -3
- data/lib/rubocop/cop/style/align_array.rb +47 -0
- data/lib/rubocop/cop/style/align_hash.rb +145 -0
- data/lib/rubocop/cop/style/align_parameters.rb +9 -3
- data/lib/rubocop/cop/style/and_or.rb +3 -4
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -3
- data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -4
- data/lib/rubocop/cop/style/begin_block.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_nesting.rb +2 -2
- data/lib/rubocop/cop/style/blocks.rb +14 -2
- data/lib/rubocop/cop/style/case_equality.rb +1 -3
- data/lib/rubocop/cop/style/case_indentation.rb +1 -1
- data/lib/rubocop/cop/style/character_literal.rb +1 -2
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/style/class_methods.rb +1 -3
- data/lib/rubocop/cop/style/{avoid_class_vars.rb → class_vars.rb} +6 -2
- data/lib/rubocop/cop/style/collection_methods.rb +7 -9
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +6 -6
- data/lib/rubocop/cop/style/constant_name.rb +1 -3
- data/lib/rubocop/cop/style/def_parentheses.rb +4 -12
- data/lib/rubocop/cop/style/documentation.rb +2 -2
- data/lib/rubocop/cop/style/dot_position.rb +2 -4
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +21 -6
- data/lib/rubocop/cop/style/empty_lines.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +3 -12
- data/lib/rubocop/cop/style/encoding.rb +6 -6
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/end_of_line.rb +5 -5
- data/lib/rubocop/cop/style/even_odd.rb +2 -2
- data/lib/rubocop/cop/style/favor_join.rb +1 -3
- data/lib/rubocop/cop/style/favor_modifier.rb +7 -3
- data/lib/rubocop/cop/style/favor_sprintf.rb +1 -1
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -1
- data/lib/rubocop/cop/style/final_newline.rb +23 -0
- data/lib/rubocop/cop/style/{avoid_for.rb → for.rb} +2 -2
- data/lib/rubocop/cop/style/{avoid_global_vars.rb → global_vars.rb} +19 -6
- data/lib/rubocop/cop/style/hash_methods.rb +3 -5
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -4
- data/lib/rubocop/cop/style/if_then_else.rb +1 -1
- data/lib/rubocop/cop/style/indentation_width.rb +4 -4
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/style/line_length.rb +7 -8
- data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +1 -1
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -4
- data/lib/rubocop/cop/style/method_length.rb +4 -4
- data/lib/rubocop/cop/style/module_function.rb +1 -3
- data/lib/rubocop/cop/style/multiline_block_chain.rb +44 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -3
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +26 -6
- data/lib/rubocop/cop/style/op_method.rb +2 -2
- data/lib/rubocop/cop/style/parameter_lists.rb +4 -4
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
- data/lib/rubocop/cop/style/perl_backrefs.rb +26 -0
- data/lib/rubocop/cop/style/proc.rb +1 -3
- data/lib/rubocop/cop/style/reduce_arguments.rb +7 -5
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +9 -2
- data/lib/rubocop/cop/style/redundant_self.rb +9 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +7 -8
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +10 -10
- data/lib/rubocop/cop/style/signal_exception.rb +2 -4
- data/lib/rubocop/cop/style/single_line_methods.rb +2 -4
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +1 -1
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +34 -0
- data/lib/rubocop/cop/style/{avoid_perlisms.rb → special_global_vars.rb} +17 -8
- data/lib/rubocop/cop/style/string_literals.rb +1 -2
- data/lib/rubocop/cop/style/surrounding_space.rb +9 -8
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_name.rb +9 -2
- data/lib/rubocop/cop/style/tab.rb +5 -5
- data/lib/rubocop/cop/style/ternary_operator.rb +2 -6
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +32 -0
- data/lib/rubocop/cop/style/trailing_whitespace.rb +5 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -3
- data/lib/rubocop/cop/style/when_then.rb +1 -4
- data/lib/rubocop/cop/style/while_until_do.rb +7 -5
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/team.rb +100 -0
- data/lib/rubocop/cop/variable_inspector.rb +323 -235
- data/lib/rubocop/cop/variable_inspector/assignment.rb +103 -0
- data/lib/rubocop/cop/variable_inspector/locatable.rb +162 -0
- data/lib/rubocop/cop/variable_inspector/reference.rb +31 -0
- data/lib/rubocop/cop/variable_inspector/scope.rb +70 -0
- data/lib/rubocop/cop/variable_inspector/variable.rb +87 -0
- data/lib/rubocop/cop/variable_inspector/variable_table.rb +129 -0
- data/lib/rubocop/formatter/json_formatter.rb +8 -8
- data/lib/rubocop/formatter/progress_formatter.rb +4 -4
- data/lib/rubocop/processed_source.rb +22 -1
- data/lib/rubocop/version.rb +1 -1
- data/rubocop.gemspec +1 -1
- data/spec/rubocop/cli_spec.rb +32 -30
- data/spec/rubocop/config_spec.rb +4 -6
- data/spec/rubocop/cop/commissioner_spec.rb +4 -5
- data/spec/rubocop/cop/cop_spec.rb +8 -26
- data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +5 -9
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +105 -57
- data/spec/rubocop/cop/lint/empty_ensure_spec.rb +1 -1
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +1 -1
- data/spec/rubocop/cop/lint/end_in_method_spec.rb +1 -1
- data/spec/rubocop/cop/lint/ensure_return_spec.rb +1 -1
- data/spec/rubocop/cop/lint/eval_spec.rb +3 -3
- data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +2 -2
- data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +1 -1
- data/spec/rubocop/cop/lint/loop_spec.rb +1 -1
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +1 -1
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +5 -5
- data/spec/rubocop/cop/lint/unreachable_code_spec.rb +1 -1
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +1545 -108
- data/spec/rubocop/cop/lint/useless_comparison_spec.rb +1 -1
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +101 -0
- data/spec/rubocop/cop/lint/void_spec.rb +1 -1
- data/spec/rubocop/cop/offence_spec.rb +4 -4
- data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +1 -1
- data/spec/rubocop/cop/rails/read_attribute_spec.rb +1 -1
- data/spec/rubocop/cop/rails/validation_spec.rb +1 -1
- data/spec/rubocop/cop/style/access_control_spec.rb +20 -20
- data/spec/rubocop/cop/style/alias_spec.rb +3 -3
- data/spec/rubocop/cop/style/align_array_spec.rb +62 -0
- data/spec/rubocop/cop/style/align_hash_spec.rb +267 -0
- data/spec/rubocop/cop/style/align_parameters_spec.rb +2 -2
- data/spec/rubocop/cop/style/and_or_spec.rb +1 -1
- data/spec/rubocop/cop/style/ascii_comments_spec.rb +2 -2
- data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +2 -2
- data/spec/rubocop/cop/style/attr_spec.rb +1 -1
- 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_nesting_spec.rb +3 -3
- data/spec/rubocop/cop/style/blocks_spec.rb +25 -1
- data/spec/rubocop/cop/style/case_equality_spec.rb +1 -1
- data/spec/rubocop/cop/style/case_indentation_spec.rb +5 -5
- data/spec/rubocop/cop/style/character_literal_spec.rb +1 -1
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +1 -1
- data/spec/rubocop/cop/style/class_methods_spec.rb +1 -1
- data/spec/rubocop/cop/style/class_vars_spec.rb +25 -0
- data/spec/rubocop/cop/style/collection_methods_spec.rb +5 -6
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +0 -3
- data/spec/rubocop/cop/style/comment_annotation_spec.rb +20 -18
- data/spec/rubocop/cop/style/constant_name_spec.rb +1 -1
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/documentation_spec.rb +1 -1
- data/spec/rubocop/cop/style/dot_position_spec.rb +5 -5
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +35 -4
- data/spec/rubocop/cop/style/empty_lines_spec.rb +1 -1
- data/spec/rubocop/cop/style/empty_literal_spec.rb +7 -7
- data/spec/rubocop/cop/style/encoding_spec.rb +11 -5
- data/spec/rubocop/cop/style/end_block_spec.rb +1 -1
- data/spec/rubocop/cop/style/end_of_line_spec.rb +4 -3
- data/spec/rubocop/cop/style/even_odd_spec.rb +1 -1
- data/spec/rubocop/cop/style/favor_join_spec.rb +2 -2
- data/spec/rubocop/cop/style/favor_modifier_spec.rb +13 -10
- data/spec/rubocop/cop/style/favor_sprintf_spec.rb +4 -4
- data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +1 -1
- data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +4 -4
- data/spec/rubocop/cop/style/final_newline_spec.rb +25 -0
- data/spec/rubocop/cop/style/{avoid_for_spec.rb → for_spec.rb} +8 -12
- data/spec/rubocop/cop/style/{avoid_global_vars_spec.rb → global_vars_spec.rb} +13 -3
- data/spec/rubocop/cop/style/hash_methods_spec.rb +1 -1
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +20 -9
- data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +3 -3
- data/spec/rubocop/cop/style/indentation_width_spec.rb +19 -19
- data/spec/rubocop/cop/style/lambda_spec.rb +6 -6
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +1 -1
- data/spec/rubocop/cop/style/line_length_spec.rb +3 -3
- data/spec/rubocop/cop/style/method_and_variable_snake_case_spec.rb +8 -9
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/method_length_spec.rb +18 -17
- data/spec/rubocop/cop/style/module_function_spec.rb +1 -1
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +84 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +2 -2
- data/spec/rubocop/cop/style/nil_comparison_spec.rb +1 -1
- data/spec/rubocop/cop/style/not_spec.rb +1 -1
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +15 -25
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +2 -2
- data/spec/rubocop/cop/style/op_method_spec.rb +3 -3
- data/spec/rubocop/cop/style/parameter_lists_spec.rb +5 -5
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +4 -8
- data/spec/rubocop/cop/style/perl_backrefs_spec.rb +23 -0
- data/spec/rubocop/cop/style/proc_spec.rb +1 -1
- data/spec/rubocop/cop/style/reduce_arguments_spec.rb +18 -11
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +1 -1
- data/spec/rubocop/cop/style/redundant_return_spec.rb +16 -1
- data/spec/rubocop/cop/style/redundant_self_spec.rb +6 -1
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +19 -23
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +3 -3
- data/spec/rubocop/cop/style/semicolon_spec.rb +3 -3
- data/spec/rubocop/cop/style/signal_exception_spec.rb +1 -1
- data/spec/rubocop/cop/style/single_line_methods_spec.rb +22 -18
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_around_braces_spec.rb +13 -12
- data/spec/rubocop/cop/style/space_around_equals_in_default_parameter_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +25 -25
- data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +53 -0
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +9 -9
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +47 -61
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +4 -4
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +52 -0
- data/spec/rubocop/cop/style/string_literals_spec.rb +5 -5
- data/spec/rubocop/cop/style/symbol_array_spec.rb +1 -1
- data/spec/rubocop/cop/style/symbol_name_spec.rb +27 -18
- data/spec/rubocop/cop/style/tab_spec.rb +1 -1
- data/spec/rubocop/cop/style/ternary_operator_spec.rb +2 -2
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +24 -0
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +7 -7
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +6 -14
- data/spec/rubocop/cop/style/unless_else_spec.rb +3 -3
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +5 -5
- data/spec/rubocop/cop/style/when_then_spec.rb +15 -15
- data/spec/rubocop/cop/style/while_until_do_spec.rb +3 -3
- data/spec/rubocop/cop/style/word_array_spec.rb +1 -1
- data/spec/rubocop/cop/team_spec.rb +158 -0
- data/spec/rubocop/cop/variable_inspector/assignment_spec.rb +217 -0
- data/spec/rubocop/cop/variable_inspector/locatable_spec.rb +740 -0
- data/spec/rubocop/cop/variable_inspector/scope_spec.rb +191 -0
- data/spec/rubocop/cop/variable_inspector/variable_spec.rb +79 -0
- data/spec/rubocop/cop/variable_inspector/variable_table_spec.rb +275 -0
- data/spec/rubocop/cop/variable_inspector_spec.rb +13 -533
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +4 -4
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -1
- data/spec/support/ast_helper.rb +15 -0
- data/spec/support/shared_context.rb +18 -0
- data/spec/support/shared_examples.rb +1 -1
- metadata +95 -32
- checksums.yaml +0 -7
- data/lib/rubocop/cop/lint/unused_local_variable.rb +0 -32
- data/lib/rubocop/cop/style/avoid_perl_backrefs.rb +0 -19
- data/spec/rubocop/cop/lint/unused_local_variable_spec.rb +0 -588
- data/spec/rubocop/cop/style/avoid_class_vars_spec.rb +0 -27
- data/spec/rubocop/cop/style/avoid_perl_backrefs_spec.rb +0 -20
- data/spec/rubocop/cop/style/avoid_perlisms_spec.rb +0 -47
@@ -6,9 +6,9 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe Semicolon do
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
subject(:s) { Semicolon.new }
|
10
|
+
let(:cop_config) do
|
11
|
+
{
|
12
12
|
'AllowAfterParameterListInOneLineMethods' => false,
|
13
13
|
'AllowBeforeEndInOneLineMethods' => true
|
14
14
|
}
|
@@ -5,35 +5,39 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
|
-
describe SingleLineMethods do
|
9
|
-
|
10
|
-
|
11
|
-
SingleLineMethods.config = { 'AllowIfMethodIsEmpty' => true }
|
12
|
-
end
|
8
|
+
describe SingleLineMethods, :config do
|
9
|
+
subject(:slm) { SingleLineMethods.new(config) }
|
10
|
+
let(:cop_config) { { 'AllowIfMethodIsEmpty' => true } }
|
13
11
|
|
14
12
|
it 'registers an offence for a single-line method' do
|
15
13
|
inspect_source(slm,
|
16
14
|
['def some_method; body end',
|
17
15
|
'def link_to(name, url); {:name => name}; end',
|
18
16
|
'def @table.columns; super; end'])
|
19
|
-
expect(slm.
|
17
|
+
expect(slm.messages).to eq(
|
20
18
|
[SingleLineMethods::MSG] * 3)
|
21
19
|
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
context 'when AllowIfMethodIsEmpty is disabled' do
|
22
|
+
let(:cop_config) { { 'AllowIfMethodIsEmpty' => false } }
|
23
|
+
|
24
|
+
it 'registers an offence for an empty method' do
|
25
|
+
inspect_source(slm, ['def no_op; end',
|
26
|
+
'def self.resource_class=(klass); end',
|
27
|
+
'def @table.columns; end'])
|
28
|
+
expect(slm.offences.size).to eq(3)
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
context 'when AllowIfMethodIsEmpty is enabled' do
|
33
|
+
let(:cop_config) { { 'AllowIfMethodIsEmpty' => true } }
|
34
|
+
|
35
|
+
it 'accepts a single-line empty method' do
|
36
|
+
inspect_source(slm, ['def no_op; end',
|
37
|
+
'def self.resource_class=(klass); end',
|
38
|
+
'def @table.columns; end'])
|
39
|
+
expect(slm.offences).to be_empty
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
it 'accepts a multi-line method' do
|
@@ -6,22 +6,22 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe SpaceAfterColon do
|
9
|
-
|
9
|
+
subject(:space) { SpaceAfterColon.new }
|
10
10
|
|
11
11
|
it 'registers an offence for colon without space after it' do
|
12
12
|
inspect_source(space, ['x = w ? {a:3}:4'])
|
13
|
-
expect(space.
|
13
|
+
expect(space.messages).to eq(
|
14
14
|
['Space missing after colon.'] * 2)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'allows the colons in symbols' do
|
18
18
|
inspect_source(space, ['x = :a'])
|
19
|
-
expect(space.
|
19
|
+
expect(space.messages).to be_empty
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'allows colons in strings' do
|
23
23
|
inspect_source(space, ["str << ':'"])
|
24
|
-
expect(space.
|
24
|
+
expect(space.messages).to be_empty
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -6,23 +6,23 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe SpaceAfterComma do
|
9
|
-
|
9
|
+
subject(:space) { SpaceAfterComma.new }
|
10
10
|
|
11
11
|
it 'registers an offence for block argument commas without space' do
|
12
12
|
inspect_source(space, ['each { |s,t| }'])
|
13
|
-
expect(space.
|
13
|
+
expect(space.messages).to eq(
|
14
14
|
['Space missing after comma.'])
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'registers an offence for array index commas without space' do
|
18
18
|
inspect_source(space, ['formats[0,1]'])
|
19
|
-
expect(space.
|
19
|
+
expect(space.messages).to eq(
|
20
20
|
['Space missing after comma.'])
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'registers an offence for method call arg commas without space' do
|
24
24
|
inspect_source(space, ['a(1,2)'])
|
25
|
-
expect(space.
|
25
|
+
expect(space.messages).to eq(
|
26
26
|
['Space missing after comma.'])
|
27
27
|
end
|
28
28
|
end
|
@@ -6,17 +6,17 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe SpaceAfterSemicolon do
|
9
|
-
|
9
|
+
subject(:space) { SpaceAfterSemicolon.new }
|
10
10
|
|
11
11
|
it 'registers an offence for semicolon without space after it' do
|
12
12
|
inspect_source(space, ['x = 1;y = 2'])
|
13
|
-
expect(space.
|
13
|
+
expect(space.messages).to eq(
|
14
14
|
['Space missing after semicolon.'])
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'does not crash if semicolon is the last character of the file' do
|
18
18
|
inspect_source(space, ['x = 1;'])
|
19
|
-
expect(space.
|
19
|
+
expect(space.messages).to be_empty
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -6,42 +6,43 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe SpaceAroundBraces do
|
9
|
-
|
9
|
+
subject(:cop) { SpaceAroundBraces.new }
|
10
10
|
|
11
11
|
it 'registers an offence for left brace without spaces' do
|
12
|
-
inspect_source(
|
13
|
-
expect(
|
14
|
-
|
12
|
+
inspect_source(cop, ['each{ puts }'])
|
13
|
+
expect(cop.messages).to eq(["Surrounding space missing for '{'."])
|
14
|
+
expect(cop.highlights).to eq(['{'])
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'registers an offence for right brace without inner space' do
|
18
|
-
inspect_source(
|
19
|
-
expect(
|
18
|
+
inspect_source(cop, ['each { puts}'])
|
19
|
+
expect(cop.messages).to eq(
|
20
20
|
["Space missing to the left of '}'."])
|
21
|
+
expect(cop.highlights).to eq(['}'])
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'accepts an empty hash literal with no space inside' do
|
24
|
-
inspect_source(
|
25
|
+
inspect_source(cop,
|
25
26
|
['view_hash.each do |view_key|',
|
26
27
|
'end',
|
27
28
|
'@views = {}',
|
28
29
|
''])
|
29
|
-
expect(
|
30
|
+
expect(cop.messages).to be_empty
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'accepts string interpolation braces with no space inside' do
|
33
|
-
inspect_source(
|
34
|
+
inspect_source(cop,
|
34
35
|
['"A=#{a}"',
|
35
36
|
':"#{b}"',
|
36
37
|
'/#{c}/',
|
37
38
|
'`#{d}`',
|
38
39
|
'sprintf("#{message.gsub(/%/, \'%%\')}", line)'])
|
39
|
-
expect(
|
40
|
+
expect(cop.messages).to be_empty
|
40
41
|
end
|
41
42
|
|
42
43
|
it 'accepts braces around a hash literal argument' do
|
43
|
-
inspect_source(
|
44
|
-
expect(
|
44
|
+
inspect_source(cop, ["new({'user' => user_params})"])
|
45
|
+
expect(cop.messages).to be_empty
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
@@ -6,11 +6,11 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe SpaceAroundEqualsInParameterDefault do
|
9
|
-
|
9
|
+
subject(:space) { SpaceAroundEqualsInParameterDefault.new }
|
10
10
|
|
11
11
|
it 'registers an offence for default value assignment without space' do
|
12
12
|
inspect_source(space, ['def f(x, y=0, z=1)', 'end'])
|
13
|
-
expect(space.
|
13
|
+
expect(space.messages).to eq(
|
14
14
|
['Surrounding space missing in default value assignment.'] * 2)
|
15
15
|
end
|
16
16
|
|
@@ -26,7 +26,7 @@ module Rubocop
|
|
26
26
|
|
27
27
|
it 'accepts default value assignment with space' do
|
28
28
|
inspect_source(space, ['def f(x, y = 0, z = {})', 'end'])
|
29
|
-
expect(space.
|
29
|
+
expect(space.messages).to be_empty
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -6,17 +6,17 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe SpaceAroundOperators do
|
9
|
-
|
9
|
+
subject(:space) { SpaceAroundOperators.new }
|
10
10
|
|
11
11
|
it 'registers an offence for assignment without space on both sides' do
|
12
12
|
inspect_source(space, ['x=0', 'y= 0', 'z =0'])
|
13
|
-
expect(space.
|
13
|
+
expect(space.messages).to eq(
|
14
14
|
["Surrounding space missing for operator '='."] * 3)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'registers an offence for ternary operator without space' do
|
18
18
|
inspect_source(space, ['x == 0?1:2'])
|
19
|
-
expect(space.
|
19
|
+
expect(space.messages).to eq(
|
20
20
|
["Surrounding space missing for operator '?'.",
|
21
21
|
"Surrounding space missing for operator ':'."])
|
22
22
|
end
|
@@ -42,13 +42,13 @@ module Rubocop
|
|
42
42
|
'c=2']
|
43
43
|
inspect_source(space, src)
|
44
44
|
expect(space.offences.map(&:line)).to eq([1, 2])
|
45
|
-
expect(space.
|
45
|
+
expect(space.messages).to eq(
|
46
46
|
["Surrounding space missing for operator '='."] * 2)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'registers an offence for binary operators that could be unary' do
|
50
50
|
inspect_source(space, ['a-3', 'x&0xff', 'z+0'])
|
51
|
-
expect(space.
|
51
|
+
expect(space.messages).to eq(
|
52
52
|
["Surrounding space missing for operator '-'.",
|
53
53
|
"Surrounding space missing for operator '&'.",
|
54
54
|
"Surrounding space missing for operator '+'."])
|
@@ -56,35 +56,35 @@ module Rubocop
|
|
56
56
|
|
57
57
|
it 'registers an offence for arguments to a method' do
|
58
58
|
inspect_source(space, ['puts 1+2'])
|
59
|
-
expect(space.
|
59
|
+
expect(space.messages).to eq(
|
60
60
|
["Surrounding space missing for operator '+'."])
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'accepts operator symbols' do
|
64
64
|
inspect_source(space, ['func(:-)'])
|
65
|
-
expect(space.
|
65
|
+
expect(space.messages).to be_empty
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'accepts ranges' do
|
69
69
|
inspect_source(space, ['a, b = (1..2), (1...3)'])
|
70
|
-
expect(space.
|
70
|
+
expect(space.messages).to be_empty
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'accepts scope operator' do
|
74
74
|
source = ['@io.class == Zlib::GzipWriter']
|
75
75
|
inspect_source(space, source)
|
76
|
-
expect(space.
|
76
|
+
expect(space.messages).to be_empty
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'accepts ::Kernel::raise' do
|
80
80
|
source = ['::Kernel::raise IllegalBlockError.new']
|
81
81
|
inspect_source(space, source)
|
82
|
-
expect(space.
|
82
|
+
expect(space.messages).to be_empty
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'accepts exclamation point negation' do
|
86
86
|
inspect_source(space, ['x = !a&&!b'])
|
87
|
-
expect(space.
|
87
|
+
expect(space.messages).to eq(
|
88
88
|
["Surrounding space missing for operator '&&'."])
|
89
89
|
end
|
90
90
|
|
@@ -93,7 +93,7 @@ module Rubocop
|
|
93
93
|
' !__getobj__',
|
94
94
|
' end'])
|
95
95
|
expect(space.offences).to be_empty
|
96
|
-
expect(space.
|
96
|
+
expect(space.messages).to be_empty
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'accepts a unary' do
|
@@ -109,25 +109,25 @@ module Rubocop
|
|
109
109
|
' def each *args',
|
110
110
|
' end',
|
111
111
|
''])
|
112
|
-
expect(space.
|
112
|
+
expect(space.messages).to be_empty
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'accepts splat operator' do
|
116
116
|
inspect_source(space, ['return *list if options'])
|
117
|
-
expect(space.
|
117
|
+
expect(space.messages).to be_empty
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'accepts def of operator' do
|
121
121
|
inspect_source(space, ['def +(other); end',
|
122
122
|
'def self.===(other); end'])
|
123
|
-
expect(space.
|
123
|
+
expect(space.messages).to be_empty
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'accepts an operator at the end of a line' do
|
127
127
|
inspect_source(space,
|
128
128
|
["['Favor unless over if for negative ' +",
|
129
129
|
" 'conditions.'] * 2"])
|
130
|
-
expect(space.
|
130
|
+
expect(space.messages).to eq([])
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'accepts an assignment with spaces' do
|
@@ -144,7 +144,7 @@ module Rubocop
|
|
144
144
|
inspect_source(space,
|
145
145
|
['x+= a+b-c*d/e%f^g|h&i||j',
|
146
146
|
'y -=k&&l'])
|
147
|
-
expect(space.
|
147
|
+
expect(space.messages)
|
148
148
|
.to eq(["Surrounding space missing for operator '+='.",
|
149
149
|
"Surrounding space missing for operator '+'.",
|
150
150
|
"Surrounding space missing for operator '-'.",
|
@@ -163,14 +163,14 @@ module Rubocop
|
|
163
163
|
inspect_source(space,
|
164
164
|
['x += a + b - c * d / e % f ^ g | h & i || j',
|
165
165
|
'y -= k && l'])
|
166
|
-
expect(space.
|
166
|
+
expect(space.messages).to eq([])
|
167
167
|
end
|
168
168
|
|
169
169
|
it "accepts some operators that are exceptions & don't need spaces" do
|
170
170
|
inspect_source(space, ['(1..3)',
|
171
171
|
'ActionController::Base',
|
172
172
|
'each { |s, t| }'])
|
173
|
-
expect(space.
|
173
|
+
expect(space.messages).to eq([])
|
174
174
|
end
|
175
175
|
|
176
176
|
it 'accepts an assignment followed by newline' do
|
@@ -180,7 +180,7 @@ module Rubocop
|
|
180
180
|
|
181
181
|
it 'registers an offences for exponent operator with spaces' do
|
182
182
|
inspect_source(space, ['x = a * b ** 2'])
|
183
|
-
expect(space.
|
183
|
+
expect(space.messages).to eq(
|
184
184
|
['Space around operator ** detected.'])
|
185
185
|
end
|
186
186
|
|
@@ -191,9 +191,9 @@ module Rubocop
|
|
191
191
|
|
192
192
|
it 'accepts unary operators without space' do
|
193
193
|
inspect_source(space, ['[].map(&:size)',
|
194
|
-
|
195
|
-
|
196
|
-
expect(space.
|
194
|
+
'-3',
|
195
|
+
'x = +2'])
|
196
|
+
expect(space.messages).to eq([])
|
197
197
|
end
|
198
198
|
|
199
199
|
it 'accepts argument default values without space' do
|
@@ -202,13 +202,13 @@ module Rubocop
|
|
202
202
|
inspect_source(space,
|
203
203
|
['def init(name=nil)',
|
204
204
|
'end'])
|
205
|
-
expect(space.
|
205
|
+
expect(space.messages).to be_empty
|
206
206
|
end
|
207
207
|
|
208
208
|
it 'accepts the construct class <<self with no space after <<' do
|
209
209
|
inspect_source(space, ['class <<self',
|
210
210
|
'end'])
|
211
|
-
expect(space.
|
211
|
+
expect(space.messages).to be_empty
|
212
212
|
end
|
213
213
|
end
|
214
214
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
module Style
|
8
|
+
describe SpaceBeforeModifierKeyword do
|
9
|
+
subject(:cop) { described_class.new }
|
10
|
+
|
11
|
+
it 'registers an offence for missing space before if/unless' do
|
12
|
+
inspect_source(cop, ['(a = 3)if a == 2',
|
13
|
+
'a = "test"if a == 2',
|
14
|
+
'a = 42unless a == 2',
|
15
|
+
'a = [1,2,3]unless a == 2',
|
16
|
+
'a = {:a => "b"}if a == 2'])
|
17
|
+
expect(cop.highlights).to eq([')', '"', '2', ']', '}'])
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'registers an offence for missing space before while/until' do
|
21
|
+
inspect_source(cop, ['(a = 3)while b',
|
22
|
+
'a = "test"until b',
|
23
|
+
'a = 42while b',
|
24
|
+
'a = [1,2,3]until b',
|
25
|
+
'a = {:a => "b"}while b'])
|
26
|
+
expect(cop.highlights).to eq([')', '"', '2', ']', '}'])
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'accepts modifiers with preceding space' do
|
30
|
+
inspect_source(cop, ['(a = 3) if b',
|
31
|
+
'a = "test" unless b',
|
32
|
+
'a = 42 while b',
|
33
|
+
'a = [1,2,3] until b'])
|
34
|
+
expect(cop.offences).to be_empty
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'accepts elsif at beginning of line' do
|
38
|
+
inspect_source(cop, ["if RUBY_VERSION.between?('1.9.2', '2.0.0')",
|
39
|
+
" require 'testing/performance/ruby/yarv'",
|
40
|
+
'elsif RUBY_VERSION.between?("1.8.6", "1.9")',
|
41
|
+
" require 'testing/performance/ruby/mri'",
|
42
|
+
'end'])
|
43
|
+
expect(cop.highlights).to eq([])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'does not crash on ternary conditionals' do
|
47
|
+
inspect_source(cop, 'a ? b : c')
|
48
|
+
expect(cop.offences).to be_empty
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|