Skip to content

Commit

Permalink
chore(diagnostics): don't pass .rubocop.yml file path to RuboCop
Browse files Browse the repository at this point in the history
RuboCop will itself find and use any relevant configuration files based
on the file path of the file it is analyzing. Hence there is no need for
Solargraph to have it's own implementation of this logic.
  • Loading branch information
jimeh committed Jan 6, 2021
1 parent 0920e9e commit 1246724
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 27 deletions.
21 changes: 1 addition & 20 deletions lib/solargraph/diagnostics/rubocop_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,13 @@ module RubocopHelpers
# @param code [String]
# @return [Array(Array<String>, Array<String>)]
def generate_options filename, code
args = ['-f', 'j']
rubocop_file = find_rubocop_file(filename)
args.push('-c', fix_drive_letter(rubocop_file)) unless rubocop_file.nil?
args.push filename
args = ['-f', 'j', filename]
base_options = RuboCop::Options.new
options, paths = base_options.parse(args)
options[:stdin] = code
[options, paths]
end

# Find a RuboCop configuration file in a file's directory tree.
#
# @param filename [String]
# @return [String, nil]
def find_rubocop_file filename
return nil unless File.exist?(filename)
filename = File.realpath(filename)
dir = File.dirname(filename)
until File.dirname(dir) == dir
here = File.join(dir, '.rubocop.yml')
return here if File.exist?(here)
dir = File.dirname(dir)
end
nil
end

# RuboCop internally uses capitalized drive letters for Windows paths,
# so we need to convert the paths provided to the command.
#
Expand Down
7 changes: 0 additions & 7 deletions spec/diagnostics/rubocop_helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
describe Solargraph::Diagnostics::RubocopHelpers do
it "finds a .rubocop.yml file in a parent directory" do
file = File.realpath(File.join 'spec', 'fixtures', 'rubocop-subfolder-configuration', 'folder1', 'folder2', 'test.rb')
conf = File.realpath(File.join 'spec', 'fixtures', 'rubocop-subfolder-configuration', '.rubocop.yml')
found = Solargraph::Diagnostics::RubocopHelpers.find_rubocop_file(file)
expect(found).to eq(conf)
end

it "converts lower-case drive letters to upper-case" do
input = 'c:/one/two'
output = Solargraph::Diagnostics::RubocopHelpers.fix_drive_letter(input)
Expand Down

0 comments on commit 1246724

Please sign in to comment.