Skip to main content

rigsql_rules/structure/
st09.rs

1use rigsql_core::SegmentType;
2
3use crate::rule::{CrawlType, Rule, RuleContext, RuleGroup};
4use crate::violation::LintViolation;
5
6/// ST09: Join condition order convention.
7///
8/// This is a stub rule. The full implementation would check that in an ON
9/// clause, the column from the most recently JOINed table appears on the
10/// left side of the comparison. This is complex to detect reliably.
11#[derive(Debug, Default)]
12pub struct RuleST09;
13
14impl Rule for RuleST09 {
15    fn code(&self) -> &'static str {
16        "ST09"
17    }
18    fn name(&self) -> &'static str {
19        "structure.join_condition_order"
20    }
21    fn description(&self) -> &'static str {
22        "Join condition column order convention."
23    }
24    fn explanation(&self) -> &'static str {
25        "In a JOIN ... ON clause, the column from the table being joined should appear \
26         on the left side of the comparison for consistency and readability. \
27         This rule is currently a stub and does not produce violations."
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::OnClause])
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_st09_no_false_positives() {
53        let violations = lint_sql("SELECT * FROM a JOIN b ON a.id = b.id;", RuleST09);
54        assert_eq!(violations.len(), 0);
55    }
56}