ridecharge-rubocop 0.0.1
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.
- 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,138 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
|
|
6
|
+
subject(:cop) { described_class.new(config) }
|
|
7
|
+
let(:cop_config) { { 'EnforcedStyle' => 'space' } }
|
|
8
|
+
|
|
9
|
+
context 'with space inside empty braces not allowed' do
|
|
10
|
+
let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'no_space' } }
|
|
11
|
+
|
|
12
|
+
it 'accepts empty braces with no space inside' do
|
|
13
|
+
inspect_source(cop, ['h = {}'])
|
|
14
|
+
expect(cop.messages).to be_empty
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'registers an offence for empty braces with space inside' do
|
|
18
|
+
inspect_source(cop, ['h = { }'])
|
|
19
|
+
expect(cop.messages)
|
|
20
|
+
.to eq(['Space inside empty hash literal braces detected.'])
|
|
21
|
+
expect(cop.highlights).to eq([' '])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'auto-corrects unwanted space' do
|
|
25
|
+
new_source = autocorrect_source(cop, 'h = { }')
|
|
26
|
+
expect(new_source).to eq('h = {}')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context 'with space inside empty braces allowed' do
|
|
31
|
+
let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'space' } }
|
|
32
|
+
|
|
33
|
+
it 'accepts empty braces with space inside' do
|
|
34
|
+
inspect_source(cop, ['h = { }'])
|
|
35
|
+
expect(cop.messages).to be_empty
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'registers an offence for empty braces with no space inside' do
|
|
39
|
+
inspect_source(cop, ['h = {}'])
|
|
40
|
+
expect(cop.messages)
|
|
41
|
+
.to eq(['Space inside empty hash literal braces missing.'])
|
|
42
|
+
expect(cop.highlights).to eq(['{'])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'auto-corrects missing space' do
|
|
46
|
+
new_source = autocorrect_source(cop, 'h = {}')
|
|
47
|
+
expect(new_source).to eq('h = { }')
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'registers an offence for hashes with no spaces if so configured' do
|
|
52
|
+
inspect_source(cop,
|
|
53
|
+
['h = {a: 1, b: 2}',
|
|
54
|
+
'h = {a => 1}'])
|
|
55
|
+
expect(cop.messages).to eq(['Space inside { missing.',
|
|
56
|
+
'Space inside } missing.',
|
|
57
|
+
'Space inside { missing.',
|
|
58
|
+
'Space inside } missing.'])
|
|
59
|
+
expect(cop.highlights).to eq(['{', '}', '{', '}'])
|
|
60
|
+
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' => 'no_space')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'registers an offence for correct + opposite' do
|
|
64
|
+
inspect_source(cop,
|
|
65
|
+
['h = { a: 1}'])
|
|
66
|
+
expect(cop.messages).to eq(['Space inside } missing.'])
|
|
67
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'auto-corrects missing space' do
|
|
71
|
+
new_source = autocorrect_source(cop, ['h = {a: 1, b: 2}',
|
|
72
|
+
'h = {a => 1 }'])
|
|
73
|
+
expect(new_source).to eq(['h = { a: 1, b: 2 }',
|
|
74
|
+
'h = { a => 1 }'].join("\n"))
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context 'when EnforcedStyle is no_space' do
|
|
78
|
+
let(:cop_config) { { 'EnforcedStyle' => 'no_space' } }
|
|
79
|
+
|
|
80
|
+
it 'registers an offence for hashes with spaces' do
|
|
81
|
+
inspect_source(cop,
|
|
82
|
+
['h = { a: 1, b: 2 }'])
|
|
83
|
+
expect(cop.messages).to eq(['Space inside { detected.',
|
|
84
|
+
'Space inside } detected.'])
|
|
85
|
+
expect(cop.highlights).to eq([' ', ' '])
|
|
86
|
+
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' => 'space')
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'registers an offence for opposite + correct' do
|
|
90
|
+
inspect_source(cop,
|
|
91
|
+
['h = {a: 1 }'])
|
|
92
|
+
expect(cop.messages).to eq(['Space inside } detected.'])
|
|
93
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'auto-corrects unwanted space' do
|
|
97
|
+
new_source = autocorrect_source(cop, ['h = { a: 1, b: 2 }',
|
|
98
|
+
'h = {a => 1 }'])
|
|
99
|
+
expect(new_source).to eq(['h = {a: 1, b: 2}',
|
|
100
|
+
'h = {a => 1}'].join("\n"))
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it 'accepts hashes with no spaces' do
|
|
104
|
+
inspect_source(cop,
|
|
105
|
+
['h = {a: 1, b: 2}',
|
|
106
|
+
'h = {a => 1}'])
|
|
107
|
+
expect(cop.offences).to be_empty
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'accepts multiline hashes for no space' do
|
|
111
|
+
inspect_source(cop,
|
|
112
|
+
['h = {',
|
|
113
|
+
' a: 1,',
|
|
114
|
+
' b: 2,',
|
|
115
|
+
'}'])
|
|
116
|
+
expect(cop.offences).to be_empty
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'accepts hashes with spaces by default' do
|
|
121
|
+
inspect_source(cop,
|
|
122
|
+
['h = { a: 1, b: 2 }',
|
|
123
|
+
'h = { a => 1 }'])
|
|
124
|
+
expect(cop.offences).to be_empty
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'accepts hash literals with no braces' do
|
|
128
|
+
inspect_source(cop, ['x(a: b.c)'])
|
|
129
|
+
expect(cop.offences).to be_empty
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it 'can handle interpolation in a braceless hash literal' do
|
|
133
|
+
# A tricky special case where the closing brace of the
|
|
134
|
+
# interpolation risks getting confused for a hash literal brace.
|
|
135
|
+
inspect_source(cop, ['f(get: "#{x}")'])
|
|
136
|
+
expect(cop.offences).to be_empty
|
|
137
|
+
end
|
|
138
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::SpaceInsideParens do
|
|
6
|
+
subject(:cop) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'registers an offence for spaces inside parens' do
|
|
9
|
+
inspect_source(cop, ['f( 3)',
|
|
10
|
+
'g(3 )'])
|
|
11
|
+
expect(cop.messages).to eq(
|
|
12
|
+
['Space inside parentheses detected.',
|
|
13
|
+
'Space inside parentheses detected.'])
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'accepts parentheses in block parameter list' do
|
|
17
|
+
inspect_source(cop,
|
|
18
|
+
['list.inject(Tms.new) { |sum, (label, item)|',
|
|
19
|
+
'}'])
|
|
20
|
+
expect(cop.messages).to be_empty
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'accepts parentheses with no spaces' do
|
|
24
|
+
inspect_source(cop, ['split("\n")'])
|
|
25
|
+
expect(cop.messages).to be_empty
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'auto-corrects unwanted space' do
|
|
29
|
+
new_source = autocorrect_source(cop, ['f( 3)',
|
|
30
|
+
'g(3 )'])
|
|
31
|
+
expect(new_source).to eq(['f(3)',
|
|
32
|
+
'g(3)'].join("\n"))
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::SpecialGlobalVars do
|
|
6
|
+
subject(:cop) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'registers an offence for $:' do
|
|
9
|
+
inspect_source(cop, ['puts $:'])
|
|
10
|
+
expect(cop.offences.size).to eq(1)
|
|
11
|
+
expect(cop.messages)
|
|
12
|
+
.to eq(['Prefer $LOAD_PATH over $:.'])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'registers an offence for $"' do
|
|
16
|
+
inspect_source(cop, ['puts $"'])
|
|
17
|
+
expect(cop.offences.size).to eq(1)
|
|
18
|
+
expect(cop.messages)
|
|
19
|
+
.to eq(['Prefer $LOADED_FEATURES over $".'])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'registers an offence for $0' do
|
|
23
|
+
inspect_source(cop, ['puts $0'])
|
|
24
|
+
expect(cop.offences.size).to eq(1)
|
|
25
|
+
expect(cop.messages)
|
|
26
|
+
.to eq(['Prefer $PROGRAM_NAME over $0.'])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'registers an offence for $$' do
|
|
30
|
+
inspect_source(cop, ['puts $$'])
|
|
31
|
+
expect(cop.offences.size).to eq(1)
|
|
32
|
+
expect(cop.messages)
|
|
33
|
+
.to eq(['Prefer $PROCESS_ID or $PID from the English library over $$.'])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'is clear about variables from the English library vs those not' do
|
|
37
|
+
inspect_source(cop, ['puts $*'])
|
|
38
|
+
expect(cop.messages)
|
|
39
|
+
.to eq(['Prefer $ARGV from the English library, or ARGV over $*.'])
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'does not register an offence for backrefs like $1' do
|
|
43
|
+
inspect_source(cop, ['puts $1'])
|
|
44
|
+
expect(cop.offences).to be_empty
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'auto-corrects $: to $LOAD_PATH' do
|
|
48
|
+
new_source = autocorrect_source(cop, '$:')
|
|
49
|
+
expect(new_source).to eq('$LOAD_PATH')
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'auto-corrects $/ to $INPUT_RECORD_SEPARATOR' do
|
|
53
|
+
new_source = autocorrect_source(cop, '$/')
|
|
54
|
+
expect(new_source).to eq('$INPUT_RECORD_SEPARATOR')
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::StringLiterals, :config do
|
|
6
|
+
subject(:cop) { described_class.new(config) }
|
|
7
|
+
|
|
8
|
+
context 'configured with single quotes preferred' do
|
|
9
|
+
let(:cop_config) { { 'EnforcedStyle' => 'single_quotes' } }
|
|
10
|
+
|
|
11
|
+
it 'registers offence for double quotes when single quotes ' \
|
|
12
|
+
'suffice' do
|
|
13
|
+
inspect_source(cop, ['s = "abc"',
|
|
14
|
+
'x = "a\\\\b"',
|
|
15
|
+
'y ="\\\\b"',
|
|
16
|
+
'z = "a\\\\"'])
|
|
17
|
+
expect(cop.highlights).to eq(['"abc"',
|
|
18
|
+
'"a\\\\b"',
|
|
19
|
+
'"\\\\b"',
|
|
20
|
+
'"a\\\\"'])
|
|
21
|
+
expect(cop.messages)
|
|
22
|
+
.to eq(["Prefer single-quoted strings when you don't need " \
|
|
23
|
+
'string interpolation or special symbols.'] * 4)
|
|
24
|
+
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
|
|
25
|
+
'double_quotes')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'registers offence for correct + opposite' do
|
|
29
|
+
inspect_source(cop, ['s = "abc"',
|
|
30
|
+
"x = 'abc'"])
|
|
31
|
+
expect(cop.messages)
|
|
32
|
+
.to eq(["Prefer single-quoted strings when you don't need " \
|
|
33
|
+
'string interpolation or special symbols.'])
|
|
34
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'accepts single quotes' do
|
|
38
|
+
inspect_source(cop, ["a = 'x'"])
|
|
39
|
+
expect(cop.offences).to be_empty
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'accepts %q and %Q quotes' do
|
|
43
|
+
inspect_source(cop, ['a = %q(x) + %Q[x]'])
|
|
44
|
+
expect(cop.offences).to be_empty
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'accepts % quotes' do
|
|
48
|
+
inspect_source(cop, ['a = %(x)'])
|
|
49
|
+
expect(cop.offences).to be_empty
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'accepts heredocs' do
|
|
53
|
+
inspect_source(cop,
|
|
54
|
+
['execute <<-SQL',
|
|
55
|
+
' SELECT name from users',
|
|
56
|
+
'SQL'])
|
|
57
|
+
|
|
58
|
+
expect(cop.offences).to be_empty
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'accepts double quotes when they are needed' do
|
|
62
|
+
src = ['a = "\n"',
|
|
63
|
+
'b = "#{encode_severity}:' \
|
|
64
|
+
'#{sprintf("%3d", line_number)}: #{m}"',
|
|
65
|
+
'c = "\'"',
|
|
66
|
+
'd = "#@test"',
|
|
67
|
+
'e = "#$test"',
|
|
68
|
+
'f = "\e"',
|
|
69
|
+
'g = "#@@test"']
|
|
70
|
+
inspect_source(cop, src)
|
|
71
|
+
expect(cop.offences).to be_empty
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'accepts double quotes at the start of regexp literals' do
|
|
75
|
+
inspect_source(cop, ['s = /"((?:[^\\"]|\\.)*)"/'])
|
|
76
|
+
expect(cop.offences).to be_empty
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'accepts double quotes with some other special symbols' do
|
|
80
|
+
# "Substitutions in double-quoted strings"
|
|
81
|
+
# http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
|
|
82
|
+
src = ['g = "\xf9"',
|
|
83
|
+
'copyright = "\u00A9"']
|
|
84
|
+
inspect_source(cop, src)
|
|
85
|
+
expect(cop.offences).to be_empty
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'accepts " in a %w' do
|
|
89
|
+
inspect_source(cop, ['%w(")'])
|
|
90
|
+
expect(cop.offences).to be_empty
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'accepts \\\\\n in a string' do # this would be: "\\\n"
|
|
94
|
+
inspect_source(cop, ['"foo \\\\\n bar"'])
|
|
95
|
+
expect(cop.offences).to be_empty
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'can handle double quotes within embedded expression' do
|
|
99
|
+
src = ['"#{"A"}"']
|
|
100
|
+
inspect_source(cop, src)
|
|
101
|
+
expect(cop.offences).to be_empty
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'can handle a built-in constant parsed as string' do
|
|
105
|
+
# Parser will produce str nodes for constants such as __FILE__.
|
|
106
|
+
src = ['if __FILE__ == $PROGRAM_NAME',
|
|
107
|
+
'end']
|
|
108
|
+
inspect_source(cop, src)
|
|
109
|
+
expect(cop.offences).to be_empty
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'can handle character literals' do
|
|
113
|
+
src = 'a = ?/'
|
|
114
|
+
inspect_source(cop, src)
|
|
115
|
+
expect(cop.offences).to be_empty
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'auto-corrects " with \'' do
|
|
119
|
+
new_source = autocorrect_source(cop, 's = "abc"')
|
|
120
|
+
expect(new_source).to eq("s = 'abc'")
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context 'configured with double quotes preferred' do
|
|
125
|
+
let(:cop_config) { { 'EnforcedStyle' => 'double_quotes' } }
|
|
126
|
+
|
|
127
|
+
it 'registers offence for single quotes when double quotes would ' \
|
|
128
|
+
'be equivalent' do
|
|
129
|
+
inspect_source(cop, ["s = 'abc'"])
|
|
130
|
+
expect(cop.highlights).to eq(["'abc'"])
|
|
131
|
+
expect(cop.messages)
|
|
132
|
+
.to eq(['Prefer double-quoted strings unless you need ' \
|
|
133
|
+
'single quotes to avoid extra backslashes for ' +
|
|
134
|
+
'escaping.'])
|
|
135
|
+
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
|
|
136
|
+
'single_quotes')
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'registers offence for opposite + correct' do
|
|
140
|
+
inspect_source(cop, ['s = "abc"',
|
|
141
|
+
"x = 'abc'"])
|
|
142
|
+
expect(cop.messages)
|
|
143
|
+
.to eq(['Prefer double-quoted strings unless you need ' \
|
|
144
|
+
'single quotes to avoid extra backslashes for ' +
|
|
145
|
+
'escaping.'])
|
|
146
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'accepts double quotes' do
|
|
150
|
+
inspect_source(cop, ['a = "x"'])
|
|
151
|
+
expect(cop.offences).to be_empty
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it 'accepts %q and %Q quotes' do
|
|
155
|
+
inspect_source(cop, ['a = %q(x) + %Q[x]'])
|
|
156
|
+
expect(cop.offences).to be_empty
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it 'accepts % quotes' do
|
|
160
|
+
inspect_source(cop, ['a = %(x)'])
|
|
161
|
+
expect(cop.offences).to be_empty
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'accepts heredocs' do
|
|
165
|
+
inspect_source(cop,
|
|
166
|
+
['execute <<-SQL',
|
|
167
|
+
' SELECT name from users',
|
|
168
|
+
'SQL'])
|
|
169
|
+
|
|
170
|
+
expect(cop.offences).to be_empty
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it 'accepts single quotes when they are needed' do
|
|
174
|
+
src = ["a = '\\n'",
|
|
175
|
+
"b = '\"'"]
|
|
176
|
+
inspect_source(cop, src)
|
|
177
|
+
expect(cop.offences).to be_empty
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'accepts single quotes at the start of regexp literals' do
|
|
181
|
+
inspect_source(cop, ["s = /'((?:[^\\']|\\.)*)'/"])
|
|
182
|
+
expect(cop.offences).to be_empty
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it "accepts ' in a %w" do
|
|
186
|
+
inspect_source(cop, ["%w(')"])
|
|
187
|
+
expect(cop.offences).to be_empty
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it 'can handle a built-in constant parsed as string' do
|
|
191
|
+
# Parser will produce str nodes for constants such as __FILE__.
|
|
192
|
+
src = ['if __FILE__ == $PROGRAM_NAME',
|
|
193
|
+
'end']
|
|
194
|
+
inspect_source(cop, src)
|
|
195
|
+
expect(cop.offences).to be_empty
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
it "auto-corrects ' with \"" do
|
|
199
|
+
new_source = autocorrect_source(cop, "s = 'abc'")
|
|
200
|
+
expect(new_source).to eq('s = "abc"')
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
context 'when configured with a bad value' do
|
|
205
|
+
let(:cop_config) { { 'EnforcedStyle' => 'other' } }
|
|
206
|
+
|
|
207
|
+
it 'fails' do
|
|
208
|
+
expect { inspect_source(cop, ['a = "b"']) }
|
|
209
|
+
.to raise_error(RuntimeError)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::SymbolArray do
|
|
6
|
+
subject(:cop) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'registers an offence for arrays of symbols', ruby: 2.0 do
|
|
9
|
+
inspect_source(cop,
|
|
10
|
+
['[:one, :two, :three]'])
|
|
11
|
+
expect(cop.offences.size).to eq(1)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'does not reg an offence for array with non-syms', ruby: 2.0 do
|
|
15
|
+
inspect_source(cop,
|
|
16
|
+
['[:one, :two, "three"]'])
|
|
17
|
+
expect(cop.offences).to be_empty
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'does not reg an offence for array starting with %i', ruby: 2.0 do
|
|
21
|
+
inspect_source(cop,
|
|
22
|
+
['%i(one two three)'])
|
|
23
|
+
expect(cop.offences).to be_empty
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'does not reg an offence for array with one element', ruby: 2.0 do
|
|
27
|
+
inspect_source(cop,
|
|
28
|
+
['[:three]'])
|
|
29
|
+
expect(cop.offences).to be_empty
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'does nothing on Ruby 1.9', ruby: 1.9 do
|
|
33
|
+
inspect_source(cop,
|
|
34
|
+
['[:one, :two, :three]'])
|
|
35
|
+
expect(cop.offences).to be_empty
|
|
36
|
+
end
|
|
37
|
+
end
|