Skip to content

Commit

Permalink
refactor: remove unused encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
gvozdvmozgu authored and benfdking committed Sep 16, 2024
1 parent 6afed05 commit 26bd43f
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 31 deletions.
4 changes: 2 additions & 2 deletions crates/lib-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Linter {
let line_index = LineIndex::new(sql);

let rule_pack = self.base.get_rulepack().rules();
let result = self.base.lint_string(sql, None, None, None, rule_pack, false);
let result = self.base.lint_string(sql, None, None, rule_pack, false);
let violations = result.violations;

violations
Expand All @@ -60,7 +60,7 @@ impl Linter {
#[wasm_bindgen]
pub fn format(&self, sql: &str) -> String {
let rule_pack = self.base.get_rulepack().rules();
let tree = self.base.lint_string(sql, None, None, None, rule_pack, true);
let tree = self.base.lint_string(sql, None, None, rule_pack, true);
tree.fix_string()
}
}
2 changes: 1 addition & 1 deletion crates/lib/benches/depth_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ SELECT construct_depth_info('uuid-3');"#;
fn depth_map(c: &mut Criterion) {
let linter = Linter::new(FluffConfig::default(), None, None);
let tables = Tables::default();
let tree = linter.parse_string(&tables, COMPLEX_QUERY, None, None, None).unwrap().tree.unwrap();
let tree = linter.parse_string(&tables, COMPLEX_QUERY, None, None).unwrap().tree.unwrap();

c.bench_function("DepthMap::from_parent", |b| {
b.iter(|| black_box(DepthMap::from_parent(&tree)));
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/benches/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn fix(c: &mut Criterion) {
let linter = Linter::new(sqruff_lib::core::config::FluffConfig::default(), None, None);
for (name, source) in passes {
let tables = Tables::default();
let parsed = linter.parse_string(&tables, source, None, None, None).unwrap();
let parsed = linter.parse_string(&tables, source, None, None).unwrap();

c.bench_function(name, |b| {
b.iter(|| {
Expand Down
6 changes: 3 additions & 3 deletions crates/lib/src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ mod tests {
for (raw, err_locations) in tests {
let lnt = Linter::new(FluffConfig::new(<_>::default(), None, None), None, None);
let tables = Tables::default();
let parsed = lnt.parse_string(&tables, raw, None, None, None).unwrap();
let parsed = lnt.parse_string(&tables, raw, None, None).unwrap();
assert!(!parsed.violations.is_empty());

let locs: Vec<(usize, usize)> =
Expand All @@ -191,7 +191,7 @@ mod tests {
.expect("Unable to read file");

let tables = Tables::default();
let parsed = lnt.parse_string(&tables, &file_content, None, None, None).unwrap();
let parsed = lnt.parse_string(&tables, &file_content, None, None).unwrap();

for raw_seg in parsed.tree.unwrap().get_raw_segments() {
if raw_seg.is_type(SyntaxKind::Whitespace) || raw_seg.is_type(SyntaxKind::Newline) {
Expand All @@ -213,7 +213,7 @@ mod tests {

for (sql_string, meta_loc) in cases {
let tables = Tables::default();
let parsed = lnt.parse_string(&tables, sql_string, None, None, None).unwrap();
let parsed = lnt.parse_string(&tables, sql_string, None, None).unwrap();
let tree = parsed.tree.unwrap();

let res_meta_locs = tree
Expand Down
1 change: 0 additions & 1 deletion crates/lib/src/core/linter/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub struct RenderedFile {
pub templated_file: TemplatedFile,
pub templater_violations: Vec<SQLTemplaterError>,
pub(crate) f_name: String,
pub encoding: String,
pub source_str: String,
}

Expand Down
26 changes: 7 additions & 19 deletions crates/lib/src/core/linter/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,7 @@ impl Linter {
let f_name = f_name.unwrap_or_else(|| "<string input>".into());

let mut linted_path = LintedDir::new(f_name.clone());
linted_path.add(self.lint_string(
sql,
Some(f_name),
None,
None,
rules,
fix.unwrap_or_default(),
));
linted_path.add(self.lint_string(sql, Some(f_name), None, rules, fix.unwrap_or_default()));

let mut result = LintingResult::new();
result.add(linted_path);
Expand All @@ -94,18 +87,17 @@ impl Linter {
tables: &Tables,
in_str: &str,
f_name: Option<String>,
encoding: Option<String>,

parse_statistics: Option<bool>,
) -> Result<ParsedString, SQLFluffUserError> {
let f_name = f_name.unwrap_or_else(|| "<string>".to_string());
let encoding = encoding.unwrap_or_else(|| "utf-8".to_string());
let parse_statistics = parse_statistics.unwrap_or(false);

let mut violations: Vec<Box<dyn SqlError>> = vec![];

// Scan the raw file for config commands.
self.config.process_raw_file_for_config(in_str);
let rendered = self.render_string(in_str, f_name, &self.config, Some(encoding))?;
let rendered = self.render_string(in_str, f_name, &self.config)?;

for violation in &rendered.templater_violations {
violations.push(Box::new(violation.clone()));
Expand All @@ -126,15 +118,14 @@ impl Linter {
in_str: &str,
f_name: Option<String>,
config: Option<&FluffConfig>,
_encoding: Option<String>,
rules: Vec<ErasedRule>,
fix: bool,
) -> LintedFile {
// Sort out config, defaulting to the built in config if no override
let _defaulted_config = config.unwrap_or(&self.config);
// Parse the string.
let tables = Tables::default();
let parsed = self.parse_string(&tables, in_str, f_name, None, None).unwrap();
let parsed = self.parse_string(&tables, in_str, f_name, None).unwrap();

// Lint the file and return the LintedFile
self.lint_parsed(&tables, parsed, rules, fix)
Expand Down Expand Up @@ -185,7 +176,7 @@ impl Linter {

pub fn render_file(&self, fname: String) -> RenderedFile {
let in_str = std::fs::read_to_string(&fname).unwrap();
self.render_string(&in_str, fname, &self.config, None).unwrap()
self.render_string(&in_str, fname, &self.config).unwrap()
}

pub fn lint_rendered(
Expand Down Expand Up @@ -346,7 +337,6 @@ impl Linter {
in_str: &str,
f_name: String,
config: &FluffConfig,
encoding: Option<String>,
) -> Result<RenderedFile, SQLFluffUserError> {
let in_str = Self::normalise_newlines(in_str);

Expand All @@ -372,9 +362,7 @@ impl Linter {
Ok(RenderedFile {
templated_file,
templater_violations,

f_name: f_name.to_owned(),
encoding: encoding.to_owned().unwrap_or_else(|| "UTF-8".into()),
source_str: f_name.to_owned(),
})
}
Expand Down Expand Up @@ -708,7 +696,7 @@ mod tests {
fn test_linter_empty_file() {
let linter = Linter::new(FluffConfig::new(<_>::default(), None, None), None, None);
let tables = Tables::default();
let parsed = linter.parse_string(&tables, "", None, None, None).unwrap();
let parsed = linter.parse_string(&tables, "", None, None).unwrap();

assert!(parsed.violations.is_empty());
}
Expand All @@ -735,7 +723,7 @@ mod tests {

let linter = Linter::new(FluffConfig::new(<_>::default(), None, None), None, None);
let tables = Tables::default();
let _parsed = linter.parse_string(&tables, &sql, None, None, None).unwrap();
let _parsed = linter.parse_string(&tables, &sql, None, None).unwrap();
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/core/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ mod tests {
let config = FluffConfig::new(<_>::default(), None, None);
let linter = Linter::new(config, None, None);
let tables = Tables::default();
let _ = linter.parse_string(&tables, &in_str, None, None, None);
let _ = linter.parse_string(&tables, &in_str, None, None);
}
}
2 changes: 1 addition & 1 deletion crates/lib/src/core/test_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::core::linter::core::Linter;
pub fn parse_ansi_string(sql: &str) -> ErasedSegment {
let tables = Tables::default();
let linter = Linter::new(<_>::default(), None, None);
linter.parse_string(&tables, sql, None, None, None).unwrap().tree.unwrap()
linter.parse_string(&tables, sql, None, None).unwrap().tree.unwrap()
}

pub fn fresh_ansi_dialect() -> Dialect {
Expand Down
4 changes: 2 additions & 2 deletions crates/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl LanguageServer {
fn format(&mut self, uri: Uri) -> Vec<lsp_types::TextEdit> {
let rule_pack = self.linter.get_rulepack().rules();
let text = &self.documents[&uri];
let tree = self.linter.lint_string(text, None, None, None, rule_pack, true);
let tree = self.linter.lint_string(text, None, None, rule_pack, true);

let new_text = tree.fix_string();
let start_position = Position { line: 0, character: 0 };
Expand Down Expand Up @@ -177,7 +177,7 @@ impl LanguageServer {

fn check_file(&self, uri: Uri, text: &str) {
let rule_pack = self.linter.get_rulepack().rules();
let result = self.linter.lint_string(text, None, None, None, rule_pack, false);
let result = self.linter.lint_string(text, None, None, rule_pack, false);

let diagnostics = result
.violations
Expand Down

0 comments on commit 26bd43f

Please sign in to comment.