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,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SingleLineBlockParams, :config do
|
6
|
+
subject(:cop) { described_class.new(config) }
|
7
|
+
let(:cop_config) do
|
8
|
+
{ 'Methods' =>
|
9
|
+
[{ 'reduce' => %w(a e) },
|
10
|
+
{ 'test' => %w(x y) }]
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'find wrong argument names in calls with different syntax' do
|
15
|
+
inspect_source(cop,
|
16
|
+
['def m',
|
17
|
+
' [0, 1].reduce { |c, d| c + d }',
|
18
|
+
' [0, 1].reduce{ |c, d| c + d }',
|
19
|
+
' [0, 1].reduce(5) { |c, d| c + d }',
|
20
|
+
' [0, 1].reduce(5){ |c, d| c + d }',
|
21
|
+
' [0, 1].reduce (5) { |c, d| c + d }',
|
22
|
+
' [0, 1].reduce(5) { |c, d| c + d }',
|
23
|
+
' ala.test { |x, z| bala }',
|
24
|
+
'end'])
|
25
|
+
expect(cop.offences.size).to eq(7)
|
26
|
+
expect(cop.offences.map(&:line).sort).to eq((2..8).to_a)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'allows calls with proper argument names' do
|
30
|
+
inspect_source(cop,
|
31
|
+
['def m',
|
32
|
+
' [0, 1].reduce { |a, e| a + e }',
|
33
|
+
' [0, 1].reduce{ |a, e| a + e }',
|
34
|
+
' [0, 1].reduce(5) { |a, e| a + e }',
|
35
|
+
' [0, 1].reduce(5){ |a, e| a + e }',
|
36
|
+
' [0, 1].reduce (5) { |a, e| a + e }',
|
37
|
+
' [0, 1].reduce(5) { |a, e| a + e }',
|
38
|
+
' ala.test { |x, y| bala }',
|
39
|
+
'end'])
|
40
|
+
expect(cop.offences).to be_empty
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'ignores do..end blocks' do
|
44
|
+
inspect_source(cop,
|
45
|
+
['def m',
|
46
|
+
' [0, 1].reduce do |c, d|',
|
47
|
+
' c + d',
|
48
|
+
' end',
|
49
|
+
'end'])
|
50
|
+
expect(cop.offences).to be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'ignores :reduce symbols' do
|
54
|
+
inspect_source(cop,
|
55
|
+
['def m',
|
56
|
+
' call_method(:reduce) { |a, b| a + b}',
|
57
|
+
'end'])
|
58
|
+
expect(cop.offences).to be_empty
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'does not report when destructuring is used' do
|
62
|
+
inspect_source(cop,
|
63
|
+
['def m',
|
64
|
+
' test.reduce { |a, (id, _)| a + id}',
|
65
|
+
'end'])
|
66
|
+
expect(cop.offences).to be_empty
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SingleLineMethods, :config do
|
6
|
+
subject(:cop) { described_class.new(config) }
|
7
|
+
let(:cop_config) { { 'AllowIfMethodIsEmpty' => true } }
|
8
|
+
|
9
|
+
it 'registers an offence for a single-line method' do
|
10
|
+
inspect_source(cop,
|
11
|
+
['def some_method; body end',
|
12
|
+
'def link_to(name, url); {:name => name}; end',
|
13
|
+
'def @table.columns; super; end'])
|
14
|
+
expect(cop.messages).to eq(
|
15
|
+
['Avoid single-line method definitions.'] * 3)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when AllowIfMethodIsEmpty is disabled' do
|
19
|
+
let(:cop_config) { { 'AllowIfMethodIsEmpty' => false } }
|
20
|
+
|
21
|
+
it 'registers an offence for an empty method' do
|
22
|
+
inspect_source(cop, ['def no_op; end',
|
23
|
+
'def self.resource_class=(klass); end',
|
24
|
+
'def @table.columns; end'])
|
25
|
+
expect(cop.offences.size).to eq(3)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when AllowIfMethodIsEmpty is enabled' do
|
30
|
+
let(:cop_config) { { 'AllowIfMethodIsEmpty' => true } }
|
31
|
+
|
32
|
+
it 'accepts a single-line empty method' do
|
33
|
+
inspect_source(cop, ['def no_op; end',
|
34
|
+
'def self.resource_class=(klass); end',
|
35
|
+
'def @table.columns; end'])
|
36
|
+
expect(cop.offences).to be_empty
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'accepts a multi-line method' do
|
41
|
+
inspect_source(cop, ['def some_method',
|
42
|
+
' body',
|
43
|
+
'end'])
|
44
|
+
expect(cop.offences).to be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'does not crash on an method with a capitalized name' do
|
48
|
+
inspect_source(cop, ['def NoSnakeCase',
|
49
|
+
'end'])
|
50
|
+
expect(cop.offences).to be_empty
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceAfterColon do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for colon without space after it' do
|
9
|
+
# TODO: There is double reporting of the last colon (also from
|
10
|
+
# SpaceAroundOperators).
|
11
|
+
inspect_source(cop, ['x = w ? {a:3}:4'])
|
12
|
+
expect(cop.messages).to eq(['Space missing after colon.'] * 2)
|
13
|
+
expect(cop.highlights).to eq([':'] * 2)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts colons in symbols' do
|
17
|
+
inspect_source(cop, ['x = :a'])
|
18
|
+
expect(cop.messages).to be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
if RUBY_VERSION >= '2.1'
|
22
|
+
it 'accepts colons denoting required keyword argument' do
|
23
|
+
inspect_source(cop, ['def initialize(table:, nodes:)',
|
24
|
+
'end'])
|
25
|
+
expect(cop.messages).to be_empty
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'accepts colons in strings' do
|
30
|
+
inspect_source(cop, ["str << ':'"])
|
31
|
+
expect(cop.messages).to be_empty
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'auto-corrects missing space' do
|
35
|
+
new_source = autocorrect_source(cop, 'x = w ? {a:3}:4')
|
36
|
+
expect(new_source).to eq('x = w ? {a: 3}: 4')
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceAfterComma do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for block argument commas without space' do
|
9
|
+
inspect_source(cop, ['each { |s,t| }'])
|
10
|
+
expect(cop.messages).to eq(
|
11
|
+
['Space missing after comma.'])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'registers an offence for array index commas without space' do
|
15
|
+
inspect_source(cop, ['formats[0,1]'])
|
16
|
+
expect(cop.messages).to eq(
|
17
|
+
['Space missing after comma.'])
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'registers an offence for method call arg commas without space' do
|
21
|
+
inspect_source(cop, ['a(1,2)'])
|
22
|
+
expect(cop.messages).to eq(
|
23
|
+
['Space missing after comma.'])
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'auto-corrects missing space' do
|
27
|
+
new_source = autocorrect_source(cop, 'each { |s,t| a(1,formats[0,1])}')
|
28
|
+
expect(new_source).to eq('each { |s, t| a(1, formats[0, 1])}')
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceAfterControlKeyword do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for normal if' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['if(test) then result end'])
|
11
|
+
expect(cop.offences.size).to eq(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'registers an offence for modifier unless' do
|
15
|
+
inspect_source(cop, ['action unless(test)'])
|
16
|
+
|
17
|
+
expect(cop.offences.size).to eq(1)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'does not get confused by keywords' do
|
21
|
+
inspect_source(cop, ['[:if, :unless].action'])
|
22
|
+
expect(cop.offences).to be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'does not get confused by the ternary operator' do
|
26
|
+
inspect_source(cop, ['a ? b : c'])
|
27
|
+
expect(cop.offences).to be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'registers an offence for if, elsif, and unless' do
|
31
|
+
inspect_source(cop,
|
32
|
+
['if(a)',
|
33
|
+
'elsif(b)',
|
34
|
+
' unless(c)',
|
35
|
+
' end',
|
36
|
+
'end'])
|
37
|
+
expect(cop.offences.map(&:line)).to eq([1, 2, 3])
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'registers an offence for case and when' do
|
41
|
+
inspect_source(cop,
|
42
|
+
['case(a)',
|
43
|
+
'when(0) then 1',
|
44
|
+
'end'])
|
45
|
+
expect(cop.offences.map(&:line)).to eq([1, 2])
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'registers an offence for while and until' do
|
49
|
+
inspect_source(cop,
|
50
|
+
['while(a)',
|
51
|
+
' b until(c)',
|
52
|
+
'end'])
|
53
|
+
expect(cop.offences.map(&:line)).to eq([1, 2])
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'auto-corrects missing space' do
|
57
|
+
new_source = autocorrect_source(cop, ['if(test) then result end',
|
58
|
+
'action unless(test)',
|
59
|
+
'if(a)',
|
60
|
+
'elsif(b)',
|
61
|
+
' unless(c)',
|
62
|
+
' end',
|
63
|
+
'end',
|
64
|
+
'case(a)',
|
65
|
+
'when(0) then 1',
|
66
|
+
'end',
|
67
|
+
'while(a)',
|
68
|
+
' b until(c)',
|
69
|
+
'end'])
|
70
|
+
expect(new_source).to eq(['if (test) then result end',
|
71
|
+
'action unless (test)',
|
72
|
+
'if (a)',
|
73
|
+
'elsif (b)',
|
74
|
+
' unless (c)',
|
75
|
+
' end',
|
76
|
+
'end',
|
77
|
+
'case (a)',
|
78
|
+
'when (0) then 1',
|
79
|
+
'end',
|
80
|
+
'while (a)',
|
81
|
+
' b until (c)',
|
82
|
+
'end'].join("\n"))
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceAfterMethodName do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for def with space before the parenthesis' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['def func (x)',
|
11
|
+
' a',
|
12
|
+
'end'])
|
13
|
+
expect(cop.offences.size).to eq(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'registers an offence for defs with space before the parenthesis' do
|
17
|
+
inspect_source(cop,
|
18
|
+
['def self.func (x)',
|
19
|
+
' a',
|
20
|
+
'end'])
|
21
|
+
expect(cop.offences.size).to eq(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'accepts a def without arguments' do
|
25
|
+
inspect_source(cop,
|
26
|
+
['def func',
|
27
|
+
' a',
|
28
|
+
'end'])
|
29
|
+
expect(cop.offences).to be_empty
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'accepts a defs without arguments' do
|
33
|
+
inspect_source(cop,
|
34
|
+
['def self.func',
|
35
|
+
' a',
|
36
|
+
'end'])
|
37
|
+
expect(cop.offences).to be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'accepts a def with arguments but no parentheses' do
|
41
|
+
inspect_source(cop,
|
42
|
+
['def func x',
|
43
|
+
' a',
|
44
|
+
'end'])
|
45
|
+
expect(cop.offences).to be_empty
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'accepts a defs with arguments but no parentheses' do
|
49
|
+
inspect_source(cop,
|
50
|
+
['def self.func x',
|
51
|
+
' a',
|
52
|
+
'end'])
|
53
|
+
expect(cop.offences).to be_empty
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'auto-corrects unwanted space' do
|
57
|
+
new_source = autocorrect_source(cop, ['def func (x)',
|
58
|
+
' a',
|
59
|
+
'end',
|
60
|
+
'def self.func (x)',
|
61
|
+
' a',
|
62
|
+
'end'])
|
63
|
+
expect(new_source).to eq(['def func(x)',
|
64
|
+
' a',
|
65
|
+
'end',
|
66
|
+
'def self.func(x)',
|
67
|
+
' a',
|
68
|
+
'end'].join("\n"))
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceAfterNot do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'reports an offence for space after !' do
|
9
|
+
inspect_source(cop, ['! something'])
|
10
|
+
expect(cop.offences.size).to eq(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'accepts no space after !' do
|
14
|
+
inspect_source(cop, ['!something'])
|
15
|
+
expect(cop.offences).to be_empty
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'auto-corrects by removing redundant space' do
|
19
|
+
new_source = autocorrect_source(cop, '! something')
|
20
|
+
expect(new_source).to eq('!something')
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceAfterSemicolon do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for semicolon without space after it' do
|
9
|
+
inspect_source(cop, ['x = 1;y = 2'])
|
10
|
+
expect(cop.messages).to eq(
|
11
|
+
['Space missing after semicolon.'])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'does not crash if semicolon is the last character of the file' do
|
15
|
+
inspect_source(cop, ['x = 1;'])
|
16
|
+
expect(cop.messages).to be_empty
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'auto-corrects missing space' do
|
20
|
+
new_source = autocorrect_source(cop, 'x = 1;y = 2')
|
21
|
+
expect(new_source).to eq('x = 1; y = 2')
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,283 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::SpaceAroundBlockBraces do
|
6
|
+
SUPPORTED_STYLES = %w(space_inside_braces no_space_inside_braces)
|
7
|
+
|
8
|
+
subject(:cop) { described_class.new(config) }
|
9
|
+
let(:config) do
|
10
|
+
merged = Rubocop::ConfigLoader
|
11
|
+
.default_configuration['SpaceAroundBlockBraces'].merge(cop_config)
|
12
|
+
Rubocop::Config.new('Blocks' => { 'Enabled' => false },
|
13
|
+
'SpaceAroundBlockBraces' => merged)
|
14
|
+
end
|
15
|
+
let(:cop_config) do
|
16
|
+
{
|
17
|
+
'EnforcedStyle' => 'space_inside_braces',
|
18
|
+
'SupportedStyles' => SUPPORTED_STYLES,
|
19
|
+
'SpaceBeforeBlockParameters' => true
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with space inside empty braces not allowed' do
|
24
|
+
let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'no_space' } }
|
25
|
+
|
26
|
+
it 'accepts empty braces with no space inside' do
|
27
|
+
inspect_source(cop, ['each {}'])
|
28
|
+
expect(cop.messages).to be_empty
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'accepts empty braces with line break inside' do
|
32
|
+
inspect_source(cop, [' each {',
|
33
|
+
' }'])
|
34
|
+
expect(cop.messages).to be_empty
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'registers an offence for empty braces with space inside' do
|
38
|
+
inspect_source(cop, ['each { }'])
|
39
|
+
expect(cop.messages).to eq(['Space inside empty braces detected.'])
|
40
|
+
expect(cop.highlights).to eq([' '])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'auto-corrects unwanted space' do
|
44
|
+
new_source = autocorrect_source(cop, 'each { }')
|
45
|
+
expect(new_source).to eq('each {}')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'does not auto-correct when braces are not empty' do
|
49
|
+
old_source = <<-END
|
50
|
+
a {
|
51
|
+
b
|
52
|
+
}
|
53
|
+
END
|
54
|
+
new_source = autocorrect_source(cop, old_source)
|
55
|
+
expect(new_source).to eq(old_source)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with space inside empty braces allowed' do
|
60
|
+
let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'space' } }
|
61
|
+
|
62
|
+
it 'accepts empty braces with space inside' do
|
63
|
+
inspect_source(cop, ['each { }'])
|
64
|
+
expect(cop.messages).to be_empty
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'registers an offence for empty braces with no space inside' do
|
68
|
+
inspect_source(cop, ['each {}'])
|
69
|
+
expect(cop.messages).to eq(['Space missing inside empty braces.'])
|
70
|
+
expect(cop.highlights).to eq(['{}'])
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'auto-corrects missing space' do
|
74
|
+
new_source = autocorrect_source(cop, 'each {}')
|
75
|
+
expect(new_source).to eq('each { }')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'accepts braces surrounded by spaces' do
|
80
|
+
inspect_source(cop, ['each { puts }'])
|
81
|
+
expect(cop.messages).to be_empty
|
82
|
+
expect(cop.highlights).to be_empty
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'registers an offence for left brace without outer space' do
|
86
|
+
inspect_source(cop, ['each{ puts }'])
|
87
|
+
expect(cop.messages).to eq(['Space missing to the left of {.'])
|
88
|
+
expect(cop.highlights).to eq(['{'])
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'registers an offence for left brace without inner space' do
|
92
|
+
inspect_source(cop, ['each {puts }'])
|
93
|
+
expect(cop.messages).to eq(['Space missing inside {.'])
|
94
|
+
expect(cop.highlights).to eq(['p'])
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'registers an offence for right brace without inner space' do
|
98
|
+
inspect_source(cop, ['each { puts}'])
|
99
|
+
expect(cop.messages).to eq(['Space missing inside }.'])
|
100
|
+
expect(cop.highlights).to eq(['}'])
|
101
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'registers offences for both braces without inner space' do
|
105
|
+
inspect_source(cop, ['a {}',
|
106
|
+
'b { }',
|
107
|
+
'each {puts}'])
|
108
|
+
expect(cop.messages).to eq(['Space inside empty braces detected.',
|
109
|
+
'Space missing inside {.',
|
110
|
+
'Space missing inside }.'])
|
111
|
+
expect(cop.highlights).to eq([' ', 'p', '}'])
|
112
|
+
|
113
|
+
# Both correct and incorrect code has been found in relation to
|
114
|
+
# EnforcedStyleForEmptyBraces, but that doesn't matter. EnforcedStyle can
|
115
|
+
# be changed to get rid of the EnforcedStyle offences.
|
116
|
+
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
|
117
|
+
'no_space_inside_braces')
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'auto-corrects missing space' do
|
121
|
+
new_source = autocorrect_source(cop, 'each {puts}')
|
122
|
+
expect(new_source).to eq('each { puts }')
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'with passed in parameters' do
|
126
|
+
it 'accepts left brace with inner space' do
|
127
|
+
inspect_source(cop, ['each { |x| puts }'])
|
128
|
+
expect(cop.messages).to be_empty
|
129
|
+
expect(cop.highlights).to be_empty
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'registers an offence for left brace without inner space' do
|
133
|
+
inspect_source(cop, ['each {|x| puts }'])
|
134
|
+
expect(cop.messages).to eq(['Space between { and | missing.'])
|
135
|
+
expect(cop.highlights).to eq(['{|'])
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'auto-corrects missing space' do
|
139
|
+
new_source = autocorrect_source(cop, 'each{|x| puts }')
|
140
|
+
expect(new_source).to eq('each { |x| puts }')
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'and Blocks cop enabled' do
|
144
|
+
let(:config) do
|
145
|
+
Rubocop::Config.new('Blocks' => { 'Enabled' => true },
|
146
|
+
'SpaceAroundBlockBraces' => cop_config)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'does auto-correction for single-line blocks' do
|
150
|
+
new_source = autocorrect_source(cop, 'each{|x| puts}')
|
151
|
+
expect(new_source).to eq('each { |x| puts }')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'does not do auto-correction for multi-line blocks' do
|
155
|
+
# {} will be changed to do..end by the Blocks cop, and then this cop is
|
156
|
+
# not relevant anymore.
|
157
|
+
old_source = ['each{|x|',
|
158
|
+
' puts',
|
159
|
+
'}']
|
160
|
+
new_source = autocorrect_source(cop, old_source)
|
161
|
+
expect(new_source).to eq(old_source.join("\n"))
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'and space before block parameters not allowed' do
|
166
|
+
let(:cop_config) do
|
167
|
+
{
|
168
|
+
'EnforcedStyle' => 'space_inside_braces',
|
169
|
+
'SupportedStyles' => SUPPORTED_STYLES,
|
170
|
+
'SpaceBeforeBlockParameters' => false
|
171
|
+
}
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'registers an offence for left brace with inner space' do
|
175
|
+
inspect_source(cop, ['each { |x| puts }'])
|
176
|
+
expect(cop.messages).to eq(['Space between { and | detected.'])
|
177
|
+
expect(cop.highlights).to eq([' '])
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'auto-corrects unwanted space' do
|
181
|
+
new_source = autocorrect_source(cop, 'each { |x| puts }')
|
182
|
+
expect(new_source).to eq('each {|x| puts }')
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'accepts left brace without inner space' do
|
186
|
+
inspect_source(cop, ['each {|x| puts }'])
|
187
|
+
expect(cop.messages).to be_empty
|
188
|
+
expect(cop.highlights).to be_empty
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'configured with no_space_inside_braces' do
|
194
|
+
let(:cop_config) do
|
195
|
+
{
|
196
|
+
'EnforcedStyle' => 'no_space_inside_braces',
|
197
|
+
'SupportedStyles' => SUPPORTED_STYLES,
|
198
|
+
'SpaceBeforeBlockParameters' => true
|
199
|
+
}
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'accepts braces without spaces inside' do
|
203
|
+
inspect_source(cop, ['each {puts}'])
|
204
|
+
expect(cop.messages).to be_empty
|
205
|
+
expect(cop.highlights).to be_empty
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'registers an offence for left brace with inner space' do
|
209
|
+
inspect_source(cop, ['each { puts}'])
|
210
|
+
expect(cop.messages).to eq(['Space inside { detected.'])
|
211
|
+
expect(cop.highlights).to eq([' '])
|
212
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'registers an offence for right brace with inner space' do
|
216
|
+
inspect_source(cop, ['each {puts }'])
|
217
|
+
expect(cop.messages).to eq(['Space inside } detected.'])
|
218
|
+
expect(cop.highlights).to eq([' '])
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'registers offences for both braces with inner space' do
|
222
|
+
inspect_source(cop, ['each { puts }'])
|
223
|
+
expect(cop.messages).to eq(['Space inside { detected.',
|
224
|
+
'Space inside } detected.'])
|
225
|
+
expect(cop.highlights).to eq([' ', ' '])
|
226
|
+
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
|
227
|
+
'space_inside_braces')
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'registers an offence for left brace without outer space' do
|
231
|
+
inspect_source(cop, ['each{puts}'])
|
232
|
+
expect(cop.messages).to eq(['Space missing to the left of {.'])
|
233
|
+
expect(cop.highlights).to eq(['{'])
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'auto-corrects missing space' do
|
237
|
+
new_source = autocorrect_source(cop, 'each{ puts }')
|
238
|
+
expect(new_source).to eq('each {puts}')
|
239
|
+
end
|
240
|
+
|
241
|
+
context 'with passed in parameters' do
|
242
|
+
context 'and space before block parameters allowed' do
|
243
|
+
it 'accepts left brace with inner space' do
|
244
|
+
inspect_source(cop, ['each { |x| puts}'])
|
245
|
+
expect(cop.messages).to eq([])
|
246
|
+
expect(cop.highlights).to eq([])
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'registers an offence for left brace without inner space' do
|
250
|
+
inspect_source(cop, ['each {|x| puts}'])
|
251
|
+
expect(cop.messages).to eq(['Space between { and | missing.'])
|
252
|
+
expect(cop.highlights).to eq(['{|'])
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'auto-corrects missing space' do
|
256
|
+
new_source = autocorrect_source(cop, 'each {|x| puts}')
|
257
|
+
expect(new_source).to eq('each { |x| puts}')
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context 'and space before block parameters not allowed' do
|
262
|
+
let(:cop_config) do
|
263
|
+
{
|
264
|
+
'EnforcedStyle' => 'no_space_inside_braces',
|
265
|
+
'SupportedStyles' => SUPPORTED_STYLES,
|
266
|
+
'SpaceBeforeBlockParameters' => false
|
267
|
+
}
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'registers an offence for left brace with inner space' do
|
271
|
+
inspect_source(cop, ['each { |x| puts}'])
|
272
|
+
expect(cop.messages).to eq(['Space between { and | detected.'])
|
273
|
+
expect(cop.highlights).to eq([' '])
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'auto-corrects unwanted space' do
|
277
|
+
new_source = autocorrect_source(cop, 'each { |x| puts}')
|
278
|
+
expect(new_source).to eq('each {|x| puts}')
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|