Class: Yard::Lint::Config
- Inherits:
-
Object
- Object
- Yard::Lint::Config
- Defined in:
- lib/yard/lint/config.rb
Overview
Configuration object for YARD Lint
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
Default YAML config file name
'.yard-lint.yml'- VALID_SEVERITIES =
Valid severity levels for fail_on_severity
%w[error warning convention never].freeze
- METADATA_KEYS =
Metadata keys to skip when merging validator configs
%w[Description StyleGuide VersionAdded VersionChanged].freeze
Instance Attribute Summary collapse
-
#only_validators ⇒ Object
Returns the value of attribute only_validators.
-
#raw_config ⇒ Object
readonly
Returns the value of attribute raw_config.
-
#validators ⇒ Object
readonly
Returns the value of attribute validators.
Class Method Summary collapse
-
.find_config_file(start_path) ⇒ String?
Find config file by searching upwards from start_path.
-
.from_file(path) ⇒ Yard::Lint::Config
Load configuration from a YAML file.
-
.load(start_path: Dir.pwd) ⇒ Yard::Lint::Config?
Search for and load config file from current directory upwards.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Allow hash-like access for convenience.
-
#all_validators ⇒ Hash
Get AllValidators section.
-
#build_default_validator_config(validator_name) ⇒ Hash
Build default configuration for a validator.
-
#build_validators_config ⇒ Hash
Build validators configuration from raw config.
-
#default_exclusions ⇒ Array<String>
Default exclusion patterns for typical Ruby/Rails projects.
-
#diff_mode_default_base_ref ⇒ String?
Diff mode default base ref (main or master).
-
#exclude ⇒ Array<String>
Global file exclusion patterns.
-
#exclude=(value) ⇒ Object
Set global exclude patterns.
-
#fail_on_severity ⇒ String
Minimum severity level to fail on.
-
#fail_on_severity=(value) ⇒ Object
Set fail on severity level.
-
#get_validator_config_with_default(validator_name, key) ⇒ Object?
Generic helper to get validator configuration with default fallback.
-
#initialize(raw_config = {}) {|_self| ... } ⇒ Config
constructor
A new instance of Config.
-
#merge_validator_config(base, override) ⇒ Hash
Merge validator configuration.
-
#min_coverage ⇒ Float?
Minimum documentation coverage percentage required.
-
#min_coverage=(value) ⇒ Object
Set minimum coverage percentage.
-
#options ⇒ Array<String>
YARD command-line options.
-
#options=(value) ⇒ Object
Set YARD options.
-
#set_validator_config(validator_name, key, value) ⇒ Object
Generic helper to set validator configuration.
-
#validator_all_excludes(validator_name) ⇒ Array<String>
Combined global and per-validator exclusions Returns all exclusion patterns that apply to this validator.
-
#validator_config(validator_name, key) ⇒ Object?
Get validator-specific configuration value.
-
#validator_enabled?(validator_name) ⇒ Boolean
Check if a validator is enabled.
-
#validator_exclude(validator_name) ⇒ Array<String>
Get validator-specific exclude patterns.
-
#validator_severity(validator_name) ⇒ String
Get validator severity.
-
#validator_yard_options(validator_name) ⇒ Array<String>
Get YARD options for a specific validator Falls back to global options if validator doesn’t specify its own.
Constructor Details
#initialize(raw_config = {}) {|_self| ... } ⇒ Config
Returns a new instance of Config.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/yard/lint/config.rb', line 21 def initialize(raw_config = {}) @raw_config = raw_config # Validate configuration structure and values ConfigValidator.validate!(@raw_config) unless raw_config.empty? @validators = build_validators_config @only_validators = [] yield self if block_given? end |
Instance Attribute Details
#only_validators ⇒ Object
Returns the value of attribute only_validators.
9 10 11 |
# File 'lib/yard/lint/config.rb', line 9 def only_validators @only_validators end |
#raw_config ⇒ Object (readonly)
Returns the value of attribute raw_config.
8 9 10 |
# File 'lib/yard/lint/config.rb', line 8 def raw_config @raw_config end |
#validators ⇒ Object (readonly)
Returns the value of attribute validators.
8 9 10 |
# File 'lib/yard/lint/config.rb', line 8 def validators @validators end |
Class Method Details
.find_config_file(start_path) ⇒ String?
Find config file by searching upwards from start_path
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/yard/lint/config.rb', line 60 def find_config_file(start_path) current = File.(start_path) root = File.('/') loop do config_path = File.join(current, DEFAULT_CONFIG_FILE) return config_path if File.exist?(config_path) break if current == root current = File.dirname(current) end nil end |
.from_file(path) ⇒ Yard::Lint::Config
Load configuration from a YAML file
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/yard/lint/config.rb', line 38 def from_file(path) unless File.exist?(path) raise Errors::ConfigFileNotFoundError, "Config file not found: #{path}" end # Load with inheritance support merged_yaml = ConfigLoader.load(path) new(merged_yaml) end |
.load(start_path: Dir.pwd) ⇒ Yard::Lint::Config?
Search for and load config file from current directory upwards
52 53 54 55 |
# File 'lib/yard/lint/config.rb', line 52 def load(start_path: Dir.pwd) config_path = find_config_file(start_path) config_path ? from_file(config_path) : nil end |
Instance Method Details
#[](key) ⇒ Object?
Allow hash-like access for convenience
227 228 229 |
# File 'lib/yard/lint/config.rb', line 227 def [](key) respond_to?(key) ? send(key) : nil end |
#all_validators ⇒ Hash
Get AllValidators section
254 255 256 |
# File 'lib/yard/lint/config.rb', line 254 def all_validators @raw_config['AllValidators'] || {} end |
#build_default_validator_config(validator_name) ⇒ Hash
Build default configuration for a validator
282 283 284 285 286 287 288 289 290 |
# File 'lib/yard/lint/config.rb', line 282 def build_default_validator_config(validator_name) # Get defaults from validator config validator_cfg = ConfigLoader.validator_config(validator_name) defaults = validator_cfg&.defaults || {} base = ConfigLoader::DEFAULT_VALIDATOR_CONFIG.dup # Merge validator-specific defaults with base config base.merge(defaults) end |
#build_validators_config ⇒ Hash
Build validators configuration from raw config
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/yard/lint/config.rb', line 260 def build_validators_config config = {} # Start with defaults for all validators ConfigLoader::ALL_VALIDATORS.each do |validator_name| config[validator_name] = build_default_validator_config(validator_name) end # Apply validator-specific overrides @raw_config.each do |key, value| next unless key.include?('/') # Validator-specific config next unless ConfigLoader::ALL_VALIDATORS.include?(key) config[key] = merge_validator_config(config[key], value) if value.is_a?(Hash) end config end |
#default_exclusions ⇒ Array<String>
Default exclusion patterns for typical Ruby/Rails projects
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/yard/lint/config.rb', line 100 def default_exclusions [ # Version control '\.git', # Dependencies 'vendor/**/*', 'node_modules/**/*', # Test directories 'spec/**/*', 'test/**/*', 'features/**/*', # Temporary and cache directories 'tmp/**/*', 'log/**/*', 'coverage/**/*', '.bundle/**/*', # Rails-specific 'db/schema.rb', 'db/migrate/**/*', 'public/assets/**/*', 'public/packs/**/*', 'public/system/**/*', # Build artifacts 'pkg/**/*', 'doc/**/*', '.yardoc/**/*', # Configuration that doesn't need docs 'config/initializers/**/*', 'config/environments/**/*' ] end |
#diff_mode_default_base_ref ⇒ String?
Diff mode default base ref (main or master)
140 141 142 143 |
# File 'lib/yard/lint/config.rb', line 140 def diff_mode_default_base_ref diff_config = all_validators['DiffMode'] || {} diff_config['DefaultBaseRef'] end |
#exclude ⇒ Array<String>
Global file exclusion patterns
94 95 96 |
# File 'lib/yard/lint/config.rb', line 94 def exclude all_validators['Exclude'] || default_exclusions end |
#exclude=(value) ⇒ Object
Set global exclude patterns
205 206 207 208 |
# File 'lib/yard/lint/config.rb', line 205 def exclude=(value) @raw_config['AllValidators'] ||= {} @raw_config['AllValidators']['Exclude'] = value end |
#fail_on_severity ⇒ String
Minimum severity level to fail on
134 135 136 |
# File 'lib/yard/lint/config.rb', line 134 def fail_on_severity all_validators['FailOnSeverity'] || 'warning' end |
#fail_on_severity=(value) ⇒ Object
Set fail on severity level
212 213 214 215 |
# File 'lib/yard/lint/config.rb', line 212 def fail_on_severity=(value) @raw_config['AllValidators'] ||= {} @raw_config['AllValidators']['FailOnSeverity'] = value end |
#get_validator_config_with_default(validator_name, key) ⇒ Object?
Generic helper to get validator configuration with default fallback
245 246 247 248 249 250 |
# File 'lib/yard/lint/config.rb', line 245 def get_validator_config_with_default(validator_name, key) validator_config(validator_name, key) || begin validator_cfg = ConfigLoader.validator_config(validator_name) validator_cfg&.defaults&.dig(key) end end |
#merge_validator_config(base, override) ⇒ Hash
Merge validator configuration
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/yard/lint/config.rb', line 296 def merge_validator_config(base, override) result = base.dup override.each do |key, value| # Skip metadata keys next if METADATA_KEYS.include?(key) result[key] = if value.is_a?(Array) && result[key].is_a?(Array) value # Array replacement elsif value.is_a?(Hash) && result[key].is_a?(Hash) result[key].merge(value) else value end end result end |
#min_coverage ⇒ Float?
Minimum documentation coverage percentage required
147 148 149 |
# File 'lib/yard/lint/config.rb', line 147 def min_coverage all_validators['MinCoverage'] end |
#min_coverage=(value) ⇒ Object
Set minimum coverage percentage
219 220 221 222 |
# File 'lib/yard/lint/config.rb', line 219 def min_coverage=(value) @raw_config['AllValidators'] ||= {} @raw_config['AllValidators']['MinCoverage'] = value end |
#options ⇒ Array<String>
YARD command-line options
79 80 81 |
# File 'lib/yard/lint/config.rb', line 79 def all_validators['YardOptions'] || [] end |
#options=(value) ⇒ Object
Set YARD options
198 199 200 201 |
# File 'lib/yard/lint/config.rb', line 198 def (value) @raw_config['AllValidators'] ||= {} @raw_config['AllValidators']['YardOptions'] = value end |
#set_validator_config(validator_name, key, value) ⇒ Object
Generic helper to set validator configuration
235 236 237 238 239 |
# File 'lib/yard/lint/config.rb', line 235 def set_validator_config(validator_name, key, value) @raw_config[validator_name] ||= {} @raw_config[validator_name][key] = value @validators = build_validators_config end |
#validator_all_excludes(validator_name) ⇒ Array<String>
Combined global and per-validator exclusions Returns all exclusion patterns that apply to this validator
182 183 184 |
# File 'lib/yard/lint/config.rb', line 182 def validator_all_excludes(validator_name) exclude + validator_exclude(validator_name) end |
#validator_config(validator_name, key) ⇒ Object?
Get validator-specific configuration value
190 191 192 |
# File 'lib/yard/lint/config.rb', line 190 def validator_config(validator_name, key) validators.dig(validator_name, key) end |
#validator_enabled?(validator_name) ⇒ Boolean
Check if a validator is enabled
154 155 156 157 158 159 160 |
# File 'lib/yard/lint/config.rb', line 154 def validator_enabled?(validator_name) # If --only is specified, it takes full control return only_validators.include?(validator_name) if only_validators.any? validator_config = validators[validator_name] || {} validator_config['Enabled'] != false # Default to true end |
#validator_exclude(validator_name) ⇒ Array<String>
Get validator-specific exclude patterns
173 174 175 176 |
# File 'lib/yard/lint/config.rb', line 173 def validator_exclude(validator_name) validator_config = validators[validator_name] || {} validator_config['Exclude'] || [] end |
#validator_severity(validator_name) ⇒ String
Get validator severity
165 166 167 168 |
# File 'lib/yard/lint/config.rb', line 165 def validator_severity(validator_name) validator_config = validators[validator_name] || {} validator_config['Severity'] || 'warning' end |
#validator_yard_options(validator_name) ⇒ Array<String>
Get YARD options for a specific validator Falls back to global options if validator doesn’t specify its own
87 88 89 90 |
# File 'lib/yard/lint/config.rb', line 87 def (validator_name) validator_config = validators[validator_name] || {} validator_config['YardOptions'] || end |