Skip to content

CLI: excluded_files ignores --exclude=pattern (equals-sign) syntax #13

Description

@jcouball

Summary

excluded_files only recognizes the space-separated --exclude pattern form. If .yardopts or the command line contains --exclude=vendor (equals-sign syntax), the argument string "--exclude=vendor" does not == "--exclude", so the exclusion pattern is silently ignored. No files are excluded and examples from those files are run unexpectedly.

Location

lib/yard/cli/test_examples.rbexcluded_files

def excluded_files
  excluded = []
  args = YARD::Config.with_yardopts { YARD::Config.arguments.dup }
  args.each_with_index do |arg, i|
    next unless arg == '--exclude'
    next if args[i + 1].nil?

    excluded << args[i + 1]
  end

  excluded
end

Concrete example

.yardopts:

--plugin yard_example_test
--exclude=vendor

Current behavior: excluded_files returns []vendor/ files are parsed and their examples are run.

Expected behavior: excluded_files returns ["vendor"].

Proposed solution

Handle both forms by checking for the = prefix as well:

def excluded_files
  excluded = []
  args = YARD::Config.with_yardopts { YARD::Config.arguments.dup }
  args.each_with_index do |arg, i|
    if arg == '--exclude'
      excluded << args[i + 1] unless args[i + 1].nil?
    elsif arg.start_with?('--exclude=')
      excluded << arg.delete_prefix('--exclude=')
    end
  end

  excluded
end

Alternatively, use OptionParser or a regex like /\A--exclude(?:=(.+))?\z/ to handle both forms in one pass.

Acceptance criteria

  • --exclude=pattern in .yardopts excludes matching files
  • --exclude pattern (space-separated) continues to work
  • All existing cucumber scenarios continue to pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions