Class: Ukiryu::Definition::DefinitionLinter
- Inherits:
-
Object
- Object
- Ukiryu::Definition::DefinitionLinter
- Defined in:
- lib/ukiryu/definition/definition_linter.rb
Overview
Lint tool definitions for best practices
This class checks tool definitions for best practices, deprecated patterns, naming conventions, and security issues.
Defined Under Namespace
Classes: LintResult, Rules
Class Method Summary collapse
-
.lint(definition, rules: nil) ⇒ LintResult
Lint a definition.
-
.lint_file(file_path, rules: nil) ⇒ LintResult
Lint a definition file.
-
.lint_string(yaml_string, rules: nil) ⇒ LintResult
Lint a YAML string.
Class Method Details
.lint(definition, rules: nil) ⇒ LintResult
Lint a definition
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/ukiryu/definition/definition_linter.rb', line 192 def lint(definition, rules: nil) issues = [] # Check if definition is a hash return LintResult.new([LintIssue.error('Definition must be a hash/object')]) unless definition.is_a?(Hash) # Run all lint checks issues.concat(check_naming_conventions(definition)) issues.concat(check_completeness(definition)) issues.concat(check_security(definition)) issues.concat(check_deprecated_patterns(definition)) issues.concat(check_best_practices(definition)) # Filter by rules if provided if rules enabled_rules = rules[:enabled] || [] disabled_rules = rules[:disabled] || [] issues = issues.select do |issue| if disabled_rules.any? !disabled_rules.include?(issue.rule_id) elsif enabled_rules.any? enabled_rules.include?(issue.rule_id) else true end end end LintResult.new(issues) end |
.lint_file(file_path, rules: nil) ⇒ LintResult
Lint a definition file
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/ukiryu/definition/definition_linter.rb', line 229 def lint_file(file_path, rules: nil) # Load raw YAML hash for linting require 'yaml' definition = YAML.safe_load(File.read(file_path), permitted_classes: [Symbol, Date, Time], symbolize_names: true) lint(definition, rules: rules) rescue Ukiryu::Errors::DefinitionNotFoundError LintResult.new([LintIssue.error("File not found: #{file_path}")]) rescue Ukiryu::Errors::DefinitionLoadError, Ukiryu::Errors::DefinitionValidationError => e LintResult.new([LintIssue.error(e.)]) rescue Errno::ENOENT LintResult.new([LintIssue.error("File not found: #{file_path}")]) rescue Psych::SyntaxError => e LintResult.new([LintIssue.error("Invalid YAML: #{e.}")]) end |
.lint_string(yaml_string, rules: nil) ⇒ LintResult
Lint a YAML string
250 251 252 253 254 255 256 |
# File 'lib/ukiryu/definition/definition_linter.rb', line 250 def lint_string(yaml_string, rules: nil) require 'yaml' definition = YAML.safe_load(yaml_string, permitted_classes: [Symbol, Date, Time]) lint(definition, rules: rules) rescue Psych::SyntaxError => e LintResult.new([LintIssue.error("Invalid YAML: #{e.}")]) end |