sqruff_lib/rules/layout/
lt02.rs1use ahash::AHashMap;
2
3use crate::core::config::Value;
4use crate::core::rules::base::{Erased, ErasedRule, LintResult, Rule, RuleGroups};
5use crate::core::rules::context::RuleContext;
6use crate::core::rules::crawlers::{Crawler, RootOnlyCrawler};
7use crate::utils::reflow::sequence::ReflowSequence;
8
9#[derive(Default, Debug, Clone)]
10pub struct RuleLT02;
11
12impl Rule for RuleLT02 {
13 fn load_from_config(&self, _config: &AHashMap<String, Value>) -> Result<ErasedRule, String> {
14 Ok(RuleLT02.erased())
15 }
16 fn name(&self) -> &'static str {
17 "layout.indent"
18 }
19
20 fn description(&self) -> &'static str {
21 "Incorrect Indentation."
22 }
23
24 fn long_description(&self) -> &'static str {
25 r#"
26**Anti-pattern**
27
28The ``•`` character represents a space and the ``→`` character represents a tab.
29In this example, the third line contains five spaces instead of four and
30the second line contains two spaces and one tab.
31
32```sql
33SELECT
34••→a,
35•••••b
36FROM foo
37```
38
39**Best practice**
40
41Change the indentation to use a multiple of four spaces. This example also assumes that the indent_unit config value is set to space. If it had instead been set to tab, then the indents would be tabs instead.
42
43```sql
44SELECT
45••••a,
46••••b
47FROM foo
48```
49"#
50 }
51
52 fn groups(&self) -> &'static [RuleGroups] {
53 &[RuleGroups::All, RuleGroups::Core, RuleGroups::Layout]
54 }
55
56 fn eval(&self, context: &RuleContext) -> Vec<LintResult> {
57 ReflowSequence::from_root(context.segment.clone(), context.config)
58 .reindent(context.tables)
59 .results()
60 }
61
62 fn is_fix_compatible(&self) -> bool {
63 true
64 }
65
66 fn crawl_behaviour(&self) -> Crawler {
67 RootOnlyCrawler.into()
68 }
69}