chore: misc clippy lints

This commit is contained in:
Will Lillis 2024-10-06 17:55:00 -04:00 committed by GitHub
parent 50bea73ce3
commit 5c6445edea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 74 additions and 72 deletions

View file

@ -94,6 +94,7 @@ const TEST_BINDING_PY_TEMPLATE: &str = include_str!("./templates/test_binding.py
const PACKAGE_SWIFT_TEMPLATE: &str = include_str!("./templates/package.swift");
const TESTS_SWIFT_TEMPLATE: &str = include_str!("./templates/tests.swift");
#[must_use]
pub fn path_in_ignore(repo_path: &Path) -> bool {
[
"bindings",
@ -130,6 +131,7 @@ pub struct JsonConfigOpts {
}
impl JsonConfigOpts {
#[must_use]
pub fn to_tree_sitter_json(self) -> TreeSitterJSON {
TreeSitterJSON {
grammars: vec![Grammar {
@ -255,8 +257,7 @@ pub fn migrate_package_json(repo_path: &Path) -> Result<bool> {
authors: {
let authors = old_config
.author
.map(|a| vec![a].into_iter())
.unwrap_or_else(|| vec![].into_iter())
.map_or_else(|| vec![].into_iter(), |a| vec![a].into_iter())
.chain(old_config.maintainers.unwrap_or_default())
.filter_map(|a| match a {
PackageJSONAuthor::String(s) => {
@ -362,7 +363,7 @@ pub fn generate_grammar_files(
repo_path: &Path,
language_name: &str,
_allow_update: bool,
opts: Option<JsonConfigOpts>,
opts: Option<&JsonConfigOpts>,
) -> Result<()> {
let dashed_language_name = language_name.to_kebab_case();
@ -371,17 +372,15 @@ pub fn generate_grammar_files(
true,
|path| {
// invariant: opts is always Some when `tree-sitter.json` doesn't exist
let Some(opts) = opts.clone() else {
unreachable!()
};
let Some(opts) = opts else { unreachable!() };
let tree_sitter_json = opts.to_tree_sitter_json();
let tree_sitter_json = opts.clone().to_tree_sitter_json();
write_file(path, serde_json::to_string_pretty(&tree_sitter_json)?)
},
|path| {
// updating the config, if needed
if let Some(opts) = opts.clone() {
let tree_sitter_json = opts.to_tree_sitter_json();
if let Some(opts) = opts {
let tree_sitter_json = opts.clone().to_tree_sitter_json();
write_file(path, serde_json::to_string_pretty(&tree_sitter_json)?)?;
}
Ok(())
@ -674,7 +673,7 @@ pub fn get_root_path(path: &Path) -> Result<PathBuf> {
}
})
.transpose()?;
if let Some(true) = json {
if json == Some(true) {
return Ok(pathbuf.parent().unwrap().to_path_buf());
}
pathbuf.pop(); // filename
@ -838,7 +837,7 @@ fn generate_file(
match generate_opts.description {
Some(description) => {
replacement = replacement.replace(PARSER_DESCRIPTION_PLACEHOLDER, description)
replacement = replacement.replace(PARSER_DESCRIPTION_PLACEHOLDER, description);
}
_ => {
replacement = replacement.replace(
@ -847,7 +846,7 @@ fn generate_file(
"{} grammar for tree-sitter",
language_name.to_upper_camel_case()
),
)
);
}
}
@ -858,7 +857,7 @@ fn generate_file(
PARSER_URL_STRIPPED_PLACEHOLDER,
&repository.replace("https://", "").to_lowercase(),
)
.replace(PARSER_URL_PLACEHOLDER, &repository.to_lowercase())
.replace(PARSER_URL_PLACEHOLDER, &repository.to_lowercase());
}
_ => {
replacement = replacement
@ -875,7 +874,7 @@ fn generate_file(
"https://github.com/tree-sitter/tree-sitter-{}",
language_name.to_lowercase()
),
)
);
}
}

View file

@ -674,7 +674,12 @@ impl Init {
(json.grammars[0].name.clone(), None)
};
generate_grammar_files(current_dir, &language_name, self.update, json_config_opts)?;
generate_grammar_files(
current_dir,
&language_name,
self.update,
json_config_opts.as_ref(),
)?;
Ok(())
}

View file

@ -372,9 +372,8 @@ pub fn parse_file_at_path(parser: &mut Parser, opts: &ParseFileOptions) -> Resul
bytes: source_code.len(),
duration: Some(duration),
});
} else {
parser.stop_printing_dot_graphs();
}
parser.stop_printing_dot_graphs();
if opts.print_time {
let duration = time.elapsed();

View file

@ -338,7 +338,7 @@ fn run_tests(
parser: &mut Parser,
test_entry: TestEntry,
opts: &mut TestOptions,
mut indent_level: i32,
mut indent_level: u32,
failures: &mut Vec<(String, String, String)>,
corrected_entries: &mut Vec<(String, String, String, String, usize, usize)>,
has_parse_errors: &mut bool,

View file

@ -273,13 +273,13 @@ impl std::fmt::Display for Pattern {
}
}
impl<'a, 'tree> PartialOrd for Match<'a, 'tree> {
impl PartialOrd for Match<'_, '_> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<'a, 'tree> Ord for Match<'a, 'tree> {
impl Ord for Match<'_, '_> {
// Tree-sitter returns matches in the order that they terminate
// during a depth-first walk of the tree. If multiple matches
// terminate on the same node, those matches are produced in the

View file

@ -161,7 +161,7 @@ fn test_parsing_with_custom_utf16le_input() {
let lines = ["pub fn foo() {", " 1", "}"]
.iter()
.map(|s| s.encode_utf16().map(|u| u.to_le()).collect::<Vec<_>>())
.map(|s| s.encode_utf16().map(u16::to_le).collect::<Vec<_>>())
.collect::<Vec<_>>();
let newline = [('\n' as u16).to_le()];
@ -267,7 +267,7 @@ fn test_parsing_text_with_byte_order_mark() {
.parse_utf16_le(
"\u{FEFF}fn a() {}"
.encode_utf16()
.map(|u| u.to_le())
.map(u16::to_le)
.collect::<Vec<_>>(),
None,
)
@ -1134,7 +1134,7 @@ fn test_parsing_utf16_code_with_errors_at_the_end_of_an_included_range() {
let source_code = "<script>a.</script>";
let utf16_source_code = source_code
.encode_utf16()
.map(|u| u.to_le())
.map(u16::to_le)
.collect::<Vec<_>>();
let start_byte = 2 * source_code.find("a.").unwrap();

View file

@ -3488,10 +3488,10 @@ fn test_query_captures_with_matches_removed() {
let mut captures = cursor.captures(&query, tree.root_node(), source.as_bytes());
while let Some((m, i)) = captures.next() {
println!("captured: {:?}, {}", m, i);
println!("captured: {m:?}, {i}");
let capture = m.captures[*i];
let text = capture.node.utf8_text(source.as_bytes()).unwrap();
println!("captured: {:?}", text);
println!("captured: {text:?}");
if text == "a" {
m.remove();
continue;

View file

@ -705,11 +705,11 @@ fn test_consistency_with_mid_codepoint_edit() {
#[test]
fn test_tree_cursor_on_aliased_root_with_extra_child() {
let source = r#"
let source = r"
fn main() {
C/* hi */::<D>::E;
}
"#;
";
let mut parser = Parser::new();
parser.set_language(&get_language("rust")).unwrap();