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
-
#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.
-
#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.
-
#initialize(raw_config = {}) {|_self| ... } ⇒ Config
constructor
A new instance of Config.
-
#options ⇒ Array<String>
YARD command-line options.
-
#options=(value) ⇒ Object
Set YARD options.
-
#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.
20 21 22 23 24 25 |
# File 'lib/yard/lint/config.rb', line 20 def initialize(raw_config = {}) @raw_config = raw_config @validators = build_validators_config yield self if block_given? end |
Instance Attribute Details
#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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yard/lint/config.rb', line 54 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
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yard/lint/config.rb', line 32 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
46 47 48 49 |
# File 'lib/yard/lint/config.rb', line 46 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
164 165 166 |
# File 'lib/yard/lint/config.rb', line 164 def [](key) respond_to?(key) ? send(key) : nil end |
#exclude ⇒ Array<String>
Global file exclusion patterns
88 89 90 |
# File 'lib/yard/lint/config.rb', line 88 def exclude all_validators['Exclude'] || ['\.git', 'vendor/**/*', 'node_modules/**/*'] end |
#exclude=(value) ⇒ Object
Set global exclude patterns
149 150 151 152 |
# File 'lib/yard/lint/config.rb', line 149 def exclude=(value) @raw_config['AllValidators'] ||= {} @raw_config['AllValidators']['Exclude'] = value end |
#fail_on_severity ⇒ String
Minimum severity level to fail on
94 95 96 |
# File 'lib/yard/lint/config.rb', line 94 def fail_on_severity all_validators['FailOnSeverity'] || 'warning' end |
#fail_on_severity=(value) ⇒ Object
Set fail on severity level
156 157 158 159 |
# File 'lib/yard/lint/config.rb', line 156 def fail_on_severity=(value) @raw_config['AllValidators'] ||= {} @raw_config['AllValidators']['FailOnSeverity'] = value end |
#options ⇒ Array<String>
YARD command-line options
73 74 75 |
# File 'lib/yard/lint/config.rb', line 73 def all_validators['YardOptions'] || [] end |
#options=(value) ⇒ Object
Set YARD options
142 143 144 145 |
# File 'lib/yard/lint/config.rb', line 142 def (value) @raw_config['AllValidators'] ||= {} @raw_config['AllValidators']['YardOptions'] = value end |
#validator_all_excludes(validator_name) ⇒ Array<String>
Combined global and per-validator exclusions Returns all exclusion patterns that apply to this validator
126 127 128 |
# File 'lib/yard/lint/config.rb', line 126 def validator_all_excludes(validator_name) exclude + validator_exclude(validator_name) end |
#validator_config(validator_name, key) ⇒ Object?
Get validator-specific configuration value
134 135 136 |
# File 'lib/yard/lint/config.rb', line 134 def validator_config(validator_name, key) validators.dig(validator_name, key) end |
#validator_enabled?(validator_name) ⇒ Boolean
Check if a validator is enabled
101 102 103 104 |
# File 'lib/yard/lint/config.rb', line 101 def validator_enabled?(validator_name) validator_config = validators[validator_name] || {} validator_config['Enabled'] != false # Default to true end |
#validator_exclude(validator_name) ⇒ Array<String>
Get validator-specific exclude patterns
117 118 119 120 |
# File 'lib/yard/lint/config.rb', line 117 def validator_exclude(validator_name) validator_config = validators[validator_name] || {} validator_config['Exclude'] || [] end |
#validator_severity(validator_name) ⇒ String
Get validator severity
109 110 111 112 |
# File 'lib/yard/lint/config.rb', line 109 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
81 82 83 84 |
# File 'lib/yard/lint/config.rb', line 81 def (validator_name) validator_config = validators[validator_name] || {} validator_config['YardOptions'] || end |