rigsql_rules/tsql/
tq01.rs1use crate::rule::{CrawlType, Rule, RuleContext, RuleGroup};
2use crate::violation::LintViolation;
3
4#[derive(Debug, Default)]
14pub struct RuleTQ01;
15
16impl Rule for RuleTQ01 {
17 fn code(&self) -> &'static str {
18 "TQ01"
19 }
20 fn name(&self) -> &'static str {
21 "tsql.sp_prefix"
22 }
23 fn description(&self) -> &'static str {
24 "Avoid using the sp_ prefix for stored procedures."
25 }
26 fn explanation(&self) -> &'static str {
27 "Stored procedures with the sp_ prefix cause SQL Server to search the master database \
28 first before checking the current database. This lookup adds unnecessary overhead and \
29 can lead to unexpected behavior if a system procedure with the same name exists. \
30 Use a different prefix such as usp_ for user-defined stored procedures."
31 }
32 fn groups(&self) -> &[RuleGroup] {
33 &[RuleGroup::Convention]
34 }
35 fn is_fixable(&self) -> bool {
36 false
37 }
38
39 fn crawl_type(&self) -> CrawlType {
40 CrawlType::RootOnly
42 }
43
44 fn eval(&self, _ctx: &RuleContext) -> Vec<LintViolation> {
45 vec![]
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53 use crate::test_utils::lint_sql_with_dialect;
54
55 #[test]
56 fn test_tq01_stub_no_violations() {
57 let violations = lint_sql_with_dialect("EXEC sp_helpdb", RuleTQ01, "tsql");
59 assert_eq!(violations.len(), 0);
60 }
61
62 #[test]
63 fn test_tq01_stub_no_violations_ansi() {
64 let violations = lint_sql_with_dialect("EXEC sp_helpdb", RuleTQ01, "ansi");
65 assert_eq!(violations.len(), 0);
66 }
67}