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.

Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/README.md +16 -4
  4. data/config/default.yml +37 -10
  5. data/config/enabled.yml +25 -7
  6. data/lib/rubocop.rb +15 -19
  7. data/lib/rubocop/cli.rb +2 -2
  8. data/lib/rubocop/config.rb +40 -3
  9. data/lib/rubocop/config_loader.rb +6 -37
  10. data/lib/rubocop/config_store.rb +0 -1
  11. data/lib/rubocop/cop/commissioner.rb +12 -9
  12. data/lib/rubocop/cop/cop.rb +17 -5
  13. data/lib/rubocop/cop/force.rb +41 -0
  14. data/lib/rubocop/cop/ignored_node.rb +10 -10
  15. data/lib/rubocop/cop/lint/ambiguous_operator.rb +1 -1
  16. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -2
  17. data/lib/rubocop/cop/lint/block_alignment.rb +2 -2
  18. data/lib/rubocop/cop/lint/condition_position.rb +2 -0
  19. data/lib/rubocop/cop/lint/debugger.rb +17 -3
  20. data/lib/rubocop/cop/lint/end_alignment.rb +3 -11
  21. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
  22. data/lib/rubocop/cop/lint/rescue_exception.rb +11 -0
  23. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +4 -6
  24. data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +39 -0
  25. data/lib/rubocop/cop/lint/unused_block_argument.rb +81 -0
  26. data/lib/rubocop/cop/lint/unused_method_argument.rb +52 -0
  27. data/lib/rubocop/cop/lint/useless_assignment.rb +6 -8
  28. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -0
  29. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  30. data/lib/rubocop/cop/lint/void.rb +1 -1
  31. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
  32. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +7 -3
  33. data/lib/rubocop/cop/mixin/check_assignment.rb +11 -0
  34. data/lib/rubocop/cop/mixin/check_methods.rb +12 -0
  35. data/lib/rubocop/cop/mixin/percent_literal.rb +26 -0
  36. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -2
  37. data/lib/rubocop/cop/mixin/string_help.rb +0 -4
  38. data/lib/rubocop/cop/rails/delegate.rb +109 -0
  39. data/lib/rubocop/cop/style/align_hash.rb +3 -3
  40. data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
  41. data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
  42. data/lib/rubocop/cop/style/dot_position.rb +1 -1
  43. data/lib/rubocop/cop/style/encoding.rb +44 -16
  44. data/lib/rubocop/cop/style/indentation_width.rb +29 -19
  45. data/lib/rubocop/cop/style/lambda_call.rb +1 -1
  46. data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -1
  47. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -21
  48. data/lib/rubocop/cop/style/predicate_name.rb +1 -1
  49. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  50. data/lib/rubocop/cop/style/redundant_begin.rb +18 -2
  51. data/lib/rubocop/cop/style/redundant_self.rb +2 -2
  52. data/lib/rubocop/cop/style/regexp_literal.rb +29 -37
  53. data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
  54. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  55. data/lib/rubocop/cop/style/trailing_blank_lines.rb +37 -23
  56. data/lib/rubocop/cop/style/trailing_comma.rb +2 -3
  57. data/lib/rubocop/cop/style/trivial_accessors.rb +40 -4
  58. data/lib/rubocop/cop/style/unneeded_capital_w.rb +29 -0
  59. data/lib/rubocop/cop/team.rb +10 -2
  60. data/lib/rubocop/cop/util.rb +2 -2
  61. data/lib/rubocop/cop/{variable_inspector.rb → variable_force.rb} +45 -37
  62. data/lib/rubocop/cop/{variable_inspector → variable_force}/assignment.rb +1 -1
  63. data/lib/rubocop/cop/{variable_inspector → variable_force}/locatable.rb +1 -1
  64. data/lib/rubocop/cop/{variable_inspector → variable_force}/reference.rb +13 -1
  65. data/lib/rubocop/cop/{variable_inspector → variable_force}/scope.rb +9 -1
  66. data/lib/rubocop/cop/{variable_inspector → variable_force}/variable.rb +14 -4
  67. data/lib/rubocop/cop/{variable_inspector → variable_force}/variable_table.rb +1 -1
  68. data/lib/rubocop/file_inspector.rb +3 -1
  69. data/lib/rubocop/formatter/base_formatter.rb +1 -1
  70. data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -2
  71. data/lib/rubocop/formatter/disabled_lines_formatter.rb +2 -2
  72. data/lib/rubocop/formatter/offense_count_formatter.rb +11 -10
  73. data/lib/rubocop/formatter/progress_formatter.rb +2 -2
  74. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
  75. data/lib/rubocop/options.rb +74 -58
  76. data/lib/rubocop/path_util.rb +17 -2
  77. data/lib/rubocop/rake_task.rb +23 -5
  78. data/lib/rubocop/version.rb +1 -1
  79. data/relnotes/v0.21.0.md +45 -0
  80. data/rubocop-todo.yml +6 -6
  81. data/rubocop.gemspec +1 -1
  82. data/spec/rubocop/cli_spec.rb +170 -59
  83. data/spec/rubocop/config_spec.rb +48 -3
  84. data/spec/rubocop/config_store_spec.rb +3 -3
  85. data/spec/rubocop/cop/commissioner_spec.rb +9 -7
  86. data/spec/rubocop/cop/cop_spec.rb +0 -2
  87. data/spec/rubocop/cop/force_spec.rb +29 -0
  88. data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +2 -2
  89. data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +1 -1
  90. data/spec/rubocop/cop/lint/block_alignment_spec.rb +24 -24
  91. data/spec/rubocop/cop/lint/condition_position_spec.rb +7 -5
  92. data/spec/rubocop/cop/lint/debugger_spec.rb +26 -9
  93. data/spec/rubocop/cop/lint/end_alignment_spec.rb +6 -3
  94. data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +7 -6
  95. data/spec/rubocop/cop/lint/rescue_exception_spec.rb +36 -0
  96. data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +4 -4
  97. data/spec/rubocop/cop/lint/underscore_prefixed_variable_name_spec.rb +179 -0
  98. data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +147 -0
  99. data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +140 -0
  100. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +50 -48
  101. data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +1 -1
  102. data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +2 -0
  103. data/spec/rubocop/cop/rails/delegate_spec.rb +152 -0
  104. data/spec/rubocop/cop/style/encoding_spec.rb +131 -36
  105. data/spec/rubocop/cop/style/indentation_width_spec.rb +79 -0
  106. data/spec/rubocop/cop/style/redundant_begin_spec.rb +32 -0
  107. data/spec/rubocop/cop/style/regexp_literal_spec.rb +83 -13
  108. data/spec/rubocop/cop/style/string_literals_spec.rb +9 -3
  109. data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +65 -25
  110. data/spec/rubocop/cop/style/trivial_accessors_spec.rb +76 -0
  111. data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +85 -0
  112. data/spec/rubocop/cop/team_spec.rb +43 -0
  113. data/spec/rubocop/cop/{variable_inspector → variable_force}/assignment_spec.rb +3 -3
  114. data/spec/rubocop/cop/{variable_inspector → variable_force}/locatable_spec.rb +3 -3
  115. data/spec/rubocop/cop/{variable_inspector → variable_force}/scope_spec.rb +30 -2
  116. data/spec/rubocop/cop/{variable_inspector → variable_force}/variable_spec.rb +12 -27
  117. data/spec/rubocop/cop/{variable_inspector → variable_force}/variable_table_spec.rb +1 -1
  118. data/spec/rubocop/cop/{variable_inspector_spec.rb → variable_force_spec.rb} +4 -8
  119. data/spec/rubocop/formatter/base_formatter_spec.rb +2 -2
  120. data/spec/rubocop/formatter/offense_count_formatter_spec.rb +1 -1
  121. data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
  122. data/spec/rubocop/options_spec.rb +2 -2
  123. data/spec/rubocop/path_util_spec.rb +47 -14
  124. data/spec/spec_helper.rb +9 -3
  125. data/spec/support/file_helper.rb +2 -0
  126. metadata +43 -26
  127. data/lib/rubocop/cop/style/final_newline.rb +0 -29
  128. 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::VariableInspector::Assignment do
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::VariableInspector::Scope.new(def_node) }
45
+ let(:scope) { Rubocop::Cop::VariableForce::Scope.new(def_node) }
46
46
  let(:variable) do
47
- Rubocop::Cop::VariableInspector::Variable.new(name, lvasgn_node, scope)
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::VariableInspector::Locatable do
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::VariableInspector::Locatable
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::VariableInspector::Scope.new(def_node) }
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::VariableInspector::Scope do
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::VariableInspector.wrap_with_top_level_node(ast)
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::VariableInspector::Variable do
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::VariableInspector::Scope.new(s(:class))
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 yet assigned' do
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 assignment is referenced' do
31
+ context 'and the variable is referenced' do
42
32
  before do
43
- variable.assignments.first.reference!
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 multiple assignments' do
40
+ context 'when the variable has an assignment' do
51
41
  before do
52
- variable.assign(s(:lvasgn, :foo))
53
- variable.assign(s(:lvasgn, :foo))
42
+ variable.assign(s(:lvasgn, name))
54
43
  end
55
44
 
56
- context 'and only once assignment is referenced' do
57
- before do
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 all assignments are referenced' do
49
+ context 'and the variable is referenced' do
65
50
  before do
66
- variable.assignments.each { |a| a.reference! }
51
+ variable.reference!(s(:lvar, name))
67
52
  end
68
53
 
69
54
  it { should be_true }
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Rubocop::Cop::VariableInspector::VariableTable do
5
+ describe Rubocop::Cop::VariableForce::VariableTable do
6
6
  include AST::Sexp
7
7
 
8
8
  subject(:variable_table) { described_class.new }
@@ -2,18 +2,14 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Rubocop::Cop::VariableInspector do
5
+ describe Rubocop::Cop::VariableForce do
6
6
  include AST::Sexp
7
7
 
8
- class ExampleInspector
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
- inspector.variable_table.push_scope(s(:def))
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 { inspector.process_node(node) }.not_to raise_error
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, *args)
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(file, offenses)
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(1, cop_counts)
43
+ formatter.report_summary(cop_counts)
44
44
  expect(output.string).to include(
45
45
  "\n1 OffendedCop\n--\n1 Total")
46
46
  end
@@ -40,7 +40,7 @@ module Rubocop
40
40
 
41
41
  describe '#report_file_as_mark' do
42
42
  before do
43
- formatter.report_file_as_mark(files.first, offenses)
43
+ formatter.report_file_as_mark(offenses)
44
44
  end
45
45
 
46
46
  def offense_with_severity(severity)
@@ -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 COP Run just one cop.
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 [cop1,cop2,...] Shows the given cops, or all cops by
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
- it 'matches strings to the basename' do
20
- expect(subject.match_path?('file', '/dir/file')).to be_true
21
- expect(subject.match_path?('file', '/dir/files')).to be_false
22
- expect(subject.match_path?('dir', '/dir/file')).to be_false
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?('/dir/file', '/dir/file')).to be_true
27
- expect(subject.match_path?('/dir/file', '/dir/dir/file')).to be_false
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/*', 'dir/file')).to be_true
32
- expect(subject.match_path?('dir/*', 'dir/sub/file')).to be_true
33
- expect(subject.match_path?('dir/**/*', 'dir/sub/file')).to be_true
34
- expect(subject.match_path?('sub/*', 'dir/sub/file')).to be_false
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 |block|
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 |block|
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
- commissioner = Rubocop::Cop::Commissioner.new([cop], raise_error: true)
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
@@ -11,6 +11,8 @@ module FileHelper
11
11
 
12
12
  File.open(file_path, 'w') do |file|
13
13
  case content
14
+ when ''
15
+ # Write nothing. Create empty file.
14
16
  when String
15
17
  file.puts content
16
18
  when Array