diff --git a/lib/yard/cli/yardopts_command.rb b/lib/yard/cli/yardopts_command.rb index b86497e85..8e5ae8729 100644 --- a/lib/yard/cli/yardopts_command.rb +++ b/lib/yard/cli/yardopts_command.rb @@ -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] 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 diff --git a/spec/cli/yardoc_spec.rb b/spec/cli/yardoc_spec.rb index 5430cef32..f4e017a67 100644 --- a/spec/cli/yardoc_spec.rb +++ b/spec/cli/yardoc_spec.rb @@ -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")