rubocop 0.20.1 → 0.21.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/CHANGELOG.md +46 -0
- data/README.md +16 -4
- data/config/default.yml +37 -10
- data/config/enabled.yml +25 -7
- data/lib/rubocop.rb +15 -19
- data/lib/rubocop/cli.rb +2 -2
- data/lib/rubocop/config.rb +40 -3
- data/lib/rubocop/config_loader.rb +6 -37
- data/lib/rubocop/config_store.rb +0 -1
- data/lib/rubocop/cop/commissioner.rb +12 -9
- data/lib/rubocop/cop/cop.rb +17 -5
- data/lib/rubocop/cop/force.rb +41 -0
- data/lib/rubocop/cop/ignored_node.rb +10 -10
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -2
- data/lib/rubocop/cop/lint/block_alignment.rb +2 -2
- data/lib/rubocop/cop/lint/condition_position.rb +2 -0
- data/lib/rubocop/cop/lint/debugger.rb +17 -3
- data/lib/rubocop/cop/lint/end_alignment.rb +3 -11
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +11 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +4 -6
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +39 -0
- data/lib/rubocop/cop/lint/unused_block_argument.rb +81 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +52 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +6 -8
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +1 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +7 -3
- data/lib/rubocop/cop/mixin/check_assignment.rb +11 -0
- data/lib/rubocop/cop/mixin/check_methods.rb +12 -0
- data/lib/rubocop/cop/mixin/percent_literal.rb +26 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -2
- data/lib/rubocop/cop/mixin/string_help.rb +0 -4
- data/lib/rubocop/cop/rails/delegate.rb +109 -0
- data/lib/rubocop/cop/style/align_hash.rb +3 -3
- data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
- data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
- data/lib/rubocop/cop/style/dot_position.rb +1 -1
- data/lib/rubocop/cop/style/encoding.rb +44 -16
- data/lib/rubocop/cop/style/indentation_width.rb +29 -19
- data/lib/rubocop/cop/style/lambda_call.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -21
- data/lib/rubocop/cop/style/predicate_name.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +18 -2
- data/lib/rubocop/cop/style/redundant_self.rb +2 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +29 -37
- data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +37 -23
- data/lib/rubocop/cop/style/trailing_comma.rb +2 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +40 -4
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +29 -0
- data/lib/rubocop/cop/team.rb +10 -2
- data/lib/rubocop/cop/util.rb +2 -2
- data/lib/rubocop/cop/{variable_inspector.rb → variable_force.rb} +45 -37
- data/lib/rubocop/cop/{variable_inspector → variable_force}/assignment.rb +1 -1
- data/lib/rubocop/cop/{variable_inspector → variable_force}/locatable.rb +1 -1
- data/lib/rubocop/cop/{variable_inspector → variable_force}/reference.rb +13 -1
- data/lib/rubocop/cop/{variable_inspector → variable_force}/scope.rb +9 -1
- data/lib/rubocop/cop/{variable_inspector → variable_force}/variable.rb +14 -4
- data/lib/rubocop/cop/{variable_inspector → variable_force}/variable_table.rb +1 -1
- data/lib/rubocop/file_inspector.rb +3 -1
- data/lib/rubocop/formatter/base_formatter.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -2
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +2 -2
- data/lib/rubocop/formatter/offense_count_formatter.rb +11 -10
- data/lib/rubocop/formatter/progress_formatter.rb +2 -2
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/options.rb +74 -58
- data/lib/rubocop/path_util.rb +17 -2
- data/lib/rubocop/rake_task.rb +23 -5
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.21.0.md +45 -0
- data/rubocop-todo.yml +6 -6
- data/rubocop.gemspec +1 -1
- data/spec/rubocop/cli_spec.rb +170 -59
- data/spec/rubocop/config_spec.rb +48 -3
- data/spec/rubocop/config_store_spec.rb +3 -3
- data/spec/rubocop/cop/commissioner_spec.rb +9 -7
- data/spec/rubocop/cop/cop_spec.rb +0 -2
- data/spec/rubocop/cop/force_spec.rb +29 -0
- data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +2 -2
- data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +1 -1
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +24 -24
- data/spec/rubocop/cop/lint/condition_position_spec.rb +7 -5
- data/spec/rubocop/cop/lint/debugger_spec.rb +26 -9
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +6 -3
- data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +7 -6
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +36 -0
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +4 -4
- data/spec/rubocop/cop/lint/underscore_prefixed_variable_name_spec.rb +179 -0
- data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +147 -0
- data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +140 -0
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +50 -48
- data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +1 -1
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +2 -0
- data/spec/rubocop/cop/rails/delegate_spec.rb +152 -0
- data/spec/rubocop/cop/style/encoding_spec.rb +131 -36
- data/spec/rubocop/cop/style/indentation_width_spec.rb +79 -0
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +32 -0
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +83 -13
- data/spec/rubocop/cop/style/string_literals_spec.rb +9 -3
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +65 -25
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +76 -0
- data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +85 -0
- data/spec/rubocop/cop/team_spec.rb +43 -0
- data/spec/rubocop/cop/{variable_inspector → variable_force}/assignment_spec.rb +3 -3
- data/spec/rubocop/cop/{variable_inspector → variable_force}/locatable_spec.rb +3 -3
- data/spec/rubocop/cop/{variable_inspector → variable_force}/scope_spec.rb +30 -2
- data/spec/rubocop/cop/{variable_inspector → variable_force}/variable_spec.rb +12 -27
- data/spec/rubocop/cop/{variable_inspector → variable_force}/variable_table_spec.rb +1 -1
- data/spec/rubocop/cop/{variable_inspector_spec.rb → variable_force_spec.rb} +4 -8
- data/spec/rubocop/formatter/base_formatter_spec.rb +2 -2
- data/spec/rubocop/formatter/offense_count_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
- data/spec/rubocop/options_spec.rb +2 -2
- data/spec/rubocop/path_util_spec.rb +47 -14
- data/spec/spec_helper.rb +9 -3
- data/spec/support/file_helper.rb +2 -0
- metadata +43 -26
- data/lib/rubocop/cop/style/final_newline.rb +0 -29
- data/spec/rubocop/cop/style/final_newline_spec.rb +0 -30
@@ -139,4 +139,47 @@ describe Rubocop::Cop::Team do
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
142
|
+
|
143
|
+
describe '#forces' do
|
144
|
+
subject(:forces) { team.forces }
|
145
|
+
let(:cop_classes) { Rubocop::Cop::Cop.non_rails }
|
146
|
+
|
147
|
+
it 'returns force instances' do
|
148
|
+
expect(forces).not_to be_empty
|
149
|
+
|
150
|
+
forces.each do |force|
|
151
|
+
expect(force).to be_a(Rubocop::Cop::Force)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when a cop joined a force' do
|
156
|
+
let(:cop_classes) { [Rubocop::Cop::Lint::UselessAssignment] }
|
157
|
+
|
158
|
+
it 'returns the force' do
|
159
|
+
expect(forces.size).to eq(1)
|
160
|
+
expect(forces.first).to be_a(Rubocop::Cop::VariableForce)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'when multiple cops joined a same force' do
|
165
|
+
let(:cop_classes) do
|
166
|
+
[
|
167
|
+
Rubocop::Cop::Lint::UselessAssignment,
|
168
|
+
Rubocop::Cop::Lint::ShadowingOuterLocalVariable
|
169
|
+
]
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'returns only one force instance' do
|
173
|
+
expect(forces.size).to eq(1)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'when no cops joined force' do
|
178
|
+
let(:cop_classes) { [Rubocop::Cop::Style::For] }
|
179
|
+
|
180
|
+
it 'returns nothing' do
|
181
|
+
expect(forces).to be_empty
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
142
185
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Rubocop::Cop::
|
5
|
+
describe Rubocop::Cop::VariableForce::Assignment do
|
6
6
|
include ASTHelper
|
7
7
|
include AST::Sexp
|
8
8
|
|
@@ -42,9 +42,9 @@ describe Rubocop::Cop::VariableInspector::Assignment do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
let(:name) { lvasgn_node.children.first }
|
45
|
-
let(:scope) { Rubocop::Cop::
|
45
|
+
let(:scope) { Rubocop::Cop::VariableForce::Scope.new(def_node) }
|
46
46
|
let(:variable) do
|
47
|
-
Rubocop::Cop::
|
47
|
+
Rubocop::Cop::VariableForce::Variable.new(name, lvasgn_node, scope)
|
48
48
|
end
|
49
49
|
let(:assignment) { described_class.new(lvasgn_node, variable) }
|
50
50
|
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Rubocop::Cop::
|
5
|
+
describe Rubocop::Cop::VariableForce::Locatable do
|
6
6
|
include ASTHelper
|
7
7
|
include AST::Sexp
|
8
8
|
|
9
9
|
class LocatableObject
|
10
|
-
include Rubocop::Cop::
|
10
|
+
include Rubocop::Cop::VariableForce::Locatable
|
11
11
|
|
12
12
|
attr_reader :node, :scope
|
13
13
|
|
@@ -38,7 +38,7 @@ describe Rubocop::Cop::VariableInspector::Locatable do
|
|
38
38
|
found_node
|
39
39
|
end
|
40
40
|
|
41
|
-
let(:scope) { Rubocop::Cop::
|
41
|
+
let(:scope) { Rubocop::Cop::VariableForce::Scope.new(def_node) }
|
42
42
|
let(:assignment) { LocatableObject.new(lvasgn_node, scope) }
|
43
43
|
|
44
44
|
describe '#ancestor_nodes_in_scope' do
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Rubocop::Cop::
|
5
|
+
describe Rubocop::Cop::VariableForce::Scope do
|
6
6
|
include ASTHelper
|
7
7
|
include AST::Sexp
|
8
8
|
|
@@ -24,7 +24,7 @@ describe Rubocop::Cop::VariableInspector::Scope do
|
|
24
24
|
|
25
25
|
let(:ast) do
|
26
26
|
ast = Rubocop::SourceParser.parse(source).ast
|
27
|
-
Rubocop::Cop::
|
27
|
+
Rubocop::Cop::VariableForce.wrap_with_top_level_node(ast)
|
28
28
|
end
|
29
29
|
|
30
30
|
let(:scope_node_type) { :def }
|
@@ -39,6 +39,34 @@ describe Rubocop::Cop::VariableInspector::Scope do
|
|
39
39
|
|
40
40
|
subject(:scope) { described_class.new(scope_node) }
|
41
41
|
|
42
|
+
describe '#name' do
|
43
|
+
context 'when the scope is instance method definition' do
|
44
|
+
let(:source) { <<-END }
|
45
|
+
def some_method
|
46
|
+
end
|
47
|
+
END
|
48
|
+
|
49
|
+
let(:scope_node_type) { :def }
|
50
|
+
|
51
|
+
it 'returns the method name' do
|
52
|
+
expect(scope.name).to eq(:some_method)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when the scope is singleton method definition' do
|
57
|
+
let(:source) { <<-END }
|
58
|
+
def self.some_method
|
59
|
+
end
|
60
|
+
END
|
61
|
+
|
62
|
+
let(:scope_node_type) { :defs }
|
63
|
+
|
64
|
+
it 'returns the method name' do
|
65
|
+
expect(scope.name).to eq(:some_method)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
42
70
|
describe '#ancestors_of_node' do
|
43
71
|
let(:source) do
|
44
72
|
<<-END
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Rubocop::Cop::
|
5
|
+
describe Rubocop::Cop::VariableForce::Variable do
|
6
6
|
include AST::Sexp
|
7
7
|
|
8
8
|
describe '.new' do
|
@@ -10,7 +10,7 @@ describe Rubocop::Cop::VariableInspector::Variable do
|
|
10
10
|
it 'raises error' do
|
11
11
|
name = :foo
|
12
12
|
declaration_node = s(:def)
|
13
|
-
scope = Rubocop::Cop::
|
13
|
+
scope = Rubocop::Cop::VariableForce::Scope.new(s(:class))
|
14
14
|
expect { described_class.new(name, declaration_node, scope) }
|
15
15
|
.to raise_error(ArgumentError)
|
16
16
|
end
|
@@ -20,50 +20,35 @@ describe Rubocop::Cop::VariableInspector::Variable do
|
|
20
20
|
describe '#referenced?' do
|
21
21
|
let(:name) { :foo }
|
22
22
|
let(:declaration_node) { s(:arg, name) }
|
23
|
-
let(:scope) { double('scope') }
|
23
|
+
let(:scope) { double('scope').as_null_object }
|
24
24
|
let(:variable) { described_class.new(name, declaration_node, scope) }
|
25
25
|
|
26
26
|
subject { variable.referenced? }
|
27
27
|
|
28
|
-
context 'when the variable is not
|
28
|
+
context 'when the variable is not assigned' do
|
29
29
|
it { should be_false }
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when the variable has an assignment' do
|
33
|
-
before do
|
34
|
-
variable.assign(s(:lvasgn, :foo))
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'and the assignment is not yet referenced' do
|
38
|
-
it { should be_false }
|
39
|
-
end
|
40
30
|
|
41
|
-
context 'and the
|
31
|
+
context 'and the variable is referenced' do
|
42
32
|
before do
|
43
|
-
variable.
|
33
|
+
variable.reference!(s(:lvar, name))
|
44
34
|
end
|
45
35
|
|
46
36
|
it { should be_true }
|
47
37
|
end
|
48
38
|
end
|
49
39
|
|
50
|
-
context 'when the variable has
|
40
|
+
context 'when the variable has an assignment' do
|
51
41
|
before do
|
52
|
-
variable.assign(s(:lvasgn,
|
53
|
-
variable.assign(s(:lvasgn, :foo))
|
42
|
+
variable.assign(s(:lvasgn, name))
|
54
43
|
end
|
55
44
|
|
56
|
-
context 'and
|
57
|
-
|
58
|
-
variable.assignments[1].reference!
|
59
|
-
end
|
60
|
-
|
61
|
-
it { should be_true }
|
45
|
+
context 'and the variable is not yet referenced' do
|
46
|
+
it { should be_false }
|
62
47
|
end
|
63
48
|
|
64
|
-
context 'and
|
49
|
+
context 'and the variable is referenced' do
|
65
50
|
before do
|
66
|
-
variable.
|
51
|
+
variable.reference!(s(:lvar, name))
|
67
52
|
end
|
68
53
|
|
69
54
|
it { should be_true }
|
@@ -2,18 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Rubocop::Cop::
|
5
|
+
describe Rubocop::Cop::VariableForce do
|
6
6
|
include AST::Sexp
|
7
7
|
|
8
|
-
|
9
|
-
include Rubocop::Cop::VariableInspector
|
10
|
-
end
|
11
|
-
|
12
|
-
subject(:inspector) { ExampleInspector.new }
|
8
|
+
subject(:force) { Rubocop::Cop::VariableForce.new([]) }
|
13
9
|
|
14
10
|
describe '#process_node' do
|
15
11
|
before do
|
16
|
-
|
12
|
+
force.variable_table.push_scope(s(:def))
|
17
13
|
end
|
18
14
|
|
19
15
|
context 'when processing lvar node' do
|
@@ -21,7 +17,7 @@ describe Rubocop::Cop::VariableInspector do
|
|
21
17
|
|
22
18
|
context 'when the variable is not yet declared' do
|
23
19
|
it 'does not raise error' do
|
24
|
-
expect {
|
20
|
+
expect { force.process_node(node) }.not_to raise_error
|
25
21
|
end
|
26
22
|
end
|
27
23
|
end
|
@@ -45,7 +45,7 @@ module Rubocop
|
|
45
45
|
describe 'invocation order' do
|
46
46
|
subject(:formatter) do
|
47
47
|
formatter = double('formatter')
|
48
|
-
def formatter.method_missing(method_name, *
|
48
|
+
def formatter.method_missing(method_name, *)
|
49
49
|
return if method_name == :output
|
50
50
|
puts method_name
|
51
51
|
end
|
@@ -109,7 +109,7 @@ module Rubocop
|
|
109
109
|
class << formatter
|
110
110
|
attr_reader :processed_file_count
|
111
111
|
|
112
|
-
def file_finished(
|
112
|
+
def file_finished(_file, _offenses)
|
113
113
|
@processed_file_count ||= 0
|
114
114
|
@processed_file_count += 1
|
115
115
|
end
|
@@ -40,7 +40,7 @@ module Rubocop
|
|
40
40
|
context 'when an offense is detected' do
|
41
41
|
let(:cop_counts) { { 'OffendedCop' => 1 } }
|
42
42
|
it 'shows the cop and the offense count' do
|
43
|
-
formatter.report_summary(
|
43
|
+
formatter.report_summary(cop_counts)
|
44
44
|
expect(output.string).to include(
|
45
45
|
"\n1 OffendedCop\n--\n1 Total")
|
46
46
|
end
|
@@ -36,7 +36,7 @@ describe Rubocop::Options, :isolated_environment do
|
|
36
36
|
|
37
37
|
expected_help = <<-END
|
38
38
|
Usage: rubocop [options] [file1, file2, ...]
|
39
|
-
--only
|
39
|
+
--only [COP1,COP2,...] Run only the given cop(s).
|
40
40
|
-c, --config FILE Specify configuration file.
|
41
41
|
--auto-gen-config Generate a configuration file acting as a
|
42
42
|
TODO list.
|
@@ -62,7 +62,7 @@ Usage: rubocop [options] [file1, file2, ...]
|
|
62
62
|
if no format is specified.
|
63
63
|
-r, --require FILE Require Ruby file.
|
64
64
|
--fail-level SEVERITY Minimum severity for exit with error code.
|
65
|
-
--show-cops [
|
65
|
+
--show-cops [COP1,COP2,...] Shows the given cops, or all cops by
|
66
66
|
default, and their configurations for the
|
67
67
|
current directory.
|
68
68
|
-d, --debug Display debug info.
|
@@ -4,7 +4,6 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Rubocop::PathUtil do
|
6
6
|
describe '#relative_path' do
|
7
|
-
pending 'builds paths relative to the current project by default'
|
8
7
|
it 'builds paths relative to PWD by default as a stop-gap' do
|
9
8
|
relative = File.join(Dir.pwd, 'relative')
|
10
9
|
expect(subject.relative_path(relative)).to eq('relative')
|
@@ -15,28 +14,62 @@ describe Rubocop::PathUtil do
|
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
|
-
describe '#match_path?' do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
describe '#match_path?', :isolated_environment do
|
18
|
+
include FileHelper
|
19
|
+
|
20
|
+
before do
|
21
|
+
create_file('file', '')
|
22
|
+
create_file('dir/file', '')
|
23
|
+
create_file('dir/files', '')
|
24
|
+
create_file('dir/dir/file', '')
|
25
|
+
create_file('dir/sub/file', '')
|
26
|
+
$stderr = StringIO.new
|
27
|
+
end
|
28
|
+
|
29
|
+
after { $stderr = STDERR }
|
30
|
+
|
31
|
+
context 'with deprecated patterns' do
|
32
|
+
it 'matches dir/** and prints warning' do
|
33
|
+
expect(subject.match_path?('dir/**', 'dir/sub/file', '.rubocop.yml'))
|
34
|
+
.to be_true
|
35
|
+
expect($stderr.string)
|
36
|
+
.to eq("Warning: Deprecated pattern style 'dir/**' in " \
|
37
|
+
".rubocop.yml. Change to 'dir/**/*'.\n")
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'matches strings to the basename and prints warning' do
|
41
|
+
expect(subject.match_path?('file', 'dir/file', '.rubocop.yml'))
|
42
|
+
.to be_true
|
43
|
+
expect($stderr.string)
|
44
|
+
.to eq("Warning: Deprecated pattern style 'file' in .rubocop.yml. " \
|
45
|
+
"Change to '**/file'.\n")
|
46
|
+
|
47
|
+
expect(subject.match_path?('file', 'dir/files', '')).to be_false
|
48
|
+
expect(subject.match_path?('dir', 'dir/file', '')).to be_false
|
49
|
+
end
|
23
50
|
end
|
24
51
|
|
25
52
|
it 'matches strings to the full path' do
|
26
|
-
expect(subject.match_path?(
|
27
|
-
|
53
|
+
expect(subject.match_path?("#{Dir.pwd}/dir/file",
|
54
|
+
"#{Dir.pwd}/dir/file", '')).to be_true
|
55
|
+
expect(subject.match_path?("#{Dir.pwd}/dir/file",
|
56
|
+
"#{Dir.pwd}/dir/dir/file", '')).to be_false
|
28
57
|
end
|
29
58
|
|
30
59
|
it 'matches glob expressions' do
|
31
|
-
expect(subject.match_path?('dir/*',
|
32
|
-
expect(subject.match_path?('dir
|
33
|
-
expect(subject.match_path?('dir/**/*', 'dir/sub/file')).to be_true
|
34
|
-
expect(subject.match_path?('
|
60
|
+
expect(subject.match_path?('dir/*', 'dir/file', '')).to be_true
|
61
|
+
expect(subject.match_path?('dir/*/*', 'dir/sub/file', '')).to be_true
|
62
|
+
expect(subject.match_path?('dir/**/*', 'dir/sub/file', '')).to be_true
|
63
|
+
expect(subject.match_path?('dir/**/*', 'dir/file', '')).to be_true
|
64
|
+
expect(subject.match_path?('**/*', 'dir/sub/file', '')).to be_true
|
65
|
+
expect(subject.match_path?('**/file', 'file', '')).to be_true
|
66
|
+
|
67
|
+
expect(subject.match_path?('sub/*', 'dir/sub/file', '')).to be_false
|
35
68
|
end
|
36
69
|
|
37
70
|
it 'matches regexps' do
|
38
|
-
expect(subject.match_path?(/^d.*e$/, 'dir/file')).to be_true
|
39
|
-
expect(subject.match_path?(/^d.*e$/, 'dir/filez')).to be_false
|
71
|
+
expect(subject.match_path?(/^d.*e$/, 'dir/file', '')).to be_true
|
72
|
+
expect(subject.match_path?(/^d.*e$/, 'dir/filez', '')).to be_false
|
40
73
|
end
|
41
74
|
end
|
42
75
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -46,11 +46,11 @@ module ExitCodeMatchers
|
|
46
46
|
end
|
47
47
|
actual && actual == code
|
48
48
|
end
|
49
|
-
failure_message_for_should do
|
49
|
+
failure_message_for_should do
|
50
50
|
"expected block to call exit(#{code}) but exit" +
|
51
51
|
(actual.nil? ? ' not called' : "(#{actual}) was called")
|
52
52
|
end
|
53
|
-
failure_message_for_should_not do
|
53
|
+
failure_message_for_should_not do
|
54
54
|
"expected block not to call exit(#{code})"
|
55
55
|
end
|
56
56
|
description do
|
@@ -125,7 +125,13 @@ def autocorrect_source(cop, source, file = nil)
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def _investigate(cop, processed_source)
|
128
|
-
|
128
|
+
forces = Rubocop::Cop::Force.all.each_with_object([]) do |klass, instances|
|
129
|
+
next unless cop.join_force?(klass)
|
130
|
+
instances << klass.new([cop])
|
131
|
+
end
|
132
|
+
|
133
|
+
commissioner =
|
134
|
+
Rubocop::Cop::Commissioner.new([cop], forces, raise_error: true)
|
129
135
|
commissioner.investigate(processed_source)
|
130
136
|
commissioner
|
131
137
|
end
|