ridecharge-rubocop 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/.travis.yml +14 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +22 -0
- data/bin/ridecharge-rubocop +49 -0
- data/config/0default.yml +8 -0
- data/config/fleet-magic-todo.yml +380 -0
- data/config/rc-todo.yml +190 -0
- data/config/ridecharge-rubocop_todo.yml +73 -0
- data/config/rubocop/default.yml +308 -0
- data/config/rubocop/disabled.yml +9 -0
- data/config/rubocop/enabled.yml +648 -0
- data/config/standard-todo.yml +24 -0
- data/config/tabs.yml +15 -0
- data/config/vehicle-todo.yml +195 -0
- data/lib/ridecharge/rubocop.rb +2 -0
- data/lib/ridecharge/rubocop/version.rb +5 -0
- data/lib/rubocop/config_loader_monkeypatch.rb +117 -0
- data/lib/rubocop/ridecharge.rb +1 -0
- data/ridecharge-rubocop.gemspec +25 -0
- data/spec/isolated_environment_spec.rb +24 -0
- data/spec/project_spec.rb +118 -0
- data/spec/rubocop/cli_spec.rb +1385 -0
- data/spec/rubocop/config_loader_spec.rb +328 -0
- data/spec/rubocop/config_spec.rb +179 -0
- data/spec/rubocop/config_store_spec.rb +53 -0
- data/spec/rubocop/cop/commissioner_spec.rb +83 -0
- data/spec/rubocop/cop/cop_spec.rb +114 -0
- data/spec/rubocop/cop/corrector_spec.rb +59 -0
- data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +113 -0
- data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +35 -0
- data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +107 -0
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +411 -0
- data/spec/rubocop/cop/lint/condition_position_spec.rb +49 -0
- data/spec/rubocop/cop/lint/debugger_spec.rb +39 -0
- data/spec/rubocop/cop/lint/else_layout_spec.rb +65 -0
- data/spec/rubocop/cop/lint/empty_ensure_spec.rb +27 -0
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +136 -0
- data/spec/rubocop/cop/lint/end_in_method_spec.rb +29 -0
- data/spec/rubocop/cop/lint/ensure_return_spec.rb +39 -0
- data/spec/rubocop/cop/lint/eval_spec.rb +35 -0
- data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +30 -0
- data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +33 -0
- data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +63 -0
- data/spec/rubocop/cop/lint/loop_spec.rb +27 -0
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +57 -0
- data/spec/rubocop/cop/lint/require_parentheses_spec.rb +82 -0
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +131 -0
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +237 -0
- data/spec/rubocop/cop/lint/syntax_spec.rb +34 -0
- data/spec/rubocop/cop/lint/unreachable_code_spec.rb +63 -0
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +1570 -0
- data/spec/rubocop/cop/lint/useless_comparison_spec.rb +30 -0
- data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +48 -0
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +149 -0
- data/spec/rubocop/cop/lint/void_spec.rb +57 -0
- data/spec/rubocop/cop/offence_spec.rb +133 -0
- data/spec/rubocop/cop/rails/default_scope_spec.rb +37 -0
- data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +13 -0
- data/spec/rubocop/cop/rails/output_spec.rb +41 -0
- data/spec/rubocop/cop/rails/read_attribute_spec.rb +13 -0
- data/spec/rubocop/cop/rails/validation_spec.rb +21 -0
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +361 -0
- data/spec/rubocop/cop/style/accessor_method_name_spec.rb +81 -0
- data/spec/rubocop/cop/style/alias_spec.rb +59 -0
- data/spec/rubocop/cop/style/align_array_spec.rb +75 -0
- data/spec/rubocop/cop/style/align_hash_spec.rb +310 -0
- data/spec/rubocop/cop/style/align_parameters_spec.rb +222 -0
- data/spec/rubocop/cop/style/and_or_spec.rb +57 -0
- data/spec/rubocop/cop/style/ascii_comments_spec.rb +22 -0
- data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +36 -0
- data/spec/rubocop/cop/style/attr_spec.rb +19 -0
- data/spec/rubocop/cop/style/begin_block_spec.rb +13 -0
- data/spec/rubocop/cop/style/block_comments_spec.rb +21 -0
- data/spec/rubocop/cop/style/block_nesting_spec.rb +156 -0
- data/spec/rubocop/cop/style/blocks_spec.rb +99 -0
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +284 -0
- data/spec/rubocop/cop/style/case_equality_spec.rb +12 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +289 -0
- data/spec/rubocop/cop/style/character_literal_spec.rb +37 -0
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +40 -0
- data/spec/rubocop/cop/style/class_length_spec.rb +131 -0
- data/spec/rubocop/cop/style/class_methods_spec.rb +45 -0
- data/spec/rubocop/cop/style/class_vars_spec.rb +19 -0
- data/spec/rubocop/cop/style/collection_methods_spec.rb +48 -0
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +60 -0
- data/spec/rubocop/cop/style/comment_annotation_spec.rb +86 -0
- data/spec/rubocop/cop/style/constant_name_spec.rb +65 -0
- data/spec/rubocop/cop/style/cyclomatic_complexity_spec.rb +204 -0
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +39 -0
- data/spec/rubocop/cop/style/documentation_spec.rb +123 -0
- data/spec/rubocop/cop/style/dot_position_spec.rb +94 -0
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +127 -0
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +56 -0
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +131 -0
- data/spec/rubocop/cop/style/empty_lines_spec.rb +40 -0
- data/spec/rubocop/cop/style/empty_literal_spec.rb +100 -0
- data/spec/rubocop/cop/style/encoding_spec.rb +56 -0
- data/spec/rubocop/cop/style/end_block_spec.rb +13 -0
- data/spec/rubocop/cop/style/end_of_line_spec.rb +47 -0
- data/spec/rubocop/cop/style/even_odd_spec.rb +75 -0
- data/spec/rubocop/cop/style/favor_join_spec.rb +31 -0
- data/spec/rubocop/cop/style/favor_sprintf_spec.rb +47 -0
- data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +76 -0
- data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +41 -0
- data/spec/rubocop/cop/style/final_newline_spec.rb +30 -0
- data/spec/rubocop/cop/style/flip_flop_spec.rb +23 -0
- data/spec/rubocop/cop/style/for_spec.rb +105 -0
- data/spec/rubocop/cop/style/global_vars_spec.rb +34 -0
- data/spec/rubocop/cop/style/hash_methods_spec.rb +45 -0
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +131 -0
- data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +128 -0
- data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +19 -0
- data/spec/rubocop/cop/style/indentation_consistency_spec.rb +490 -0
- data/spec/rubocop/cop/style/indentation_width_spec.rb +470 -0
- data/spec/rubocop/cop/style/lambda_call_spec.rb +65 -0
- data/spec/rubocop/cop/style/lambda_spec.rb +41 -0
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +64 -0
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +34 -0
- data/spec/rubocop/cop/style/line_length_spec.rb +20 -0
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +59 -0
- data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +60 -0
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +106 -0
- data/spec/rubocop/cop/style/method_length_spec.rb +147 -0
- data/spec/rubocop/cop/style/method_name_spec.rb +125 -0
- data/spec/rubocop/cop/style/module_function_spec.rb +24 -0
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +78 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +107 -0
- data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +18 -0
- data/spec/rubocop/cop/style/nested_ternary_operator_spec.rb +21 -0
- data/spec/rubocop/cop/style/nil_comparison_spec.rb +30 -0
- data/spec/rubocop/cop/style/not_spec.rb +22 -0
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +64 -0
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +13 -0
- data/spec/rubocop/cop/style/op_method_spec.rb +74 -0
- data/spec/rubocop/cop/style/parameter_lists_spec.rb +44 -0
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +122 -0
- data/spec/rubocop/cop/style/perl_backrefs_spec.rb +17 -0
- data/spec/rubocop/cop/style/predicate_name_spec.rb +25 -0
- data/spec/rubocop/cop/style/proc_spec.rb +27 -0
- data/spec/rubocop/cop/style/raise_args_spec.rb +82 -0
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +57 -0
- data/spec/rubocop/cop/style/redundant_exception_spec.rb +27 -0
- data/spec/rubocop/cop/style/redundant_return_spec.rb +171 -0
- data/spec/rubocop/cop/style/redundant_self_spec.rb +142 -0
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +83 -0
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +116 -0
- data/spec/rubocop/cop/style/semicolon_spec.rb +100 -0
- data/spec/rubocop/cop/style/signal_exception_spec.rb +266 -0
- data/spec/rubocop/cop/style/single_line_block_params_spec.rb +68 -0
- data/spec/rubocop/cop/style/single_line_methods_spec.rb +52 -0
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +38 -0
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +30 -0
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +84 -0
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +70 -0
- data/spec/rubocop/cop/style/space_after_not_spec.rb +22 -0
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +23 -0
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +283 -0
- data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +33 -0
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +325 -0
- data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +70 -0
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +52 -0
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +138 -0
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +34 -0
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +56 -0
- data/spec/rubocop/cop/style/string_literals_spec.rb +212 -0
- data/spec/rubocop/cop/style/symbol_array_spec.rb +37 -0
- data/spec/rubocop/cop/style/tab_spec.rb +17 -0
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +43 -0
- data/spec/rubocop/cop/style/trailing_comma_spec.rb +230 -0
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +30 -0
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +415 -0
- data/spec/rubocop/cop/style/unless_else_spec.rb +25 -0
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +47 -0
- data/spec/rubocop/cop/style/variable_name_spec.rb +107 -0
- data/spec/rubocop/cop/style/when_then_spec.rb +41 -0
- data/spec/rubocop/cop/style/while_until_do_spec.rb +53 -0
- data/spec/rubocop/cop/style/while_until_modifier_spec.rb +75 -0
- data/spec/rubocop/cop/style/word_array_spec.rb +97 -0
- data/spec/rubocop/cop/team_spec.rb +156 -0
- data/spec/rubocop/cop/util_spec.rb +49 -0
- data/spec/rubocop/cop/variable_inspector/assignment_spec.rb +213 -0
- data/spec/rubocop/cop/variable_inspector/locatable_spec.rb +734 -0
- data/spec/rubocop/cop/variable_inspector/scope_spec.rb +184 -0
- data/spec/rubocop/cop/variable_inspector/variable_spec.rb +73 -0
- data/spec/rubocop/cop/variable_inspector/variable_table_spec.rb +269 -0
- data/spec/rubocop/cop/variable_inspector_spec.rb +29 -0
- data/spec/rubocop/file_inspector_spec.rb +78 -0
- data/spec/rubocop/formatter/base_formatter_spec.rb +191 -0
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +114 -0
- data/spec/rubocop/formatter/colorizable_spec.rb +107 -0
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +50 -0
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +62 -0
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +33 -0
- data/spec/rubocop/formatter/formatter_set_spec.rb +132 -0
- data/spec/rubocop/formatter/json_formatter_spec.rb +148 -0
- data/spec/rubocop/formatter/offence_count_formatter_spec.rb +52 -0
- data/spec/rubocop/formatter/progress_formatter_spec.rb +182 -0
- data/spec/rubocop/formatter/simple_text_formatter_spec.rb +123 -0
- data/spec/rubocop/options_spec.rb +145 -0
- data/spec/rubocop/path_util_spec.rb +42 -0
- data/spec/rubocop/processed_source_spec.rb +114 -0
- data/spec/rubocop/source_parser_spec.rb +139 -0
- data/spec/rubocop/target_finder_spec.rb +180 -0
- data/spec/rubocop/token_spec.rb +25 -0
- data/spec/spec_helper.rb +136 -0
- data/spec/support/ast_helper.rb +15 -0
- data/spec/support/file_helper.rb +21 -0
- data/spec/support/isolated_environment.rb +34 -0
- data/spec/support/mri_syntax_checker.rb +73 -0
- data/spec/support/shared_context.rb +22 -0
- data/spec/support/shared_examples.rb +33 -0
- data/spec/support/statement_modifier_helper.rb +41 -0
- metadata +511 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceAroundEqualsInParameterDefault do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for default value assignment without space' do
|
9
|
+
inspect_source(cop, ['def f(x, y=0, z=1)', 'end'])
|
10
|
+
expect(cop.messages).to eq(
|
11
|
+
['Surrounding space missing in default value assignment.'] * 2)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'registers an offence for assignment empty string without space' do
|
15
|
+
inspect_source(cop, ['def f(x, y="", z=1)', 'end'])
|
16
|
+
expect(cop.offences.size).to eq(2)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'registers an offence for assignment of empty list without space' do
|
20
|
+
inspect_source(cop, ['def f(x, y=[])', 'end'])
|
21
|
+
expect(cop.offences.size).to eq(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'accepts default value assignment with space' do
|
25
|
+
inspect_source(cop, ['def f(x, y = 0, z = {})', 'end'])
|
26
|
+
expect(cop.messages).to be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'auto-corrects missing space' do
|
30
|
+
new_source = autocorrect_source(cop, ['def f(x, y=0, z=1)', 'end'])
|
31
|
+
expect(new_source).to eq(['def f(x, y = 0, z = 1)', 'end'].join("\n"))
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,325 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceAroundOperators do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for assignment without space on both sides' do
|
9
|
+
inspect_source(cop, ['x=0', 'y= 0', 'z =0'])
|
10
|
+
expect(cop.messages).to eq(
|
11
|
+
["Surrounding space missing for operator '='."] * 3)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'auto-corrects assignment without space on both sides' do
|
15
|
+
new_source = autocorrect_source(cop, ['x=0', 'y= 0', 'z =0'])
|
16
|
+
expect(new_source).to eq(['x = 0', 'y = 0', 'z = 0'].join("\n"))
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'registers an offence for ternary operator without space' do
|
20
|
+
inspect_source(cop, ['x == 0?1:2'])
|
21
|
+
expect(cop.messages).to eq(
|
22
|
+
["Surrounding space missing for operator '?'.",
|
23
|
+
"Surrounding space missing for operator ':'."])
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'auto-corrects a ternary operator without space' do
|
27
|
+
new_source = autocorrect_source(cop, 'x == 0?1:2')
|
28
|
+
expect(new_source).to eq('x == 0 ? 1 : 2')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'registers an offence in presence of modifier if statement' do
|
32
|
+
check_modifier('if')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'registers an offence in presence of modifier unless statement' do
|
36
|
+
check_modifier('unless')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'registers an offence in presence of modifier while statement' do
|
40
|
+
check_modifier('unless')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'registers an offence in presence of modifier until statement' do
|
44
|
+
check_modifier('unless')
|
45
|
+
end
|
46
|
+
|
47
|
+
def check_modifier(keyword)
|
48
|
+
src = ["a=1 #{keyword} condition",
|
49
|
+
'c=2']
|
50
|
+
inspect_source(cop, src)
|
51
|
+
expect(cop.offences.map(&:line)).to eq([1, 2])
|
52
|
+
expect(cop.messages).to eq(
|
53
|
+
["Surrounding space missing for operator '='."] * 2)
|
54
|
+
|
55
|
+
new_source = autocorrect_source(cop, src)
|
56
|
+
expect(new_source)
|
57
|
+
.to eq(src.map { |line| line.sub(/=/, ' = ') }.join("\n"))
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'registers an offence for binary operators that could be unary' do
|
61
|
+
inspect_source(cop, ['a-3', 'x&0xff', 'z+0'])
|
62
|
+
expect(cop.messages).to eq(
|
63
|
+
["Surrounding space missing for operator '-'.",
|
64
|
+
"Surrounding space missing for operator '&'.",
|
65
|
+
"Surrounding space missing for operator '+'."])
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'auto-corrects missing space in binary operators that could be unary' do
|
69
|
+
new_source = autocorrect_source(cop, ['a-3', 'x&0xff', 'z+0'])
|
70
|
+
expect(new_source).to eq(['a - 3', 'x & 0xff', 'z + 0'].join("\n"))
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'registers an offence for arguments to a method' do
|
74
|
+
inspect_source(cop, ['puts 1+2'])
|
75
|
+
expect(cop.messages).to eq(
|
76
|
+
["Surrounding space missing for operator '+'."])
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'auto-corrects missing space in arguments to a method' do
|
80
|
+
new_source = autocorrect_source(cop, 'puts 1+2')
|
81
|
+
expect(new_source).to eq('puts 1 + 2')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'accepts operator surrounded by tabs' do
|
85
|
+
inspect_source(cop, ["a\t+\tb"])
|
86
|
+
expect(cop.messages).to be_empty
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'accepts operator symbols' do
|
90
|
+
inspect_source(cop, ['func(:-)'])
|
91
|
+
expect(cop.messages).to be_empty
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'accepts ranges' do
|
95
|
+
inspect_source(cop, ['a, b = (1..2), (1...3)'])
|
96
|
+
expect(cop.messages).to be_empty
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'accepts scope operator' do
|
100
|
+
source = ['@io.class == Zlib::GzipWriter']
|
101
|
+
inspect_source(cop, source)
|
102
|
+
expect(cop.messages).to be_empty
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'accepts ::Kernel::raise' do
|
106
|
+
source = ['::Kernel::raise IllegalBlockError.new']
|
107
|
+
inspect_source(cop, source)
|
108
|
+
expect(cop.messages).to be_empty
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'accepts exclamation point negation' do
|
112
|
+
inspect_source(cop, ['x = !a&&!b'])
|
113
|
+
expect(cop.messages).to eq(
|
114
|
+
["Surrounding space missing for operator '&&'."])
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'accepts exclamation point definition' do
|
118
|
+
inspect_source(cop, [' def !',
|
119
|
+
' !__getobj__',
|
120
|
+
' end'])
|
121
|
+
expect(cop.offences).to be_empty
|
122
|
+
expect(cop.messages).to be_empty
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'accepts a unary' do
|
126
|
+
inspect_source(cop,
|
127
|
+
[' def bm(label_width = 0, *labels, &blk)',
|
128
|
+
' benchmark(CAPTION, label_width, FORMAT,',
|
129
|
+
' *labels, &blk)',
|
130
|
+
' end',
|
131
|
+
'',
|
132
|
+
' def each &block',
|
133
|
+
' end',
|
134
|
+
'',
|
135
|
+
' def self.search *args',
|
136
|
+
' end',
|
137
|
+
'',
|
138
|
+
' def each *args',
|
139
|
+
' end',
|
140
|
+
''])
|
141
|
+
expect(cop.messages).to be_empty
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'accepts splat operator' do
|
145
|
+
inspect_source(cop, ['return *list if options'])
|
146
|
+
expect(cop.messages).to be_empty
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'accepts def of operator' do
|
150
|
+
inspect_source(cop, ['def +(other); end',
|
151
|
+
'def self.===(other); end'])
|
152
|
+
expect(cop.messages).to be_empty
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'accepts an operator at the end of a line' do
|
156
|
+
inspect_source(cop,
|
157
|
+
["['Favor unless over if for negative ' +",
|
158
|
+
" 'conditions.'] * 2"])
|
159
|
+
expect(cop.messages).to eq([])
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'accepts an assignment with spaces' do
|
163
|
+
inspect_source(cop, ['x = 0'])
|
164
|
+
expect(cop.offences).to be_empty
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'accepts an operator called with method syntax' do
|
168
|
+
inspect_source(cop, ['Date.today.+(1).to_s'])
|
169
|
+
expect(cop.offences).to be_empty
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'registers an offence for operators without spaces' do
|
173
|
+
inspect_source(cop,
|
174
|
+
['x+= a+b-c*d/e%f^g|h&i||j',
|
175
|
+
'y -=k&&l'])
|
176
|
+
expect(cop.messages)
|
177
|
+
.to eq(["Surrounding space missing for operator '+='.",
|
178
|
+
"Surrounding space missing for operator '+'.",
|
179
|
+
"Surrounding space missing for operator '-'.",
|
180
|
+
"Surrounding space missing for operator '*'.",
|
181
|
+
"Surrounding space missing for operator '/'.",
|
182
|
+
"Surrounding space missing for operator '%'.",
|
183
|
+
"Surrounding space missing for operator '^'.",
|
184
|
+
"Surrounding space missing for operator '|'.",
|
185
|
+
"Surrounding space missing for operator '&'.",
|
186
|
+
"Surrounding space missing for operator '||'.",
|
187
|
+
"Surrounding space missing for operator '-='.",
|
188
|
+
"Surrounding space missing for operator '&&'."])
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'auto-corrects missing space' do
|
192
|
+
new_source = autocorrect_source(cop, ['x+= a+b-c*d/e%f^g|h&i||j',
|
193
|
+
'y -=k&&l'])
|
194
|
+
expect(new_source).to eq(['x += a + b - c * d / e % f ^ g | h & i || j',
|
195
|
+
'y -= k && l'].join("\n"))
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'accepts operators with spaces' do
|
199
|
+
inspect_source(cop,
|
200
|
+
['x += a + b - c * d / e % f ^ g | h & i || j',
|
201
|
+
'y -= k && l'])
|
202
|
+
expect(cop.messages).to eq([])
|
203
|
+
end
|
204
|
+
|
205
|
+
it "accepts some operators that are exceptions & don't need spaces" do
|
206
|
+
inspect_source(cop, ['(1..3)',
|
207
|
+
'ActionController::Base',
|
208
|
+
'each { |s, t| }'])
|
209
|
+
expect(cop.messages).to eq([])
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'accepts an assignment followed by newline' do
|
213
|
+
inspect_source(cop, ['x =', '0'])
|
214
|
+
expect(cop.offences).to be_empty
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'registers an offences for exponent operator with spaces' do
|
218
|
+
inspect_source(cop, ['x = a * b ** 2'])
|
219
|
+
expect(cop.messages).to eq(
|
220
|
+
['Space around operator ** detected.'])
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'auto-corrects unwanted space around **' do
|
224
|
+
new_source = autocorrect_source(cop, ['x = a * b ** 2',
|
225
|
+
'y = a * b** 2'])
|
226
|
+
expect(new_source).to eq(['x = a * b**2',
|
227
|
+
'y = a * b**2'].join("\n"))
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'accepts exponent operator without spaces' do
|
231
|
+
inspect_source(cop, ['x = a * b**2'])
|
232
|
+
expect(cop.offences).to be_empty
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'registers an offence for a setter call without spaces' do
|
236
|
+
inspect_source(cop, ['x.y=2'])
|
237
|
+
expect(cop.messages).to eq(
|
238
|
+
["Surrounding space missing for operator '='."])
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'registers an offence for a hash rocket without spaces' do
|
242
|
+
inspect_source(cop, ['{ 1=>2, a: b }'])
|
243
|
+
expect(cop.messages).to eq(
|
244
|
+
["Surrounding space missing for operator '=>'."])
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'accepts unary operators without space' do
|
248
|
+
inspect_source(cop, ['[].map(&:size)',
|
249
|
+
'-3',
|
250
|
+
'arr.collect { |e| -e }',
|
251
|
+
'x = +2'])
|
252
|
+
expect(cop.messages).to eq([])
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'accepts [] without space' do
|
256
|
+
inspect_source(cop, ['files[2]'])
|
257
|
+
expect(cop.messages).to eq([])
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'accepts argument default values without space' do
|
261
|
+
# These are handled by SpaceAroundEqualsInParameterDefault,
|
262
|
+
# so SpaceAroundOperators leaves them alone.
|
263
|
+
inspect_source(cop,
|
264
|
+
['def init(name=nil)',
|
265
|
+
'end'])
|
266
|
+
expect(cop.messages).to be_empty
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'accepts the construct class <<self with no space after <<' do
|
270
|
+
inspect_source(cop, ['class <<self',
|
271
|
+
'end'])
|
272
|
+
expect(cop.messages).to be_empty
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'registers an offence for match operators without space' do
|
276
|
+
inspect_source(cop, ['x=~/abc/', 'y !~/abc/'])
|
277
|
+
expect(cop.messages)
|
278
|
+
.to eq(["Surrounding space missing for operator '=~'.",
|
279
|
+
"Surrounding space missing for operator '!~'."])
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'registers an offence for various assignments without space' do
|
283
|
+
inspect_source(cop, ['x||=0', 'y&&=0', 'z*=2',
|
284
|
+
'@a=0', '@@a=0', 'a,b=0', 'A=0', 'x[3]=0', '$A=0'])
|
285
|
+
expect(cop.messages)
|
286
|
+
.to eq(["Surrounding space missing for operator '||='.",
|
287
|
+
"Surrounding space missing for operator '&&='.",
|
288
|
+
"Surrounding space missing for operator '*='.",
|
289
|
+
"Surrounding space missing for operator '='.",
|
290
|
+
"Surrounding space missing for operator '='.",
|
291
|
+
"Surrounding space missing for operator '='.",
|
292
|
+
"Surrounding space missing for operator '='.",
|
293
|
+
"Surrounding space missing for operator '='.",
|
294
|
+
"Surrounding space missing for operator '='."])
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'registers an offence for equality operators without space' do
|
298
|
+
inspect_source(cop, ['x==0', 'y!=0', 'Hash===z'])
|
299
|
+
expect(cop.messages)
|
300
|
+
.to eq(["Surrounding space missing for operator '=='.",
|
301
|
+
"Surrounding space missing for operator '!='.",
|
302
|
+
"Surrounding space missing for operator '==='."])
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'registers an offence for - without space with negative lhs operand' do
|
306
|
+
inspect_source(cop, ['-1-arg'])
|
307
|
+
expect(cop.messages)
|
308
|
+
.to eq(["Surrounding space missing for operator '-'."])
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'registers an offence for inheritance < without space' do
|
312
|
+
inspect_source(cop, ['class ShowSourceTestClass<ShowSourceTestSuperClass',
|
313
|
+
'end'])
|
314
|
+
expect(cop.messages)
|
315
|
+
.to eq(["Surrounding space missing for operator '<'."])
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'registers an offence for hash rocket without space at rescue' do
|
319
|
+
inspect_source(cop, ['begin',
|
320
|
+
'rescue Exception=>e',
|
321
|
+
'end'])
|
322
|
+
expect(cop.messages)
|
323
|
+
.to eq(["Surrounding space missing for operator '=>'."])
|
324
|
+
end
|
325
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceBeforeModifierKeyword do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for missing space before if/unless' do
|
9
|
+
inspect_source(cop, ['(a = 3)if a == 2',
|
10
|
+
'a = "test"if a == 2',
|
11
|
+
'a = 42unless a == 2',
|
12
|
+
'a = [1,2,3]unless a == 2',
|
13
|
+
'a = {:a => "b"}if a == 2'])
|
14
|
+
expect(cop.highlights).to eq([')', '"', '2', ']', '}'])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'registers an offence for missing space before while/until' do
|
18
|
+
inspect_source(cop, ['(a = 3)while b',
|
19
|
+
'a = "test"until b',
|
20
|
+
'a = 42while b',
|
21
|
+
'a = [1,2,3]until b',
|
22
|
+
'a = {:a => "b"}while b'])
|
23
|
+
expect(cop.highlights).to eq([')', '"', '2', ']', '}'])
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'accepts modifiers with preceding space' do
|
27
|
+
inspect_source(cop, ['(a = 3) if b',
|
28
|
+
'a = "test" unless b',
|
29
|
+
'a = 42 while b',
|
30
|
+
'a = [1,2,3] until b'])
|
31
|
+
expect(cop.offences).to be_empty
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'accepts elsif at beginning of line' do
|
35
|
+
inspect_source(cop, ["if RUBY_VERSION.between?('1.9.2', '2.0.0')",
|
36
|
+
" require 'testing/performance/ruby/yarv'",
|
37
|
+
'elsif RUBY_VERSION.between?("1.8.6", "1.9")',
|
38
|
+
" require 'testing/performance/ruby/mri'",
|
39
|
+
'end'])
|
40
|
+
expect(cop.highlights).to eq([])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'does not crash on ternary conditionals' do
|
44
|
+
inspect_source(cop, 'a ? b : c')
|
45
|
+
expect(cop.offences).to be_empty
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'auto-corrects missing space' do
|
49
|
+
new_source = autocorrect_source(cop, ['(a = 3)if a == 2',
|
50
|
+
'a = "test"if a == 2',
|
51
|
+
'a = 42unless a == 2',
|
52
|
+
'a = [1,2,3]unless a == 2',
|
53
|
+
'a = {:a => "b"}if a == 2',
|
54
|
+
'(a = 3)while b',
|
55
|
+
'a = "test"until b',
|
56
|
+
'a = 42while b',
|
57
|
+
'a = [1,2,3]until b',
|
58
|
+
'a = {:a => "b"}while b'])
|
59
|
+
expect(new_source).to eq(['(a = 3) if a == 2',
|
60
|
+
'a = "test" if a == 2',
|
61
|
+
'a = 42 unless a == 2',
|
62
|
+
'a = [1,2,3] unless a == 2',
|
63
|
+
'a = {:a => "b"} if a == 2',
|
64
|
+
'(a = 3) while b',
|
65
|
+
'a = "test" until b',
|
66
|
+
'a = 42 while b',
|
67
|
+
'a = [1,2,3] until b',
|
68
|
+
'a = {:a => "b"} while b'].join("\n"))
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceInsideBrackets do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for an array literal with spaces inside' do
|
9
|
+
inspect_source(cop, ['a = [1, 2 ]',
|
10
|
+
'b = [ 1, 2]'])
|
11
|
+
expect(cop.messages).to eq(
|
12
|
+
['Space inside square brackets detected.',
|
13
|
+
'Space inside square brackets detected.'])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts space inside strings within square brackets' do
|
17
|
+
inspect_source(cop, ["['Encoding:',",
|
18
|
+
" ' Enabled: false']"])
|
19
|
+
expect(cop.messages).to be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'accepts space inside square brackets if on its own row' do
|
23
|
+
inspect_source(cop, ['a = [',
|
24
|
+
' 1, 2',
|
25
|
+
' ]'])
|
26
|
+
expect(cop.messages).to be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'accepts square brackets as method name' do
|
30
|
+
inspect_source(cop, ['def Vector.[](*array)',
|
31
|
+
'end'])
|
32
|
+
expect(cop.messages).to be_empty
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'accepts square brackets called with method call syntax' do
|
36
|
+
inspect_source(cop, ['subject.[](0)'])
|
37
|
+
expect(cop.messages).to be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'only reports a single space once' do
|
41
|
+
inspect_source(cop, ['[ ]'])
|
42
|
+
expect(cop.messages).to eq(
|
43
|
+
['Space inside square brackets detected.'])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'auto-corrects unwanted space' do
|
47
|
+
new_source = autocorrect_source(cop, ['a = [1, 2 ]',
|
48
|
+
'b = [ 1, 2]'])
|
49
|
+
expect(new_source).to eq(['a = [1, 2]',
|
50
|
+
'b = [1, 2]'].join("\n"))
|
51
|
+
end
|
52
|
+
end
|