Class: Ukiryu::Definition::LintIssue
- Inherits:
-
Object
- Object
- Ukiryu::Definition::LintIssue
- Defined in:
- lib/ukiryu/definition/lint_issue.rb
Overview
A linting issue found in a definition
This class represents a single linting issue with severity, message, location, and optional suggestion.
Constant Summary collapse
- SEVERITY_ERROR =
Severity levels
:error- SEVERITY_WARNING =
:warning- SEVERITY_INFO =
:info- SEVERITY_STYLE =
:style
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#rule_id ⇒ Object
readonly
Returns the value of attribute rule_id.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#suggestion ⇒ Object
readonly
Returns the value of attribute suggestion.
Class Method Summary collapse
-
.error(message, location: nil, suggestion: nil, rule_id: nil) ⇒ LintIssue
Create an error issue.
-
.info(message, location: nil, suggestion: nil, rule_id: nil) ⇒ LintIssue
Create an info issue.
-
.style(message, location: nil, suggestion: nil, rule_id: nil) ⇒ LintIssue
Create a style issue.
-
.warning(message, location: nil, suggestion: nil, rule_id: nil) ⇒ LintIssue
Create a warning issue.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Check if this is an error.
-
#has_location? ⇒ Boolean
Check if this issue has a location.
-
#has_suggestion? ⇒ Boolean
Check if this issue has a suggestion.
-
#info? ⇒ Boolean
Check if this is info.
-
#initialize(severity:, message:, location: nil, suggestion: nil, rule_id: nil) ⇒ LintIssue
constructor
A new instance of LintIssue.
-
#severity_string ⇒ String
Get severity as a readable string.
-
#style? ⇒ Boolean
Check if this is style.
-
#to_h ⇒ Hash
Convert to hash.
-
#to_s ⇒ String
Format as string.
-
#warning? ⇒ Boolean
Check if this is a warning.
Constructor Details
#initialize(severity:, message:, location: nil, suggestion: nil, rule_id: nil) ⇒ LintIssue
Returns a new instance of LintIssue.
18 19 20 21 22 23 24 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 18 def initialize(severity:, message:, location: nil, suggestion: nil, rule_id: nil) @severity = severity @message = @location = location @suggestion = suggestion @rule_id = rule_id end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
16 17 18 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 16 def location @location end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
16 17 18 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 16 def @message end |
#rule_id ⇒ Object (readonly)
Returns the value of attribute rule_id.
16 17 18 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 16 def rule_id @rule_id end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
16 17 18 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 16 def severity @severity end |
#suggestion ⇒ Object (readonly)
Returns the value of attribute suggestion.
16 17 18 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 16 def suggestion @suggestion end |
Class Method Details
.error(message, location: nil, suggestion: nil, rule_id: nil) ⇒ LintIssue
Create an error issue
106 107 108 109 110 111 112 113 114 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 106 def self.error(, location: nil, suggestion: nil, rule_id: nil) new( severity: SEVERITY_ERROR, message: , location: location, suggestion: suggestion, rule_id: rule_id ) end |
.info(message, location: nil, suggestion: nil, rule_id: nil) ⇒ LintIssue
Create an info issue
140 141 142 143 144 145 146 147 148 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 140 def self.info(, location: nil, suggestion: nil, rule_id: nil) new( severity: SEVERITY_INFO, message: , location: location, suggestion: suggestion, rule_id: rule_id ) end |
.style(message, location: nil, suggestion: nil, rule_id: nil) ⇒ LintIssue
Create a style issue
157 158 159 160 161 162 163 164 165 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 157 def self.style(, location: nil, suggestion: nil, rule_id: nil) new( severity: SEVERITY_STYLE, message: , location: location, suggestion: suggestion, rule_id: rule_id ) end |
.warning(message, location: nil, suggestion: nil, rule_id: nil) ⇒ LintIssue
Create a warning issue
123 124 125 126 127 128 129 130 131 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 123 def self.warning(, location: nil, suggestion: nil, rule_id: nil) new( severity: SEVERITY_WARNING, message: , location: location, suggestion: suggestion, rule_id: rule_id ) end |
Instance Method Details
#error? ⇒ Boolean
Check if this is an error
29 30 31 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 29 def error? @severity == SEVERITY_ERROR end |
#has_location? ⇒ Boolean
Check if this issue has a location
64 65 66 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 64 def has_location? !@location.nil? && !@location.empty? end |
#has_suggestion? ⇒ Boolean
Check if this issue has a suggestion
57 58 59 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 57 def has_suggestion? !@suggestion.nil? && !@suggestion.empty? end |
#info? ⇒ Boolean
Check if this is info
43 44 45 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 43 def info? @severity == SEVERITY_INFO end |
#severity_string ⇒ String
Get severity as a readable string
71 72 73 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 71 def severity_string @severity.to_s.upcase end |
#style? ⇒ Boolean
Check if this is style
50 51 52 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 50 def style? @severity == SEVERITY_STYLE end |
#to_h ⇒ Hash
Convert to hash
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 78 def to_h { severity: @severity, severity_string: severity_string, message: @message, location: @location, suggestion: @suggestion, rule_id: @rule_id } end |
#to_s ⇒ String
Format as string
92 93 94 95 96 97 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 92 def to_s output = "[#{severity_string}] #{@message}" output += " (at #{@location})" if has_location? output += "\n Suggestion: #{@suggestion}" if has_suggestion? output end |
#warning? ⇒ Boolean
Check if this is a warning
36 37 38 |
# File 'lib/ukiryu/definition/lint_issue.rb', line 36 def warning? @severity == SEVERITY_WARNING end |