Skip to content

Commit e81cf1c

Browse files
committed
Move setup of parsed indentation to its own function
1 parent fd0613b commit e81cf1c

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/lint/mod.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use crate::file_management::CanonPath;
1515
use crate::vfs::{Error, TextFile};
1616
use crate::analysis::parsing::structure::TopAst;
1717
use crate::lint::rules::indentation::{MAX_LENGTH_DEFAULT,
18-
INDENTATION_LEVEL_DEFAULT};
18+
INDENTATION_LEVEL_DEFAULT,
19+
setup_indentation_size
20+
};
1921

2022
pub fn parse_lint_cfg(path: PathBuf) -> Result<LintCfg, String> {
2123
debug!("Reading Lint configuration from {:?}", path);
@@ -29,20 +31,7 @@ pub fn parse_lint_cfg(path: PathBuf) -> Result<LintCfg, String> {
2931
pub fn maybe_parse_lint_cfg(path: PathBuf) -> Option<LintCfg> {
3032
match parse_lint_cfg(path) {
3133
Ok(mut cfg) => {
32-
let mut indentation_spaces = INDENTATION_LEVEL_DEFAULT;
33-
34-
if let Some(in1) = &cfg.in1 {
35-
indentation_spaces = in1.indentation_spaces;
36-
}
37-
if let Some(in3) = &mut cfg.in3 {
38-
in3.indentation_spaces = indentation_spaces;
39-
}
40-
if let Some(in6) = &mut cfg.in6 {
41-
in6.indentation_spaces = indentation_spaces;
42-
}
43-
if let Some(in9) = &mut cfg.in9 {
44-
in9.indentation_spaces = indentation_spaces;
45-
}
34+
setup_indentation_size(&mut cfg);
4635
Some(cfg)
4736
},
4837
Err(e) => {

src/lint/rules/indentation.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::analysis::LocalDMLError;
88
use crate::analysis::parsing::tree::{ZeroRange, Content, TreeElement};
99
use serde::{Deserialize, Serialize};
1010
use super::Rule;
11+
use crate::lint::LintCfg;
1112

1213
pub const MAX_LENGTH_DEFAULT: u32 = 80;
1314
pub const INDENTATION_LEVEL_DEFAULT: u32 = 4;
@@ -16,6 +17,22 @@ fn default_indentation_spaces() -> u32 {
1617
INDENTATION_LEVEL_DEFAULT
1718
}
1819

20+
pub fn setup_indentation_size(cfg: &mut LintCfg) {
21+
let mut indentation_spaces = INDENTATION_LEVEL_DEFAULT;
22+
23+
if let Some(in1) = &cfg.in1 {
24+
indentation_spaces = in1.indentation_spaces;
25+
}
26+
if let Some(in3) = &mut cfg.in3 {
27+
in3.indentation_spaces = indentation_spaces;
28+
}
29+
if let Some(in6) = &mut cfg.in6 {
30+
in6.indentation_spaces = indentation_spaces;
31+
}
32+
if let Some(in9) = &mut cfg.in9 {
33+
in9.indentation_spaces = indentation_spaces;
34+
}
35+
}
1936
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
2037
pub struct LongLineOptions {
2138
pub max_length: u32,

0 commit comments

Comments
 (0)