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,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::Encoding do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence when no encoding present', ruby: 1.9 do
|
9
|
+
inspect_source(cop, ['def foo() end'])
|
10
|
+
|
11
|
+
expect(cop.messages).to eq(
|
12
|
+
['Missing utf-8 encoding comment.'])
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'accepts encoding on first line', ruby: 1.9 do
|
16
|
+
inspect_source(cop, ['# encoding: utf-8',
|
17
|
+
'def foo() end'])
|
18
|
+
|
19
|
+
expect(cop.offences).to be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'accepts encoding on second line when shebang present', ruby: 1.9 do
|
23
|
+
inspect_source(cop, ['#!/usr/bin/env ruby',
|
24
|
+
'# encoding: utf-8',
|
25
|
+
'def foo() end'])
|
26
|
+
|
27
|
+
expect(cop.messages).to be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'books an offence when encoding is in the wrong place', ruby: 1.9 do
|
31
|
+
inspect_source(cop, ['def foo() end',
|
32
|
+
'# encoding: utf-8'])
|
33
|
+
|
34
|
+
expect(cop.messages).to eq(
|
35
|
+
['Missing utf-8 encoding comment.'])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'does not register an offence on Ruby 2.0', ruby: 2.0 do
|
39
|
+
inspect_source(cop, ['def foo() end'])
|
40
|
+
|
41
|
+
expect(cop.offences).to be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'accepts encoding inserted by magic_encoding gem', ruby: 1.9 do
|
45
|
+
inspect_source(cop, ['# -*- encoding : utf-8 -*-',
|
46
|
+
'def foo() end'])
|
47
|
+
|
48
|
+
expect(cop.messages).to be_empty
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'accepts vim-style encoding comments', ruby: 1.9 do
|
52
|
+
inspect_source(cop, ['# vim:fileencoding=utf-8',
|
53
|
+
'def foo() end'])
|
54
|
+
expect(cop.messages).to be_empty
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::EndBlock do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'reports an offence for an END block' do
|
9
|
+
src = ['END { test }']
|
10
|
+
inspect_source(cop, src)
|
11
|
+
expect(cop.offences.size).to eq(1)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
describe Rubocop::Cop::Style::EndOfLine do
|
7
|
+
subject(:cop) { described_class.new }
|
8
|
+
|
9
|
+
it 'registers an offence for CR+LF' do
|
10
|
+
inspect_source_file(cop, ['x=0', '', "y=1\r"])
|
11
|
+
expect(cop.messages).to eq(['Carriage return character detected.'])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'highlights the whole offendng line' do
|
15
|
+
inspect_source_file(cop, ['x=0', '', "y=1\r"])
|
16
|
+
expect(cop.highlights).to eq(["y=1\r"])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'registers an offence for CR at end of file' do
|
20
|
+
inspect_source_file(cop, ["x=0\r"])
|
21
|
+
expect(cop.messages).to eq(['Carriage return character detected.'])
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when there are many lines ending with CR+LF' do
|
25
|
+
it 'registers only one offence' do
|
26
|
+
inspect_source_file(cop, ['x=0', '', 'y=1'].join("\r\n"))
|
27
|
+
expect(cop.messages.size).to eq(1)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when the default external encoding is US_ASCII' do
|
32
|
+
before(:each) do
|
33
|
+
@orig_encoding = Encoding.default_external
|
34
|
+
Encoding.default_external = Encoding::US_ASCII
|
35
|
+
end
|
36
|
+
after(:each) { Encoding.default_external = @orig_encoding }
|
37
|
+
|
38
|
+
it 'does not crash on UTF-8 encoded non-ascii characters' do
|
39
|
+
inspect_source_file(cop,
|
40
|
+
['# encoding: UTF-8',
|
41
|
+
'class Epd::ReportsController < EpdAreaController',
|
42
|
+
" 'terecht bij uw ROM-coördinator.'",
|
43
|
+
'end'].join("\n"))
|
44
|
+
expect(cop.offences).to be_empty
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::EvenOdd do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for x % 2 == 0' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['x % 2 == 0'])
|
11
|
+
expect(cop.offences.size).to eq(1)
|
12
|
+
expect(cop.messages).to eq(['Use Fixnum.even?'])
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'registers an offence for x % 2 != 0' do
|
16
|
+
inspect_source(cop,
|
17
|
+
['x % 2 != 0'])
|
18
|
+
expect(cop.offences.size).to eq(1)
|
19
|
+
expect(cop.messages).to eq(['Use Fixnum.odd?'])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'registers an offence for (x % 2) == 0' do
|
23
|
+
inspect_source(cop,
|
24
|
+
['(x % 2) == 0'])
|
25
|
+
expect(cop.offences.size).to eq(1)
|
26
|
+
expect(cop.messages).to eq(['Use Fixnum.even?'])
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'registers an offence for (x % 2) != 0' do
|
30
|
+
inspect_source(cop,
|
31
|
+
['(x % 2) != 0'])
|
32
|
+
expect(cop.offences.size).to eq(1)
|
33
|
+
expect(cop.messages).to eq(['Use Fixnum.odd?'])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'registers an offence for x % 2 == 1' do
|
37
|
+
inspect_source(cop,
|
38
|
+
['x % 2 == 1'])
|
39
|
+
expect(cop.offences.size).to eq(1)
|
40
|
+
expect(cop.messages).to eq(['Use Fixnum.odd?'])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'registers an offence for x % 2 != 1' do
|
44
|
+
inspect_source(cop,
|
45
|
+
['x % 2 != 1'])
|
46
|
+
expect(cop.offences.size).to eq(1)
|
47
|
+
expect(cop.messages).to eq(['Use Fixnum.even?'])
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'registers an offence for (x % 2) == 1' do
|
51
|
+
inspect_source(cop,
|
52
|
+
['(x % 2) == 1'])
|
53
|
+
expect(cop.offences.size).to eq(1)
|
54
|
+
expect(cop.messages).to eq(['Use Fixnum.odd?'])
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'registers an offence for (x % 2) != 1' do
|
58
|
+
inspect_source(cop,
|
59
|
+
['(x % 2) != 1'])
|
60
|
+
expect(cop.offences.size).to eq(1)
|
61
|
+
expect(cop.messages).to eq(['Use Fixnum.even?'])
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'accepts x % 3 == 0' do
|
65
|
+
inspect_source(cop,
|
66
|
+
['x % 3 == 0'])
|
67
|
+
expect(cop.offences).to be_empty
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'accepts x % 3 != 0' do
|
71
|
+
inspect_source(cop,
|
72
|
+
['x % 3 != 0'])
|
73
|
+
expect(cop.offences).to be_empty
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::FavorJoin do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for an array followed by string' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['%w(one two three) * ", "'])
|
11
|
+
expect(cop.offences.size).to eq(1)
|
12
|
+
expect(cop.messages)
|
13
|
+
.to eq(['Favor Array#join over Array#*.'])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'does not register an offence for numbers' do
|
17
|
+
inspect_source(cop,
|
18
|
+
['%w(one two three) * 4'])
|
19
|
+
expect(cop.offences).to be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'does not register an offence for ambiguous cases' do
|
23
|
+
inspect_source(cop,
|
24
|
+
['test * ", "'])
|
25
|
+
expect(cop.offences).to be_empty
|
26
|
+
|
27
|
+
inspect_source(cop,
|
28
|
+
['%w(one two three) * test'])
|
29
|
+
expect(cop.offences).to be_empty
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::FavorSprintf do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for a string followed by something' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['puts "%d" % 10'])
|
11
|
+
expect(cop.offences.size).to eq(1)
|
12
|
+
expect(cop.messages)
|
13
|
+
.to eq(['Favor sprintf over String#%.'])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'registers an offence for something followed by an array' do
|
17
|
+
inspect_source(cop,
|
18
|
+
['puts x % [10, 11]'])
|
19
|
+
expect(cop.offences.size).to eq(1)
|
20
|
+
expect(cop.messages)
|
21
|
+
.to eq(['Favor sprintf over String#%.'])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'does not register an offence for numbers' do
|
25
|
+
inspect_source(cop,
|
26
|
+
['puts 10 % 4'])
|
27
|
+
expect(cop.offences).to be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'does not register an offence for ambiguous cases' do
|
31
|
+
inspect_source(cop,
|
32
|
+
['puts x % 4'])
|
33
|
+
expect(cop.offences).to be_empty
|
34
|
+
|
35
|
+
inspect_source(cop,
|
36
|
+
['puts x % Y'])
|
37
|
+
expect(cop.offences).to be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'works if the first operand contains embedded expressions' do
|
41
|
+
inspect_source(cop,
|
42
|
+
['puts "#{x * 5} %d #{@test}" % 10'])
|
43
|
+
expect(cop.offences.size).to eq(1)
|
44
|
+
expect(cop.messages)
|
45
|
+
.to eq(['Favor sprintf over String#%.'])
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::FavorUnlessOverNegatedIf do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for if with exclamation point condition' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['if !a_condition',
|
11
|
+
' some_method',
|
12
|
+
'end',
|
13
|
+
'some_method if !a_condition'
|
14
|
+
])
|
15
|
+
expect(cop.messages).to eq(
|
16
|
+
['Favor unless (or control flow or) over if for negative ' \
|
17
|
+
'conditions.'] * 2)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'registers an offence for if with "not" condition' do
|
21
|
+
inspect_source(cop,
|
22
|
+
['if not a_condition',
|
23
|
+
' some_method',
|
24
|
+
'end',
|
25
|
+
'some_method if not a_condition'])
|
26
|
+
expect(cop.messages).to eq(
|
27
|
+
['Favor unless (or control flow or) over if for negative ' \
|
28
|
+
'conditions.'] * 2)
|
29
|
+
expect(cop.offences.map(&:line)).to eq([1, 4])
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'accepts an if/else with negative condition' do
|
33
|
+
inspect_source(cop,
|
34
|
+
['if !a_condition',
|
35
|
+
' some_method',
|
36
|
+
'else',
|
37
|
+
' something_else',
|
38
|
+
'end',
|
39
|
+
'if not a_condition',
|
40
|
+
' some_method',
|
41
|
+
'elsif other_condition',
|
42
|
+
' something_else',
|
43
|
+
'end'])
|
44
|
+
expect(cop.offences).to be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'accepts an if where only part of the contition is negated' do
|
48
|
+
inspect_source(cop,
|
49
|
+
['if !condition && another_condition',
|
50
|
+
' some_method',
|
51
|
+
'end',
|
52
|
+
'if not condition or another_condition',
|
53
|
+
' some_method',
|
54
|
+
'end',
|
55
|
+
'some_method if not condition or another_condition'])
|
56
|
+
expect(cop.offences).to be_empty
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'is not confused by negated elsif' do
|
60
|
+
inspect_source(cop,
|
61
|
+
['if test.is_a?(String)',
|
62
|
+
' 3',
|
63
|
+
'elsif test.is_a?(Array)',
|
64
|
+
' 2',
|
65
|
+
'elsif !test.nil?',
|
66
|
+
' 1',
|
67
|
+
'end'])
|
68
|
+
|
69
|
+
expect(cop.offences).to be_empty
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'does not blow up for ternary ops' do
|
73
|
+
inspect_source(cop, 'a ? b : c')
|
74
|
+
expect(cop.offences).to be_empty
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::FavorUntilOverNegatedWhile do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for while with exclamation point condition' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['while !a_condition',
|
11
|
+
' some_method',
|
12
|
+
'end',
|
13
|
+
'some_method while !a_condition'
|
14
|
+
])
|
15
|
+
expect(cop.messages).to eq(
|
16
|
+
['Favor until over while for negative conditions.'] * 2)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'registers an offence for while with "not" condition' do
|
20
|
+
inspect_source(cop,
|
21
|
+
['while (not a_condition)',
|
22
|
+
' some_method',
|
23
|
+
'end',
|
24
|
+
'some_method while not a_condition'])
|
25
|
+
expect(cop.messages).to eq(
|
26
|
+
['Favor until over while for negative conditions.'] * 2)
|
27
|
+
expect(cop.offences.map(&:line)).to eq([1, 4])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts an while where only part of the contition is negated' do
|
31
|
+
inspect_source(cop,
|
32
|
+
['while !a_condition && another_condition',
|
33
|
+
' some_method',
|
34
|
+
'end',
|
35
|
+
'while not a_condition or another_condition',
|
36
|
+
' some_method',
|
37
|
+
'end',
|
38
|
+
'some_method while not a_condition or other_cond'])
|
39
|
+
expect(cop.messages).to be_empty
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::FinalNewline do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for missing final newline' do
|
9
|
+
source = ['x = 0', 'top']
|
10
|
+
inspect_source(cop, source)
|
11
|
+
expect(cop.offences.size).to eq(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'accepts a final newline' do
|
15
|
+
source = ['x = 0', 'top', '']
|
16
|
+
inspect_source(cop, source)
|
17
|
+
expect(cop.offences).to be_empty
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'accepts an empty file' do
|
21
|
+
source = ['']
|
22
|
+
inspect_source(cop, source)
|
23
|
+
expect(cop.offences).to be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'auto-corrects missing newline' do
|
27
|
+
new_source = autocorrect_source(cop, ['x = 0'])
|
28
|
+
expect(new_source).to eq(['x = 0', ''].join("\n"))
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::FlipFlop do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for inclusive flip flops' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['DATA.each_line do |line|',
|
11
|
+
'print line if (line =~ /begin/)..(line =~ /end/)',
|
12
|
+
'end'])
|
13
|
+
expect(cop.offences.size).to eq(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'registers an offence for exclusive flip flops' do
|
17
|
+
inspect_source(cop,
|
18
|
+
['DATA.each_line do |line|',
|
19
|
+
'print line if (line =~ /begin/)...(line =~ /end/)',
|
20
|
+
'end'])
|
21
|
+
expect(cop.offences.size).to eq(1)
|
22
|
+
end
|
23
|
+
end
|