use super::{IssueCategory, IssueSeverity};
use alloc::string::String;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IssueLocation {
pub line: usize,
pub column: usize,
pub offset: usize,
pub length: usize,
pub span: String,
}
#[derive(Debug, Clone)]
pub struct LintIssue {
severity: IssueSeverity,
category: IssueCategory,
message: String,
description: Option<String>,
location: Option<IssueLocation>,
rule_id: &'static str,
suggested_fix: Option<String>,
}
impl LintIssue {
#[must_use]
pub const fn new(
severity: IssueSeverity,
category: IssueCategory,
rule_id: &'static str,
message: String,
) -> Self {
Self {
severity,
category,
message,
description: None,
location: None,
rule_id,
suggested_fix: None,
}
}
#[must_use]
pub fn with_description(mut self, description: String) -> Self {
self.description = Some(description);
self
}
#[must_use]
pub fn with_location(mut self, location: IssueLocation) -> Self {
self.location = Some(location);
self
}
#[must_use]
pub fn with_suggested_fix(mut self, fix: String) -> Self {
self.suggested_fix = Some(fix);
self
}
#[must_use]
pub const fn severity(&self) -> IssueSeverity {
self.severity
}
#[must_use]
pub const fn category(&self) -> IssueCategory {
self.category
}
#[must_use]
pub fn message(&self) -> &str {
&self.message
}
#[must_use]
pub fn description(&self) -> Option<&str> {
self.description.as_deref()
}
#[must_use]
pub const fn location(&self) -> Option<&IssueLocation> {
self.location.as_ref()
}
#[must_use]
pub const fn rule_id(&self) -> &'static str {
self.rule_id
}
#[must_use]
pub fn suggested_fix(&self) -> Option<&str> {
self.suggested_fix.as_deref()
}
}