Class: Yard::Lint::ConfigUpdater

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

Overview

Updates existing .yard-lint.yml configuration files Adds new validators, removes obsolete ones, preserves user settings

Constant Summary collapse

TEMPLATES_DIR =

Path to templates directory

File.expand_path('templates', __dir__)
CATEGORY_ORDER =

Category order for output

%w[Documentation Tags Warnings Semantic].freeze
CATEGORY_COMMENTS =

Category comments for output

{
  'Documentation' => '# Documentation validators',
  'Tags' => '# Tags validators',
  'Warnings' => '# Warnings validators - catches YARD parser errors',
  'Semantic' => '# Semantic validators'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, strict: false) ⇒ ConfigUpdater

Returns a new instance of ConfigUpdater.

Parameters:

  • path (String, nil) (defaults to: nil)

    path to config file

  • strict (Boolean) (defaults to: false)

    use strict template



34
35
36
37
# File 'lib/yard/lint/config_updater.rb', line 34

def initialize(path: nil, strict: false)
  @path = path || File.join(Dir.pwd, Config::DEFAULT_CONFIG_FILE)
  @strict = strict
end

Class Method Details

.update(path: nil, strict: false) ⇒ Hash

Update an existing config file

Parameters:

  • path (String) (defaults to: nil)

    path to config file (default: .yard-lint.yml in current dir)

  • strict (Boolean) (defaults to: false)

    use strict template as base for new validators

Returns:

  • (Hash)

    result hash with :added, :removed, :preserved arrays



27
28
29
# File 'lib/yard/lint/config_updater.rb', line 27

def update(path: nil, strict: false)
  new(path: path, strict: strict).update
end

Instance Method Details

#updateHash

Perform the config update

Returns:

  • (Hash)

    result with :added, :removed, :preserved arrays



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/yard/lint/config_updater.rb', line 41

def update
  validate_file_exists!

  existing_config = load_existing_config
  template_config = load_template_config

  result = merge_configs(existing_config, template_config)

  write_updated_config(result[:config])

  {
    added: result[:added],
    removed: result[:removed],
    preserved: result[:preserved]
  }
end