Skip to content

Commit dd5c6e6

Browse files
gvozdvmozgubenfdking
authored andcommitted
refactor: simplify lint_string_wrapped API and clean up related tests
1 parent 38ee70a commit dd5c6e6

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ perf = "warn"
1717
cloned_instead_of_copied = "warn"
1818

1919
# https://github.com/rustwasm/wasm-bindgen/issues/3451#issuecomment-1562982835
20-
[profile.dev]
21-
opt-level = "s"
20+
#[profile.dev]
21+
#opt-level = "s"
2222

23-
[profile.release]
24-
lto = true
25-
codegen-units = 1
23+
#[profile.release]
24+
#lto = true
25+
#codegen-units = 1
2626

2727
[workspace.dependencies]
2828
ahash = { version = "0.8.11", features = ["compile-time-rng", "serde"] }

crates/lib/src/core/linter/core.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@ impl Linter {
7575
}
7676

7777
/// Lint strings directly.
78-
pub fn lint_string_wrapped(&mut self, sql: &str, fix: bool) -> LintingResult {
78+
pub fn lint_string_wrapped(&mut self, sql: &str, fix: bool) -> LintedFile {
7979
let filename = "<string input>".to_owned();
80-
81-
let mut result = LintingResult::new();
82-
result.add(self.lint_string(sql, Some(filename), fix));
83-
result
80+
self.lint_string(sql, Some(filename), fix)
8481
}
8582

8683
/// Parse a string.

crates/lib/src/templaters/placeholder.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ Also consider making a pull request to the project to have your style added, it
356356

357357
#[cfg(test)]
358358
mod tests {
359-
use std::mem::take;
360359

361360
use super::*;
362361
use crate::core::linter::core::Linter;
@@ -796,8 +795,7 @@ param_style = percent
796795
let sql = "SELECT a,b FROM users WHERE a = %s";
797796

798797
let mut linter = Linter::new(config, None, None, false);
799-
let mut result = linter.lint_string_wrapped(sql, true);
800-
let result = take(&mut result.files[0]).fix_string();
798+
let result = linter.lint_string_wrapped(sql, true).fix_string();
801799

802800
assert_eq!(result, "SELECT\n a,\n b\nFROM users WHERE a = %s\n");
803801
}

crates/lib/tests/rules.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,14 @@ dialect = {dialect}
214214
pass_str = pass_str
215215
);
216216

217-
assert_eq!(&f.files[0].violations, &[], "{}", error_string);
217+
assert_eq!(&f.violations, &[], "{}", error_string);
218218
}
219219
TestCaseKind::Fail { fail_str } => {
220220
let f = linter.lint_string_wrapped(&fail_str, false);
221-
assert_ne!(&f.files[0].violations, &[])
221+
assert_ne!(&f.violations, &[])
222222
}
223223
TestCaseKind::Fix { fail_str, fix_str } => {
224-
let f =
225-
std::mem::take(&mut linter.lint_string_wrapped(&fail_str, true).files[0])
226-
.fix_string();
224+
let f = linter.lint_string_wrapped(&fail_str, true).fix_string();
227225

228226
pretty_assertions::assert_eq!(f, fix_str);
229227
}

0 commit comments

Comments
 (0)