File tree 2 files changed +38
-3
lines changed
2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -29,20 +29,24 @@ def exclude_due_to_config?(path)
29
29
end
30
30
31
31
def include_based_files_to_inspect
32
- @include_paths . map do |path |
33
- if path =~ %r{/$}
32
+ absolute_include_paths . flat_map do |path |
33
+ if Dir . exist? ( path )
34
34
rubocop_runner . send ( :find_target_files , [ path ] )
35
35
elsif rubocop_file_to_include? ( path )
36
36
path
37
37
end
38
- end . flatten . compact
38
+ end . compact
39
39
end
40
40
41
41
def local_path ( path )
42
42
realpath = Pathname . new ( @root ) . realpath . to_s
43
43
path . gsub ( %r{^#{ realpath } /} , '' )
44
44
end
45
45
46
+ def absolute_include_paths
47
+ @include_paths . map { |path | Pathname . new ( path ) . realpath . to_s }
48
+ end
49
+
46
50
def rubocop_file_to_include? ( file )
47
51
if file =~ /\. rb$/
48
52
true
Original file line number Diff line number Diff line change @@ -62,6 +62,37 @@ def method
62
62
expect ( includes_check? ( output , "Lint/UselessAssignment" ) ) . to be false
63
63
end
64
64
65
+ it "respects excludes in an inherit_from directive" do
66
+ create_source_file ( "foo.rb" , <<-EORUBY )
67
+ def method
68
+ unused = "x"
69
+ return false
70
+ end
71
+ EORUBY
72
+ create_source_file ( "bar.rb" , <<-EORUBY )
73
+ def method
74
+ unused = 42
75
+ return true
76
+ end
77
+ EORUBY
78
+
79
+ create_source_file (
80
+ ".rubocop.yml" ,
81
+ "inherit_from: .rubocop_todo.yml\n AllCops:\n DisabledByDefault: true\n Lint/UselessAssignment:\n Enabled: true\n "
82
+ )
83
+ create_source_file (
84
+ ".rubocop_todo.yml" ,
85
+ "Lint/UselessAssignment:\n Exclude:\n - bar.rb\n "
86
+ )
87
+
88
+ output = run_engine ( "include_paths" => [ "foo.rb" , "bar.rb" ] )
89
+ issues = output . split ( "\0 " ) . map { |istr | JSON . parse ( istr ) }
90
+ lint_issues = issues . select { |issue | issue [ "check_name" ] == "Rubocop/Lint/UselessAssignment" }
91
+
92
+ expect ( lint_issues . detect { |i | i [ "location" ] [ "path" ] == "foo.rb" } ) . to be_present
93
+ expect ( lint_issues . detect { |i | i [ "location" ] [ "path" ] == "bar.rb" } ) . to be_nil
94
+ end
95
+
65
96
it "reads a file with a #!.*ruby declaration at the top" do
66
97
create_source_file ( "my_script" , <<-EORUBY )
67
98
#!/usr/bin/env ruby
You can’t perform that action at this time.
0 commit comments