use tree_sitter::Node;
use crate::cop::style::heuristics::matches_redundant_interpolation;
use crate::cop::{Cop, CopConfig};
use crate::diagnostic::Diagnostic;
use crate::parse::source::SourceFile;
pub struct RedundantInterpolation;
impl Cop for RedundantInterpolation {
fn name(&self) -> &'static str {
"Style/RedundantInterpolation"
}
fn interested_node_kinds(&self) -> &'static [&'static str] {
&["interpolation"]
}
fn check_node(
&self,
source: &SourceFile,
node: Node<'_>,
config: &CopConfig,
diagnostics: &mut Vec<Diagnostic>,
_corrections: Option<&mut Vec<crate::correction::Correction>>,
) {
if !matches_redundant_interpolation(source, node, config) {
return;
}
let (line, col) = source.offset_to_line_col(node.start_byte());
diagnostics.push(self.diagnostic(
source,
line,
col,
"Style/RedundantInterpolation offense.".to_string(),
));
}
}
#[cfg(test)]
mod tests {
use super::*;
crate::cop_fixture_tests!(RedundantInterpolation, "cops/style/redundant_interpolation");
}