mirror of
https://github.com/oppiliappan/statix.git
synced 2024-09-11 09:15:45 +03:00
apply clippy lints
This commit is contained in:
parent
90ea9335b5
commit
831bd7e91d
@ -154,7 +154,7 @@ mod dirs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_line_col(src: &str) -> Result<(usize, usize), ConfigErr> {
|
fn parse_line_col(src: &str) -> Result<(usize, usize), ConfigErr> {
|
||||||
let parts = src.split(",");
|
let parts = src.split(',');
|
||||||
match parts.collect::<Vec<_>>().as_slice() {
|
match parts.collect::<Vec<_>>().as_slice() {
|
||||||
[line, col] => {
|
[line, col] => {
|
||||||
let l = line
|
let l = line
|
||||||
@ -173,7 +173,7 @@ fn parse_warning_code(src: &str) -> Result<u32, ConfigErr> {
|
|||||||
let mut char_stream = src.chars();
|
let mut char_stream = src.chars();
|
||||||
let severity = char_stream
|
let severity = char_stream
|
||||||
.next()
|
.next()
|
||||||
.ok_or(ConfigErr::InvalidWarningCode(src.to_owned()))?
|
.ok_or_else(|| ConfigErr::InvalidWarningCode(src.to_owned()))?
|
||||||
.to_ascii_lowercase();
|
.to_ascii_lowercase();
|
||||||
match severity {
|
match severity {
|
||||||
'w' => char_stream
|
'w' => char_stream
|
||||||
@ -187,7 +187,7 @@ fn parse_warning_code(src: &str) -> Result<u32, ConfigErr> {
|
|||||||
fn build_ignore_set(ignores: &[String]) -> Result<GlobSet, GlobError> {
|
fn build_ignore_set(ignores: &[String]) -> Result<GlobSet, GlobError> {
|
||||||
let mut set = GlobSetBuilder::new();
|
let mut set = GlobSetBuilder::new();
|
||||||
for pattern in ignores {
|
for pattern in ignores {
|
||||||
let glob = GlobBuilder::new(&pattern).build()?;
|
let glob = GlobBuilder::new(pattern).build()?;
|
||||||
set.add(glob);
|
set.add(glob);
|
||||||
}
|
}
|
||||||
set.build()
|
set.build()
|
||||||
|
@ -40,8 +40,7 @@ fn find(offset: TextSize, src: &str) -> Result<Report, SingleFixErr> {
|
|||||||
rules
|
rules
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|rule| rule.validate(&child))
|
.filter_map(|rule| rule.validate(&child))
|
||||||
.filter(|report| report.total_suggestion_range().is_some())
|
.find(|report| report.total_suggestion_range().is_some())
|
||||||
.next()
|
|
||||||
}),
|
}),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
|
@ -16,7 +16,7 @@ pub fn lint(vfs_entry: VfsEntry) -> LintResult {
|
|||||||
let error_reports = parsed
|
let error_reports = parsed
|
||||||
.errors()
|
.errors()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|e| Report::from_parse_err(e));
|
.map(Report::from_parse_err);
|
||||||
|
|
||||||
let reports = parsed
|
let reports = parsed
|
||||||
.node()
|
.node()
|
||||||
|
@ -71,7 +71,7 @@ fn _main() -> Result<(), StatixErr> {
|
|||||||
let single_fix_result = fix::single(line, col, &src)?;
|
let single_fix_result = fix::single(line, col, &src)?;
|
||||||
if single_config.diff_only {
|
if single_config.diff_only {
|
||||||
let text_diff = TextDiff::from_lines(src.as_str(), &single_fix_result.src);
|
let text_diff = TextDiff::from_lines(src.as_str(), &single_fix_result.src);
|
||||||
let old_file = format!("{}", path_id);
|
let old_file = path_id.to_string();
|
||||||
let new_file = format!("{} [fixed]", path_id);
|
let new_file = format!("{} [fixed]", path_id);
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
@ -96,8 +96,7 @@ fn _main() -> Result<(), StatixErr> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match _main() {
|
if let Err(e) = _main() {
|
||||||
Err(e) => eprintln!("{}", e),
|
eprintln!("{}", e);
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,8 @@ fn write_errfmt<T: Write>(
|
|||||||
let path = vfs.file_path(file_id);
|
let path = vfs.file_path(file_id);
|
||||||
for report in lint_result.reports.iter() {
|
for report in lint_result.reports.iter() {
|
||||||
for diagnostic in report.diagnostics.iter() {
|
for diagnostic in report.diagnostics.iter() {
|
||||||
let line = line(diagnostic.at.start(), &src);
|
let line = line(diagnostic.at.start(), src);
|
||||||
let col = column(diagnostic.at.start(), &src);
|
let col = column(diagnostic.at.start(), src);
|
||||||
writeln!(
|
writeln!(
|
||||||
writer,
|
writer,
|
||||||
"{filename}>{linenumber}:{columnnumber}:{errortype}:{errornumber}:{errormessage}",
|
"{filename}>{linenumber}:{columnnumber}:{errortype}:{errornumber}:{errormessage}",
|
||||||
@ -131,7 +131,6 @@ mod json {
|
|||||||
use lib::Severity;
|
use lib::Severity;
|
||||||
use rnix::TextRange;
|
use rnix::TextRange;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json;
|
|
||||||
use vfs::ReadOnlyVfs;
|
use vfs::ReadOnlyVfs;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
@ -67,7 +67,7 @@ impl Rule for EtaReduction {
|
|||||||
let message =
|
let message =
|
||||||
format!(
|
format!(
|
||||||
"Found eta-reduction: `{}`",
|
"Found eta-reduction: `{}`",
|
||||||
replacement.text().to_string()
|
replacement.text()
|
||||||
);
|
);
|
||||||
Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
|
Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
|
||||||
} else {
|
} else {
|
||||||
@ -81,6 +81,6 @@ fn mentions_ident(ident: &Ident, node: &SyntaxNode) -> bool {
|
|||||||
if let Some(node_ident) = Ident::cast(node.clone()) {
|
if let Some(node_ident) = Ident::cast(node.clone()) {
|
||||||
node_ident.as_str() == ident.as_str()
|
node_ident.as_str() == ident.as_str()
|
||||||
} else {
|
} else {
|
||||||
node.children().any(|child| mentions_ident(&ident, &child))
|
node.children().any(|child| mentions_ident(ident, &child))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ impl Rule for UnquotedSplice {
|
|||||||
if Dynamic::cast(node.clone()).is_some();
|
if Dynamic::cast(node.clone()).is_some();
|
||||||
then {
|
then {
|
||||||
let at = node.text_range();
|
let at = node.text_range();
|
||||||
let replacement = make::quote(&node).node().clone();
|
let replacement = make::quote(node).node().clone();
|
||||||
let message = "Consider quoting this splice expression";
|
let message = "Consider quoting this splice expression";
|
||||||
Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
|
Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -156,7 +156,7 @@ impl<'μ> LintMeta<'μ> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_meta_impl(struct_name: &Ident, meta: &RawLintMeta) -> TokenStream2 {
|
pub fn generate_meta_impl(struct_name: &Ident, meta: &RawLintMeta) -> TokenStream2 {
|
||||||
let not_raw = LintMeta::from_raw(&meta);
|
let not_raw = LintMeta::from_raw(meta);
|
||||||
let name_fn = not_raw.generate_name_fn();
|
let name_fn = not_raw.generate_name_fn();
|
||||||
let note_fn = not_raw.generate_note_fn();
|
let note_fn = not_raw.generate_note_fn();
|
||||||
let code_fn = not_raw.generate_code_fn();
|
let code_fn = not_raw.generate_code_fn();
|
||||||
|
Loading…
Reference in New Issue
Block a user