Skip to content

Commit

Permalink
modify yardopts parsing to ignore hash and c-style comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eprothro committed Feb 8, 2017
1 parent fdf71a4 commit 58f63f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/yard/cli/yardopts_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ def yardopts_options(opts)

private

# Parses the .yardopts file for default yard options
# Parses the .yardopts file for default yard options,
# ignoring comment lines beginning with // or #
# @return [Array<String>] an array of options parsed from .yardopts
def yardopts(file = options_file)
return [] unless use_yardopts_file
File.read_binary(file).shell_split
contents = File.read_binary(file)
opts = contents.gsub(%r{(#|//).*\n?}, "")
opts.shell_split
rescue Errno::ENOENT
[]
end
Expand Down
13 changes: 13 additions & 0 deletions spec/cli/yardoc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,23 @@ def foo; end
optsdata = String.new("foo bar")
expect(optsdata).to receive(:shell_split)
expect(File).to receive(:read_binary).with("test").and_return(optsdata)
allow(optsdata).to receive(:gsub).and_return(optsdata)
@yardoc.options_file = "test"
@yardoc.run
end

it "ignores .yardopts tokens that are comments" do
optsdata = String.new("--one-file --locale es # --locale en\n// --title not_my_title")
expect(File).to receive(:read_binary).with("test").and_return(optsdata)
@yardoc.options_file = "test"
@yardoc.run

expect(@yardoc.options.onefile).to be_truthy
expect(@yardoc.options.locale).to eq('es')
expect(@yardoc.options.title).not_to eq('not_my_title')
expect(@yardoc.options.serializer.options)
end

it "allows opts specified in command line to override yardopts file" do
expect(File).to receive(:read_binary).with(".yardopts").and_return("-o NOTMYPATH")
@yardoc.run("-o", "MYPATH", "FILE")
Expand Down

0 comments on commit 58f63f4

Please sign in to comment.