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,18 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::MultilineTernaryOperator do
|
|
6
|
+
subject(:cop) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'registers offence for a multiline ternary operator expression' do
|
|
9
|
+
inspect_source(cop, ['a = cond ?',
|
|
10
|
+
' b : c'])
|
|
11
|
+
expect(cop.offences.size).to eq(1)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'accepts a single line ternary operator expression' do
|
|
15
|
+
inspect_source(cop, ['a = cond ? b : c'])
|
|
16
|
+
expect(cop.offences).to be_empty
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::NestedTernaryOperator do
|
|
6
|
+
subject(:cop) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'registers an offence for a nested ternary operator expression' do
|
|
9
|
+
inspect_source(cop, ['a ? (b ? b1 : b2) : a2'])
|
|
10
|
+
expect(cop.offences.size).to eq(1)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'accepts a non-nested ternary operator within an if' do
|
|
14
|
+
inspect_source(cop, ['a = if x',
|
|
15
|
+
' cond ? b : c',
|
|
16
|
+
'else',
|
|
17
|
+
' d',
|
|
18
|
+
'end'])
|
|
19
|
+
expect(cop.offences).to be_empty
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::NilComparison do
|
|
6
|
+
subject(:cop) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'registers an offence for == nil' do
|
|
9
|
+
inspect_source(cop,
|
|
10
|
+
['x == nil'])
|
|
11
|
+
expect(cop.offences.size).to eq(1)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'registers an offence for === nil' do
|
|
15
|
+
inspect_source(cop,
|
|
16
|
+
['x === nil'])
|
|
17
|
+
expect(cop.offences.size).to eq(1)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'registers an offence for === nil' do
|
|
21
|
+
inspect_source(cop,
|
|
22
|
+
['x != nil'])
|
|
23
|
+
expect(cop.offences.size).to eq(1)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'works with lambda.()' do
|
|
27
|
+
inspect_source(cop, ['a.(x) == nil'])
|
|
28
|
+
expect(cop.offences.size).to eq(1)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::Not do
|
|
6
|
+
subject(:cop) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'registers an offence for not' do
|
|
9
|
+
inspect_source(cop, ['not test'])
|
|
10
|
+
expect(cop.offences.size).to eq(1)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'does not register an offence for !' do
|
|
14
|
+
inspect_source(cop, ['!test'])
|
|
15
|
+
expect(cop.offences).to be_empty
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'does not register an offence for :not' do
|
|
19
|
+
inspect_source(cop, ['[:not, :if, :else]'])
|
|
20
|
+
expect(cop.offences).to be_empty
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::NumericLiterals, :config do
|
|
6
|
+
subject(:cop) { described_class.new(config) }
|
|
7
|
+
let(:cop_config) { { 'MinDigits' => 5 } }
|
|
8
|
+
|
|
9
|
+
it 'registers an offence for a long integer without underscores' do
|
|
10
|
+
inspect_source(cop, ['a = 123456'])
|
|
11
|
+
expect(cop.offences.size).to eq(1)
|
|
12
|
+
expect(cop.config_to_allow_offences).to eq('MinDigits' => 6)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'registers an offence for an integer with misplaced underscore' do
|
|
16
|
+
inspect_source(cop, ['a = 123_456_78_90_00'])
|
|
17
|
+
expect(cop.offences.size).to eq(1)
|
|
18
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'accepts long numbers with underscore' do
|
|
22
|
+
inspect_source(cop, ['a = 123_456',
|
|
23
|
+
'b = 123_456.55'])
|
|
24
|
+
expect(cop.messages).to be_empty
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'accepts a short integer without underscore' do
|
|
28
|
+
inspect_source(cop, ['a = 123'])
|
|
29
|
+
expect(cop.messages).to be_empty
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'does not count a leading minus sign as a digit' do
|
|
33
|
+
inspect_source(cop, ['a = -1230'])
|
|
34
|
+
expect(cop.messages).to be_empty
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'accepts short numbers without underscore' do
|
|
38
|
+
inspect_source(cop, ['a = 123',
|
|
39
|
+
'b = 123.456'])
|
|
40
|
+
expect(cop.messages).to be_empty
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'ignores non-decimal literals' do
|
|
44
|
+
inspect_source(cop, ['a = 0b1010101010101',
|
|
45
|
+
'b = 01717171717171',
|
|
46
|
+
'c = 0xab11111111bb'])
|
|
47
|
+
expect(cop.offences).to be_empty
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'autocorrects a long integer offence' do
|
|
51
|
+
corrected = autocorrect_source(cop, ['a = 123456'])
|
|
52
|
+
expect(corrected).to eq 'a = 123_456'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'autocorrects an integer with misplaced underscore' do
|
|
56
|
+
corrected = autocorrect_source(cop, ['a = 123_456_78_90_00'])
|
|
57
|
+
expect(corrected).to eq 'a = 123_456_789_000'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'autocorrects negative numbers' do
|
|
61
|
+
corrected = autocorrect_source(cop, ['a = -123456'])
|
|
62
|
+
expect(corrected).to eq 'a = -123_456'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::OneLineConditional do
|
|
6
|
+
subject(:cop) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'registers an offence for one line if/then/end' do
|
|
9
|
+
inspect_source(cop, ['if cond then run else dont end'])
|
|
10
|
+
expect(cop.messages).to eq(['Favor the ternary operator (?:)' \
|
|
11
|
+
' over if/then/else/end constructs.'])
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::OpMethod do
|
|
6
|
+
subject(:cop) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'registers an offence for arg not named other' do
|
|
9
|
+
inspect_source(cop,
|
|
10
|
+
['def +(another)',
|
|
11
|
+
' another',
|
|
12
|
+
'end'])
|
|
13
|
+
expect(cop.offences.size).to eq(1)
|
|
14
|
+
expect(cop.messages)
|
|
15
|
+
.to eq(['When defining the + operator, name its argument *other*.'])
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'works properly even if the argument not surrounded with braces' do
|
|
19
|
+
inspect_source(cop,
|
|
20
|
+
['def + another',
|
|
21
|
+
' another',
|
|
22
|
+
'end'])
|
|
23
|
+
expect(cop.offences.size).to eq(1)
|
|
24
|
+
expect(cop.messages)
|
|
25
|
+
.to eq(['When defining the + operator, name its argument *other*.'])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'does not register an offence for arg named other' do
|
|
29
|
+
inspect_source(cop,
|
|
30
|
+
['def +(other)',
|
|
31
|
+
' other',
|
|
32
|
+
'end'])
|
|
33
|
+
expect(cop.offences).to be_empty
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'does not register an offence for []' do
|
|
37
|
+
inspect_source(cop,
|
|
38
|
+
['def [](index)',
|
|
39
|
+
' other',
|
|
40
|
+
'end'])
|
|
41
|
+
expect(cop.offences).to be_empty
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'does not register an offence for []=' do
|
|
45
|
+
inspect_source(cop,
|
|
46
|
+
['def []=(index, value)',
|
|
47
|
+
' other',
|
|
48
|
+
'end'])
|
|
49
|
+
expect(cop.offences).to be_empty
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'does not register an offence for <<' do
|
|
53
|
+
inspect_source(cop,
|
|
54
|
+
['def <<(cop)',
|
|
55
|
+
' other',
|
|
56
|
+
'end'])
|
|
57
|
+
expect(cop.offences).to be_empty
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'does not register an offence for non binary operators' do
|
|
61
|
+
inspect_source(cop,
|
|
62
|
+
['def -@', # Unary minus
|
|
63
|
+
'end',
|
|
64
|
+
'',
|
|
65
|
+
# This + is not a unary operator. It can only be
|
|
66
|
+
# called with dot notation.
|
|
67
|
+
'def +',
|
|
68
|
+
'end',
|
|
69
|
+
'',
|
|
70
|
+
'def *(a, b)', # Quite strange, but legal ruby.
|
|
71
|
+
'end'])
|
|
72
|
+
expect(cop.offences).to be_empty
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::ParameterLists, :config do
|
|
6
|
+
subject(:cop) { described_class.new(config) }
|
|
7
|
+
let(:cop_config) do
|
|
8
|
+
{
|
|
9
|
+
'Max' => 4,
|
|
10
|
+
'CountKeywordArgs' => true
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'registers an offence for a method def with 5 parameters' do
|
|
15
|
+
inspect_source(cop, ['def meth(a, b, c, d, e)',
|
|
16
|
+
'end'])
|
|
17
|
+
expect(cop.offences.size).to eq(1)
|
|
18
|
+
expect(cop.config_to_allow_offences).to eq('Max' => 5)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'accepts a method def with 4 parameters' do
|
|
22
|
+
inspect_source(cop, ['def meth(a, b, c, d)',
|
|
23
|
+
'end'])
|
|
24
|
+
expect(cop.offences).to be_empty
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context 'When CountKeywordArgs is true' do
|
|
28
|
+
it 'counts keyword arguments as well', ruby: 2.0 do
|
|
29
|
+
inspect_source(cop, ['def meth(a, b, c, d: 1, e: 2)',
|
|
30
|
+
'end'])
|
|
31
|
+
expect(cop.offences.size).to eq(1)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context 'When CountKeywordArgs is false' do
|
|
36
|
+
before { cop_config['CountKeywordArgs'] = false }
|
|
37
|
+
|
|
38
|
+
it 'it does not count keyword arguments', ruby: 2.0 do
|
|
39
|
+
inspect_source(cop, ['def meth(a, b, c, d: 1, e: 2)',
|
|
40
|
+
'end'])
|
|
41
|
+
expect(cop.offences).to be_empty
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::ParenthesesAroundCondition, :config do
|
|
6
|
+
subject(:cop) { described_class.new(config) }
|
|
7
|
+
let(:cop_config) { { 'AllowSafeAssignment' => true } }
|
|
8
|
+
|
|
9
|
+
it 'registers an offence for parentheses around condition' do
|
|
10
|
+
inspect_source(cop, ['if (x > 10)',
|
|
11
|
+
'elsif (x < 3)',
|
|
12
|
+
'end',
|
|
13
|
+
'unless (x > 10)',
|
|
14
|
+
'end',
|
|
15
|
+
'while (x > 10)',
|
|
16
|
+
'end',
|
|
17
|
+
'until (x > 10)',
|
|
18
|
+
'end',
|
|
19
|
+
'x += 1 if (x < 10)',
|
|
20
|
+
'x += 1 unless (x < 10)',
|
|
21
|
+
'x += 1 until (x < 10)',
|
|
22
|
+
'x += 1 while (x < 10)'
|
|
23
|
+
])
|
|
24
|
+
expect(cop.offences.size).to eq(9)
|
|
25
|
+
expect(cop.messages.first)
|
|
26
|
+
.to eq("Don't use parentheses around the condition of an if.")
|
|
27
|
+
expect(cop.messages.last)
|
|
28
|
+
.to eq("Don't use parentheses around the condition of a while.")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'accepts parentheses if there is no space between the keyword and (.' do
|
|
32
|
+
inspect_source(cop, ['if(x > 5) then something end'])
|
|
33
|
+
expect(cop.offences).to be_empty
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'auto-corrects parentheses around condition' do
|
|
37
|
+
corrected = autocorrect_source(cop, ['if (x > 10)',
|
|
38
|
+
'elsif (x < 3)',
|
|
39
|
+
'end',
|
|
40
|
+
'unless (x > 10)',
|
|
41
|
+
'end',
|
|
42
|
+
'while (x > 10)',
|
|
43
|
+
'end',
|
|
44
|
+
'until (x > 10)',
|
|
45
|
+
'end',
|
|
46
|
+
'x += 1 if (x < 10)',
|
|
47
|
+
'x += 1 unless (x < 10)',
|
|
48
|
+
'x += 1 while (x < 10)',
|
|
49
|
+
'x += 1 until (x < 10)'
|
|
50
|
+
])
|
|
51
|
+
expect(corrected).to eq ['if x > 10',
|
|
52
|
+
'elsif x < 3',
|
|
53
|
+
'end',
|
|
54
|
+
'unless x > 10',
|
|
55
|
+
'end',
|
|
56
|
+
'while x > 10',
|
|
57
|
+
'end',
|
|
58
|
+
'until x > 10',
|
|
59
|
+
'end',
|
|
60
|
+
'x += 1 if x < 10',
|
|
61
|
+
'x += 1 unless x < 10',
|
|
62
|
+
'x += 1 while x < 10',
|
|
63
|
+
'x += 1 until x < 10'
|
|
64
|
+
].join("\n")
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'accepts condition without parentheses' do
|
|
68
|
+
inspect_source(cop, ['if x > 10',
|
|
69
|
+
'end',
|
|
70
|
+
'unless x > 10',
|
|
71
|
+
'end',
|
|
72
|
+
'while x > 10',
|
|
73
|
+
'end',
|
|
74
|
+
'until x > 10',
|
|
75
|
+
'end',
|
|
76
|
+
'x += 1 if x < 10',
|
|
77
|
+
'x += 1 unless x < 10',
|
|
78
|
+
'x += 1 while x < 10',
|
|
79
|
+
'x += 1 until x < 10'
|
|
80
|
+
])
|
|
81
|
+
expect(cop.offences).to be_empty
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'accepts parentheses around condition in a ternary' do
|
|
85
|
+
inspect_source(cop, '(a == 0) ? b : a')
|
|
86
|
+
expect(cop.offences).to be_empty
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'is not confused by leading parenthesis in subexpression' do
|
|
90
|
+
inspect_source(cop, ['(a > b) && other ? one : two'])
|
|
91
|
+
expect(cop.offences).to be_empty
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'is not confused by unbalanced parentheses' do
|
|
95
|
+
inspect_source(cop, ['if (a + b).c()',
|
|
96
|
+
'end'])
|
|
97
|
+
expect(cop.offences).to be_empty
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context 'safe assignment is allowed' do
|
|
101
|
+
it 'accepts = in condition surrounded with parentheses' do
|
|
102
|
+
inspect_source(cop,
|
|
103
|
+
['if (test = 10)',
|
|
104
|
+
'end'
|
|
105
|
+
])
|
|
106
|
+
expect(cop.offences).to be_empty
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
context 'safe assignment is not allowed' do
|
|
112
|
+
let(:cop_config) { { 'AllowSafeAssignment' => false } }
|
|
113
|
+
|
|
114
|
+
it 'does not accept = in condition surrounded with parentheses' do
|
|
115
|
+
inspect_source(cop,
|
|
116
|
+
['if (test = 10)',
|
|
117
|
+
'end'
|
|
118
|
+
])
|
|
119
|
+
expect(cop.offences.size).to eq(1)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::PerlBackrefs do
|
|
6
|
+
subject(:cop) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'registers an offence for $1' do
|
|
9
|
+
inspect_source(cop, ['puts $1'])
|
|
10
|
+
expect(cop.offences.size).to eq(1)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'auto-corrects $1 to Regexp.last_match[1]' do
|
|
14
|
+
new_source = autocorrect_source(cop, '$1')
|
|
15
|
+
expect(new_source).to eq('Regexp.last_match[1]')
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Cop::Style::PredicateName, :config do
|
|
6
|
+
subject(:cop) { described_class.new(config) }
|
|
7
|
+
let(:cop_config) { { 'NamePrefixBlacklist' => %w(has_ is_) } }
|
|
8
|
+
|
|
9
|
+
%w(has_ is_).each do |prefix|
|
|
10
|
+
it 'registers an offence for blacklisted method_name' do
|
|
11
|
+
inspect_source(cop, ["def #{prefix}_attr",
|
|
12
|
+
' # ...',
|
|
13
|
+
'end'])
|
|
14
|
+
expect(cop.offences.size).to eq(1)
|
|
15
|
+
expect(cop.highlights).to eq(["#{prefix}_attr"])
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'accepts non-blacklisted method name' do
|
|
20
|
+
inspect_source(cop, ['def have_attr',
|
|
21
|
+
' # ...',
|
|
22
|
+
'end'])
|
|
23
|
+
expect(cop.offences).to be_empty
|
|
24
|
+
end
|
|
25
|
+
end
|