rubocop 0.19.1 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/CHANGELOG.md +60 -1
- data/CONTRIBUTING.md +2 -1
- data/README.md +9 -7
- data/config/default.yml +3 -3
- data/config/disabled.yml +4 -0
- data/config/enabled.yml +45 -21
- data/lib/rubocop.rb +30 -9
- data/lib/rubocop/cli.rb +1 -1
- data/lib/rubocop/comment_config.rb +4 -2
- data/lib/rubocop/config.rb +16 -22
- data/lib/rubocop/config_loader.rb +29 -26
- data/lib/rubocop/cop/commissioner.rb +1 -1
- data/lib/rubocop/cop/cop.rb +6 -6
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/condition_position.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +9 -7
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/empty_interpolation.rb +22 -0
- data/lib/rubocop/cop/lint/end_in_method.rb +1 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/eval.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +9 -0
- data/lib/rubocop/cop/lint/loop.rb +2 -2
- data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
- data/lib/rubocop/cop/lint/space_before_first_arg.rb +36 -0
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +14 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +3 -3
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/offense.rb +3 -21
- data/lib/rubocop/cop/rails/action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/default_scope.rb +1 -1
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
- data/lib/rubocop/cop/rails/read_write_attribute.rb +43 -0
- data/lib/rubocop/cop/rails/scope_args.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/severity.rb +76 -0
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +1 -1
- data/lib/rubocop/cop/style/accessor_method_name.rb +2 -2
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/align_hash.rb +1 -1
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/{favor_join.rb → array_join.rb} +2 -2
- data/lib/rubocop/cop/style/begin_block.rb +1 -1
- data/lib/rubocop/cop/style/block_nesting.rb +12 -8
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +1 -1
- data/lib/rubocop/cop/style/case_equality.rb +1 -1
- data/lib/rubocop/cop/style/case_indentation.rb +5 -5
- data/lib/rubocop/cop/style/class_methods.rb +19 -3
- data/lib/rubocop/cop/style/class_vars.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +17 -7
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/{def_parentheses.rb → def_with_parentheses.rb} +0 -0
- data/lib/rubocop/cop/style/{hash_methods.rb → deprecated_hash_methods.rb} +5 -4
- data/lib/rubocop/cop/style/double_negation.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +2 -2
- data/lib/rubocop/cop/style/file_name.rb +1 -1
- data/lib/rubocop/cop/style/for.rb +2 -2
- data/lib/rubocop/cop/style/format_string.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +69 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +6 -10
- data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -2
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/line_end_concatenation.rb +16 -9
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -2
- data/lib/rubocop/cop/style/negated_if.rb +37 -0
- data/lib/rubocop/cop/style/negated_while.rb +33 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +14 -10
- data/lib/rubocop/cop/style/non_nil_check.rb +70 -0
- data/lib/rubocop/cop/style/not.rb +25 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/op_method.rb +4 -4
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
- data/lib/rubocop/cop/style/predicate_name.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +3 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/self_assignment.rb +2 -2
- data/lib/rubocop/cop/style/signal_exception.rb +6 -3
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +6 -5
- data/lib/rubocop/cop/style/single_space_before_first_arg.rb +41 -0
- data/lib/rubocop/cop/style/space_around_operators.rb +1 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +8 -8
- data/lib/rubocop/cop/style/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +10 -5
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/team.rb +12 -13
- data/lib/rubocop/cop/util.rb +4 -0
- data/lib/rubocop/cop/variable_inspector/locatable.rb +1 -1
- data/lib/rubocop/cop/variable_inspector/variable_table.rb +1 -1
- data/lib/rubocop/file_inspector.rb +46 -10
- data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +56 -0
- data/lib/rubocop/formatter/emacs_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +2 -1
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +2 -4
- data/lib/rubocop/formatter/json_formatter.rb +3 -7
- data/lib/rubocop/formatter/progress_formatter.rb +1 -3
- data/lib/rubocop/formatter/simple_text_formatter.rb +7 -3
- data/lib/rubocop/options.rb +29 -10
- data/lib/rubocop/path_util.rb +2 -1
- data/lib/rubocop/processed_source.rb +8 -0
- data/lib/rubocop/target_finder.rb +33 -12
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.20.0.md +69 -0
- data/rubocop-todo.yml +2 -2
- data/spec/rubocop/cli_spec.rb +269 -94
- data/spec/rubocop/config_loader_spec.rb +14 -14
- data/spec/rubocop/config_spec.rb +8 -8
- data/spec/rubocop/cop/lint/deprecated_class_methods_spec.rb +11 -6
- data/spec/rubocop/cop/lint/empty_interpolation_spec.rb +18 -0
- data/spec/rubocop/cop/lint/eval_spec.rb +2 -4
- data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +10 -0
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +0 -8
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +4 -4
- data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +48 -0
- data/spec/rubocop/cop/lint/string_conversion_in_interpolation_spec.rb +10 -0
- data/spec/rubocop/cop/lint/useless_access_modifier_spec.rb +154 -0
- data/spec/rubocop/cop/offense_spec.rb +1 -1
- data/spec/rubocop/cop/rails/read_write_attribute_spec.rb +19 -0
- data/spec/rubocop/cop/severity_spec.rb +113 -0
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +10 -10
- data/spec/rubocop/cop/style/alias_spec.rb +2 -2
- data/spec/rubocop/cop/style/and_or_spec.rb +2 -2
- data/spec/rubocop/cop/style/{favor_join_spec.rb → array_join_spec.rb} +1 -3
- data/spec/rubocop/cop/style/block_nesting_spec.rb +4 -4
- data/spec/rubocop/cop/style/case_equality_spec.rb +1 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +12 -9
- data/spec/rubocop/cop/style/class_methods_spec.rb +23 -0
- data/spec/rubocop/cop/style/collection_methods_spec.rb +2 -2
- data/spec/rubocop/cop/style/{hash_methods_spec.rb → deprecated_hash_methods_spec.rb} +3 -3
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/style/even_odd_spec.rb +8 -8
- data/spec/rubocop/cop/style/file_name_spec.rb +55 -42
- data/spec/rubocop/cop/style/for_spec.rb +4 -4
- data/spec/rubocop/cop/style/format_string_spec.rb +10 -10
- data/spec/rubocop/cop/style/guard_clause_spec.rb +77 -0
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +4 -2
- data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +4 -4
- data/spec/rubocop/cop/style/lambda_spec.rb +2 -2
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +21 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +1 -1
- data/spec/rubocop/cop/style/{favor_unless_over_negated_if_spec.rb → negated_if_spec.rb} +8 -3
- data/spec/rubocop/cop/style/{favor_until_over_negated_while_spec.rb → negated_while_spec.rb} +8 -3
- data/spec/rubocop/cop/style/nil_comparison_spec.rb +7 -13
- data/spec/rubocop/cop/style/non_nil_check_spec.rb +35 -0
- data/spec/rubocop/cop/style/not_spec.rb +11 -0
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +0 -2
- data/spec/rubocop/cop/style/op_method_spec.rb +10 -2
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +2 -2
- data/spec/rubocop/cop/style/predicate_name_spec.rb +2 -1
- data/spec/rubocop/cop/style/raise_args_spec.rb +5 -0
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/style/self_assignment_spec.rb +4 -4
- data/spec/rubocop/cop/style/signal_exception_spec.rb +24 -0
- data/spec/rubocop/cop/style/single_line_block_params_spec.rb +2 -0
- data/spec/rubocop/cop/style/single_space_before_first_arg_spec.rb +63 -0
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +6 -5
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +6 -3
- data/spec/rubocop/cop/style/unless_else_spec.rb +2 -4
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +15 -6
- data/spec/rubocop/cop/style/when_then_spec.rb +3 -4
- data/spec/rubocop/cop/team_spec.rb +4 -18
- data/spec/rubocop/file_inspector_spec.rb +4 -0
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +69 -0
- data/spec/rubocop/options_spec.rb +5 -0
- data/spec/rubocop/target_finder_spec.rb +42 -11
- data/spec/support/shared_context.rb +1 -1
- data/spec/support/statement_modifier_helper.rb +1 -1
- metadata +75 -50
- data/lib/rubocop/cop/rails/read_attribute.rb +0 -28
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +0 -24
- data/lib/rubocop/cop/style/favor_until_over_negated_while.rb +0 -20
- data/spec/rubocop/cop/rails/read_attribute_spec.rb +0 -13
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Rubocop::Cop::Style::
|
5
|
+
describe Rubocop::Cop::Style::DeprecatedHashMethods do
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'registers an offense for has_key? with one arg' do
|
@@ -10,7 +10,7 @@ describe Rubocop::Cop::Style::HashMethods do
|
|
10
10
|
['o.has_key?(o)'])
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
expect(cop.messages)
|
13
|
-
.to eq(['has_key
|
13
|
+
.to eq(['`Hash#has_key?` is deprecated in favor of `Hash#key?`.'])
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'accepts has_key? with no args' do
|
@@ -24,7 +24,7 @@ describe Rubocop::Cop::Style::HashMethods do
|
|
24
24
|
['o.has_value?(o)'])
|
25
25
|
expect(cop.offenses.size).to eq(1)
|
26
26
|
expect(cop.messages)
|
27
|
-
.to eq(['has_value
|
27
|
+
.to eq(['`Hash#has_value?` is deprecated in favor of `Hash#value?`.'])
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'accepts has_value? with no args' do
|
@@ -16,7 +16,7 @@ describe Rubocop::Cop::Style::EmptyLinesAroundAccessModifier do
|
|
16
16
|
'end'])
|
17
17
|
expect(cop.offenses.size).to eq(1)
|
18
18
|
expect(cop.messages)
|
19
|
-
.to eq(["Keep a blank line before and after
|
19
|
+
.to eq(["Keep a blank line before and after `#{access_modifier}`."])
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'requires blank line after #{access_modifier}' do
|
@@ -29,7 +29,7 @@ describe Rubocop::Cop::Style::EmptyLinesAroundAccessModifier do
|
|
29
29
|
'end'])
|
30
30
|
expect(cop.offenses.size).to eq(1)
|
31
31
|
expect(cop.messages)
|
32
|
-
.to eq(["Keep a blank line before and after
|
32
|
+
.to eq(["Keep a blank line before and after `#{access_modifier}`."])
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'accepts missing blank line when at the beginning of class/module' do
|
@@ -9,56 +9,56 @@ describe Rubocop::Cop::Style::EvenOdd do
|
|
9
9
|
inspect_source(cop,
|
10
10
|
['x % 2 == 0'])
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
|
-
expect(cop.messages).to eq(['
|
12
|
+
expect(cop.messages).to eq(['Replace with `Fixnum#even?`.'])
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'registers an offense for x % 2 != 0' do
|
16
16
|
inspect_source(cop,
|
17
17
|
['x % 2 != 0'])
|
18
18
|
expect(cop.offenses.size).to eq(1)
|
19
|
-
expect(cop.messages).to eq(['
|
19
|
+
expect(cop.messages).to eq(['Replace with `Fixnum#odd?`.'])
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'registers an offense for (x % 2) == 0' do
|
23
23
|
inspect_source(cop,
|
24
24
|
['(x % 2) == 0'])
|
25
25
|
expect(cop.offenses.size).to eq(1)
|
26
|
-
expect(cop.messages).to eq(['
|
26
|
+
expect(cop.messages).to eq(['Replace with `Fixnum#even?`.'])
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'registers an offense for (x % 2) != 0' do
|
30
30
|
inspect_source(cop,
|
31
31
|
['(x % 2) != 0'])
|
32
32
|
expect(cop.offenses.size).to eq(1)
|
33
|
-
expect(cop.messages).to eq(['
|
33
|
+
expect(cop.messages).to eq(['Replace with `Fixnum#odd?`.'])
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'registers an offense for x % 2 == 1' do
|
37
37
|
inspect_source(cop,
|
38
38
|
['x % 2 == 1'])
|
39
39
|
expect(cop.offenses.size).to eq(1)
|
40
|
-
expect(cop.messages).to eq(['
|
40
|
+
expect(cop.messages).to eq(['Replace with `Fixnum#odd?`.'])
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'registers an offense for x % 2 != 1' do
|
44
44
|
inspect_source(cop,
|
45
45
|
['x % 2 != 1'])
|
46
46
|
expect(cop.offenses.size).to eq(1)
|
47
|
-
expect(cop.messages).to eq(['
|
47
|
+
expect(cop.messages).to eq(['Replace with `Fixnum#even?`.'])
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'registers an offense for (x % 2) == 1' do
|
51
51
|
inspect_source(cop,
|
52
52
|
['(x % 2) == 1'])
|
53
53
|
expect(cop.offenses.size).to eq(1)
|
54
|
-
expect(cop.messages).to eq(['
|
54
|
+
expect(cop.messages).to eq(['Replace with `Fixnum#odd?`.'])
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'registers an offense for (x % 2) != 1' do
|
58
58
|
inspect_source(cop,
|
59
59
|
['(x % 2) != 1'])
|
60
60
|
expect(cop.offenses.size).to eq(1)
|
61
|
-
expect(cop.messages).to eq(['
|
61
|
+
expect(cop.messages).to eq(['Replace with `Fixnum#even?`.'])
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'accepts x % 3 == 0' do
|
@@ -6,66 +6,79 @@ describe Rubocop::Cop::Style::FileName do
|
|
6
6
|
subject(:cop) { described_class.new(config) }
|
7
7
|
|
8
8
|
let(:config) do
|
9
|
-
Rubocop::Config.new(
|
9
|
+
Rubocop::Config.new(
|
10
|
+
{ 'AllCops' => { 'Include' => includes } },
|
11
|
+
'/some/.rubocop.yml'
|
12
|
+
)
|
10
13
|
end
|
11
14
|
|
12
15
|
let(:includes) { [] }
|
16
|
+
let(:source) { ['print 1'] }
|
17
|
+
let(:processed_source) { parse_source(source) }
|
13
18
|
|
14
|
-
|
15
|
-
source = ['print 1']
|
16
|
-
processed_source = parse_source(source)
|
19
|
+
before do
|
17
20
|
allow(processed_source.buffer)
|
18
|
-
|
21
|
+
.to receive(:name).and_return(filename)
|
19
22
|
_investigate(cop, processed_source)
|
20
|
-
expect(cop.offenses.size).to eq(1)
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
.to
|
28
|
-
|
29
|
-
expect(cop.offenses.size).to eq(1)
|
25
|
+
context 'with camelCase file names ending in .rb' do
|
26
|
+
let(:filename) { '/some/dir/testCase.rb' }
|
27
|
+
|
28
|
+
it 'reports an offense' do
|
29
|
+
expect(cop.offenses.size).to eq(1)
|
30
|
+
end
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
.to
|
37
|
-
|
38
|
-
expect(cop.offenses).to be_empty
|
33
|
+
context 'with camelCase file names without file extension' do
|
34
|
+
let(:filename) { '/some/dir/testCase' }
|
35
|
+
|
36
|
+
it 'reports an offense' do
|
37
|
+
expect(cop.offenses.size).to eq(1)
|
38
|
+
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
.to
|
46
|
-
|
47
|
-
expect(cop.offenses).to be_empty
|
41
|
+
context 'with snake_case file names ending in .rb' do
|
42
|
+
let(:filename) { '/some/dir/test_case.rb' }
|
43
|
+
|
44
|
+
it 'reports an offense' do
|
45
|
+
expect(cop.offenses).to be_empty
|
46
|
+
end
|
48
47
|
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
.to
|
55
|
-
|
56
|
-
expect(cop.offenses).to be_empty
|
49
|
+
context 'with snake_case file names without file extension' do
|
50
|
+
let(:filename) { '/some/dir/test_case' }
|
51
|
+
|
52
|
+
it 'does not report an offense' do
|
53
|
+
expect(cop.offenses).to be_empty
|
54
|
+
end
|
57
55
|
end
|
58
56
|
|
59
|
-
context '
|
60
|
-
let(:
|
57
|
+
context 'with snake_case file names with non-rb extension' do
|
58
|
+
let(:filename) { '/some/dir/some_task.rake' }
|
61
59
|
|
62
|
-
it '
|
63
|
-
source = ['print 1']
|
64
|
-
processed_source = parse_source(source)
|
65
|
-
allow(processed_source.buffer)
|
66
|
-
.to receive(:name).and_return('/some/dir/Gemfile')
|
67
|
-
_investigate(cop, processed_source)
|
60
|
+
it 'does not report an offense' do
|
68
61
|
expect(cop.offenses).to be_empty
|
69
62
|
end
|
70
63
|
end
|
64
|
+
|
65
|
+
context 'with snake_case file names with multiple extensions' do
|
66
|
+
let(:filename) { 'some/dir/some_view.html.slim_spec.rb' }
|
67
|
+
|
68
|
+
it 'does not report an offense' do
|
69
|
+
expect(cop.offenses).to be_empty
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when the file is specified in AllCops/Include' do
|
74
|
+
let(:includes) { ['**/Gemfile'] }
|
75
|
+
|
76
|
+
context 'with a non-snake_case file name' do
|
77
|
+
let(:filename) { '/some/dir/Gemfile' }
|
78
|
+
|
79
|
+
it 'does not report an offense' do
|
80
|
+
expect(cop.offenses).to be_empty
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
71
84
|
end
|
@@ -15,7 +15,7 @@ describe Rubocop::Cop::Style::For, :config do
|
|
15
15
|
' puts n',
|
16
16
|
' end',
|
17
17
|
'end'])
|
18
|
-
expect(cop.messages).to eq(['Prefer
|
18
|
+
expect(cop.messages).to eq(['Prefer `each` over `for`.'])
|
19
19
|
expect(cop.highlights).to eq(['for'])
|
20
20
|
expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'for')
|
21
21
|
end
|
@@ -30,7 +30,7 @@ describe Rubocop::Cop::Style::For, :config do
|
|
30
30
|
' puts n',
|
31
31
|
' end',
|
32
32
|
'end'])
|
33
|
-
expect(cop.messages).to eq(['Prefer
|
33
|
+
expect(cop.messages).to eq(['Prefer `each` over `for`.'])
|
34
34
|
expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
|
35
35
|
end
|
36
36
|
|
@@ -75,7 +75,7 @@ describe Rubocop::Cop::Style::For, :config do
|
|
75
75
|
' puts n',
|
76
76
|
' end',
|
77
77
|
'end'])
|
78
|
-
expect(cop.messages).to eq(['Prefer
|
78
|
+
expect(cop.messages).to eq(['Prefer `for` over `each`.'])
|
79
79
|
expect(cop.highlights).to eq(['each'])
|
80
80
|
expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'each')
|
81
81
|
end
|
@@ -90,7 +90,7 @@ describe Rubocop::Cop::Style::For, :config do
|
|
90
90
|
' puts n',
|
91
91
|
' end',
|
92
92
|
'end'])
|
93
|
-
expect(cop.messages).to eq(['Prefer
|
93
|
+
expect(cop.messages).to eq(['Prefer `for` over `each`.'])
|
94
94
|
expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
|
95
95
|
end
|
96
96
|
|
@@ -12,7 +12,7 @@ describe Rubocop::Cop::Style::FormatString, :config do
|
|
12
12
|
['puts "%d" % 10'])
|
13
13
|
expect(cop.offenses.size).to eq(1)
|
14
14
|
expect(cop.messages)
|
15
|
-
.to eq(['Favor sprintf over String
|
15
|
+
.to eq(['Favor `sprintf` over `String#%`.'])
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'registers an offense for something followed by an array' do
|
@@ -20,7 +20,7 @@ describe Rubocop::Cop::Style::FormatString, :config do
|
|
20
20
|
['puts x % [10, 11]'])
|
21
21
|
expect(cop.offenses.size).to eq(1)
|
22
22
|
expect(cop.messages)
|
23
|
-
.to eq(['Favor sprintf over String
|
23
|
+
.to eq(['Favor `sprintf` over `String#%`.'])
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'does not register an offense for numbers' do
|
@@ -44,7 +44,7 @@ describe Rubocop::Cop::Style::FormatString, :config do
|
|
44
44
|
['puts "#{x * 5} %d #{@test}" % 10'])
|
45
45
|
expect(cop.offenses.size).to eq(1)
|
46
46
|
expect(cop.messages)
|
47
|
-
.to eq(['Favor sprintf over String
|
47
|
+
.to eq(['Favor `sprintf` over `String#%`.'])
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'registers an offense for format' do
|
@@ -52,7 +52,7 @@ describe Rubocop::Cop::Style::FormatString, :config do
|
|
52
52
|
['format(something, a, b)'])
|
53
53
|
expect(cop.offenses.size).to eq(1)
|
54
54
|
expect(cop.messages)
|
55
|
-
.to eq(['Favor sprintf over format
|
55
|
+
.to eq(['Favor `sprintf` over `format`.'])
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -64,7 +64,7 @@ describe Rubocop::Cop::Style::FormatString, :config do
|
|
64
64
|
['puts "%d" % 10'])
|
65
65
|
expect(cop.offenses.size).to eq(1)
|
66
66
|
expect(cop.messages)
|
67
|
-
.to eq(['Favor format over String
|
67
|
+
.to eq(['Favor `format` over `String#%`.'])
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'registers an offense for something followed by an array' do
|
@@ -72,7 +72,7 @@ describe Rubocop::Cop::Style::FormatString, :config do
|
|
72
72
|
['puts x % [10, 11]'])
|
73
73
|
expect(cop.offenses.size).to eq(1)
|
74
74
|
expect(cop.messages)
|
75
|
-
.to eq(['Favor format over String
|
75
|
+
.to eq(['Favor `format` over `String#%`.'])
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'does not register an offense for numbers' do
|
@@ -96,7 +96,7 @@ describe Rubocop::Cop::Style::FormatString, :config do
|
|
96
96
|
['puts "#{x * 5} %d #{@test}" % 10'])
|
97
97
|
expect(cop.offenses.size).to eq(1)
|
98
98
|
expect(cop.messages)
|
99
|
-
.to eq(['Favor format over String
|
99
|
+
.to eq(['Favor `format` over `String#%`.'])
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'registers an offense for sprintf' do
|
@@ -104,7 +104,7 @@ describe Rubocop::Cop::Style::FormatString, :config do
|
|
104
104
|
['sprintf(something, a, b)'])
|
105
105
|
expect(cop.offenses.size).to eq(1)
|
106
106
|
expect(cop.messages)
|
107
|
-
.to eq(['Favor format over sprintf
|
107
|
+
.to eq(['Favor `format` over `sprintf`.'])
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -116,7 +116,7 @@ describe Rubocop::Cop::Style::FormatString, :config do
|
|
116
116
|
['format(something, a, b)'])
|
117
117
|
expect(cop.offenses.size).to eq(1)
|
118
118
|
expect(cop.messages)
|
119
|
-
.to eq(['Favor String
|
119
|
+
.to eq(['Favor `String#%` over `format`.'])
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'registers an offense for sprintf' do
|
@@ -124,7 +124,7 @@ describe Rubocop::Cop::Style::FormatString, :config do
|
|
124
124
|
['sprintf(something, a, b)'])
|
125
125
|
expect(cop.offenses.size).to eq(1)
|
126
126
|
expect(cop.messages)
|
127
|
-
.to eq(['Favor String
|
127
|
+
.to eq(['Favor `String#%` over `sprintf`.'])
|
128
128
|
end
|
129
129
|
|
130
130
|
it 'accepts String#%' do
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::GuardClause do
|
6
|
+
let(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'reports an offense if method body is if without else' do
|
9
|
+
src = ['def func',
|
10
|
+
' if something',
|
11
|
+
' work',
|
12
|
+
' work_more',
|
13
|
+
' end',
|
14
|
+
'end']
|
15
|
+
inspect_source(cop, src)
|
16
|
+
expect(cop.offenses.size).to eq(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'reports an offense if method body ends with if without else' do
|
20
|
+
src = ['def func',
|
21
|
+
' test',
|
22
|
+
' if something',
|
23
|
+
' work',
|
24
|
+
' work_more',
|
25
|
+
' end',
|
26
|
+
'end']
|
27
|
+
inspect_source(cop, src)
|
28
|
+
expect(cop.offenses.size).to eq(1)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'accepts a method which body is if with else' do
|
32
|
+
src = ['def func',
|
33
|
+
' if something',
|
34
|
+
' work',
|
35
|
+
' work_more',
|
36
|
+
' else',
|
37
|
+
' test',
|
38
|
+
' end',
|
39
|
+
'end']
|
40
|
+
inspect_source(cop, src)
|
41
|
+
expect(cop.offenses).to be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'accepts a method which body does not end with if' do
|
45
|
+
src = ['def func',
|
46
|
+
' if something',
|
47
|
+
' work',
|
48
|
+
' work_more',
|
49
|
+
' end',
|
50
|
+
' test',
|
51
|
+
'end']
|
52
|
+
inspect_source(cop, src)
|
53
|
+
expect(cop.offenses).to be_empty
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'accepts a method which body does not end with if' do
|
57
|
+
src = ['def func',
|
58
|
+
' if something',
|
59
|
+
' work',
|
60
|
+
' work_more',
|
61
|
+
' end',
|
62
|
+
' test',
|
63
|
+
'end']
|
64
|
+
inspect_source(cop, src)
|
65
|
+
expect(cop.offenses).to be_empty
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'accepts a method whose body is an if with a one-line body' do
|
69
|
+
src = ['def func',
|
70
|
+
' if something',
|
71
|
+
' work',
|
72
|
+
' end',
|
73
|
+
'end']
|
74
|
+
inspect_source(cop, src)
|
75
|
+
expect(cop.offenses).to be_empty
|
76
|
+
end
|
77
|
+
end
|
@@ -72,9 +72,11 @@ describe Rubocop::Cop::Style::HashSyntax, :config do
|
|
72
72
|
expect(new_source).to eq('{ a: 1, b: 2}')
|
73
73
|
end
|
74
74
|
|
75
|
-
it '
|
75
|
+
it 'auto-corrects even if it interferes with SpaceAroundOperators' do
|
76
|
+
# Clobbering caused by two cops changing in the same range is dealt with
|
77
|
+
# by the auto-correct loop, so there's no reason to avoid a change.
|
76
78
|
new_source = autocorrect_source(cop, '{ :a=>1, :b=>2 }')
|
77
|
-
expect(new_source).to eq('{ :
|
79
|
+
expect(new_source).to eq('{ a: 1, b: 2 }')
|
78
80
|
end
|
79
81
|
|
80
82
|
context 'with SpaceAroundOperators disabled' do
|
@@ -23,9 +23,9 @@ describe Rubocop::Cop::Style::IfUnlessModifier do
|
|
23
23
|
" #{body}",
|
24
24
|
' end'])
|
25
25
|
expect(cop.messages).to eq(
|
26
|
-
['Favor modifier if usage when
|
26
|
+
['Favor modifier `if` usage when having a single-line' \
|
27
27
|
' body. Another good alternative is the usage of control flow' \
|
28
|
-
'
|
28
|
+
' `&&`/`||`.'])
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'registers an offense for short multiline if near an else etc' do
|
@@ -59,9 +59,9 @@ describe Rubocop::Cop::Style::IfUnlessModifier do
|
|
59
59
|
' b',
|
60
60
|
'end'])
|
61
61
|
expect(cop.messages).to eq(
|
62
|
-
['Favor modifier unless usage when
|
62
|
+
['Favor modifier `unless` usage when having a single-line' \
|
63
63
|
' body. Another good alternative is the usage of control flow' \
|
64
|
-
'
|
64
|
+
' `&&`/`||`.'])
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'accepts code with EOL comment since user might want to keep it' do
|