Class: Yard::Lint::TodoGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/lint/todo_generator.rb

Overview

Generates .yard-lint-todo.yml file with exclusions for current violations

Constant Summary collapse

DEFAULT_EXCLUDE_LIMIT =

Default grouping threshold (15+ files triggers pattern grouping)

15

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, config:, force:, exclude_limit:) ⇒ TodoGenerator

Initialize a new TodoGenerator instance

Parameters:

  • path (String)

    directory or file path containing Ruby files to analyze

  • config (Config)

    yard-lint configuration object

  • force (Boolean)

    whether to overwrite existing todo file

  • exclude_limit (Integer)

    minimum files before grouping into patterns



27
28
29
30
31
32
33
34
# File 'lib/yard/lint/todo_generator.rb', line 27

def initialize(path:, config:, force:, exclude_limit:)
  @path = path
  @config = config
  @force = force
  @exclude_limit = exclude_limit
  @todo_path = File.join(Dir.pwd, '.yard-lint-todo.yml')
  @config_path = File.join(Dir.pwd, Config::DEFAULT_CONFIG_FILE)
end

Class Method Details

.generate(path:, config:, force: false, exclude_limit: DEFAULT_EXCLUDE_LIMIT) ⇒ Hash

Generate .yard-lint-todo.yml file with exclusions for current violations

Parameters:

  • path (String)

    directory or file path containing Ruby files to analyze for violations

  • config (Config)

    yard-lint configuration object with validator settings

  • force (Boolean) (defaults to: false)

    whether to overwrite existing todo file if present

  • exclude_limit (Integer) (defaults to: DEFAULT_EXCLUDE_LIMIT)

    minimum files in directory before grouping into wildcard patterns

Returns:

  • (Hash)

    result with :message, :offense_count, :validator_count



17
18
19
# File 'lib/yard/lint/todo_generator.rb', line 17

def generate(path:, config:, force: false, exclude_limit: DEFAULT_EXCLUDE_LIMIT)
  new(path: path, config: config, force: force, exclude_limit: exclude_limit).generate
end

Instance Method Details

#generateHash

Generate the .yard-lint-todo.yml file with exclusions for current violations

Returns:

  • (Hash)

    result hash with :message, :offense_count, :validator_count keys



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/yard/lint/todo_generator.rb', line 38

def generate
  # Step 1: Check if todo file exists
  validate_todo_file_not_exists! unless @force

  # Step 2: Run linting to collect violations
  lint_result = run_linting

  # Step 3: Handle clean codebase
  return no_violations_result if lint_result[:violations_by_validator].empty?

  # Step 4: Group violations by validator
  violations_by_validator = group_violations_by_validator(lint_result)

  # Step 5: Generate todo YAML content
  todo_content = build_todo_yaml(violations_by_validator)

  # Step 6: Write todo file
  File.write(@todo_path, todo_content)

  # Step 7: Update main config to inherit todo file
  update_main_config

  # Step 8: Build success message
  build_success_result(violations_by_validator, lint_result[:total_offenses])
end