Skip to main content

rigsql_rules/structure/
st11.rs

1use rigsql_core::SegmentType;
2
3use crate::rule::{CrawlType, Rule, RuleContext, RuleGroup};
4use crate::violation::LintViolation;
5
6/// ST11: Unused JOIN (join without reference in SELECT or WHERE).
7///
8/// This is a stub rule. The full implementation would require complex
9/// cross-reference analysis to determine if a joined table is actually
10/// used in the query.
11#[derive(Debug, Default)]
12pub struct RuleST11;
13
14impl Rule for RuleST11 {
15    fn code(&self) -> &'static str {
16        "ST11"
17    }
18    fn name(&self) -> &'static str {
19        "structure.unused_join"
20    }
21    fn description(&self) -> &'static str {
22        "Joined table is not referenced in the query."
23    }
24    fn explanation(&self) -> &'static str {
25        "A table that is joined but never referenced in the SELECT, WHERE, or other \
26         clauses may be unnecessary. Remove unused joins to simplify the query and \
27         improve performance. This rule is currently a stub."
28    }
29    fn groups(&self) -> &[RuleGroup] {
30        &[RuleGroup::Structure]
31    }
32    fn is_fixable(&self) -> bool {
33        false
34    }
35
36    fn crawl_type(&self) -> CrawlType {
37        CrawlType::Segment(vec![SegmentType::SelectStatement])
38    }
39
40    fn eval(&self, _ctx: &RuleContext) -> Vec<LintViolation> {
41        // Stub: not implemented yet
42        vec![]
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49    use crate::test_utils::lint_sql;
50
51    #[test]
52    fn test_st11_no_false_positives() {
53        let violations = lint_sql("SELECT a.id FROM a JOIN b ON a.id = b.id;", RuleST11);
54        assert_eq!(violations.len(), 0);
55    }
56}