From 6089a7526288bd0c6c6d41c203c2f2f26eb1323e Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Tue, 25 Feb 2025 13:19:03 +0100 Subject: [PATCH] Rust/Ruby/Python: format code --- python/extractor/tsg-python/src/main.rs | 12 ++++++------ rust/extractor/src/config.rs | 2 +- rust/extractor/src/config/deserialize.rs | 2 +- rust/extractor/src/diagnostics.rs | 2 +- rust/extractor/src/main.rs | 4 ++-- rust/extractor/src/rust_analyzer.rs | 2 +- rust/extractor/src/translate/base.rs | 10 +++++----- rust/extractor/src/translate/mappings.rs | 2 +- shared/tree-sitter-extractor/src/extractor/mod.rs | 12 ++++-------- .../tree-sitter-extractor/tests/integration_test.rs | 2 +- .../tests/multiple_languages.rs | 2 +- 11 files changed, 24 insertions(+), 28 deletions(-) diff --git a/python/extractor/tsg-python/src/main.rs b/python/extractor/tsg-python/src/main.rs index 942d3608853..c111ef194ea 100644 --- a/python/extractor/tsg-python/src/main.rs +++ b/python/extractor/tsg-python/src/main.rs @@ -7,17 +7,17 @@ use std::path::Path; -use anyhow::anyhow; use anyhow::Context as _; use anyhow::Result; -use clap::{Command, Arg, ArgAction}; +use anyhow::anyhow; +use clap::{Arg, ArgAction, Command}; use tree_sitter::Parser; -use tree_sitter_graph::ast::File; -use tree_sitter_graph::functions::Functions; use tree_sitter_graph::ExecutionConfig; use tree_sitter_graph::Identifier; use tree_sitter_graph::NoCancellation; use tree_sitter_graph::Variables; +use tree_sitter_graph::ast::File; +use tree_sitter_graph::functions::Functions; const BUILD_VERSION: &'static str = env!("CARGO_PKG_VERSION"); @@ -332,7 +332,7 @@ pub mod extra_functions { return Err(ExecutionError::FunctionFailed( "unnamed-child-index".into(), format!("Cannot call child-index on the root node"), - )) + )); } }; let mut tree_cursor = parent.walk(); @@ -490,7 +490,7 @@ fn main() -> Result<()> { .short('t') .long("tsg") .action(ArgAction::Set) - .required(false) + .required(false), ) .arg(Arg::new("source").index(1).required(true)) .get_matches(); diff --git a/rust/extractor/src/config.rs b/rust/extractor/src/config.rs index c87af7e7728..24fef22cff0 100644 --- a/rust/extractor/src/config.rs +++ b/rust/extractor/src/config.rs @@ -4,9 +4,9 @@ use anyhow::Context; use clap::Parser; use codeql_extractor::trap; use figment::{ + Figment, providers::{Env, Format, Serialized, Yaml}, value::Value, - Figment, }; use itertools::Itertools; use ra_ap_cfg::{CfgAtom, CfgDiff}; diff --git a/rust/extractor/src/config/deserialize.rs b/rust/extractor/src/config/deserialize.rs index 5953acd8605..4f3d9689790 100644 --- a/rust/extractor/src/config/deserialize.rs +++ b/rust/extractor/src/config/deserialize.rs @@ -1,5 +1,5 @@ -use serde::de::{Error, Unexpected, Visitor}; use serde::Deserializer; +use serde::de::{Error, Unexpected, Visitor}; use std::collections::HashMap; use std::fmt::Formatter; use std::hash::BuildHasher; diff --git a/rust/extractor/src/diagnostics.rs b/rust/extractor/src/diagnostics.rs index d111975db7d..a39706a0cf2 100644 --- a/rust/extractor/src/diagnostics.rs +++ b/rust/extractor/src/diagnostics.rs @@ -2,8 +2,8 @@ use crate::config::Config; use anyhow::Context; use chrono::{DateTime, Utc}; use ra_ap_project_model::ProjectManifest; -use serde::ser::SerializeMap; use serde::Serialize; +use serde::ser::SerializeMap; use std::collections::HashMap; use std::fmt::Display; use std::fs::File; diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 48445a935c3..17bf43b91c6 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -1,11 +1,11 @@ -use crate::diagnostics::{emit_extraction_diagnostics, ExtractionStep}; +use crate::diagnostics::{ExtractionStep, emit_extraction_diagnostics}; use crate::rust_analyzer::path_to_file_id; use crate::trap::TrapId; use anyhow::Context; use archive::Archiver; use ra_ap_hir::Semantics; -use ra_ap_ide_db::line_index::{LineCol, LineIndex}; use ra_ap_ide_db::RootDatabase; +use ra_ap_ide_db::line_index::{LineCol, LineIndex}; use ra_ap_load_cargo::LoadCargoConfig; use ra_ap_paths::{AbsPathBuf, Utf8PathBuf}; use ra_ap_project_model::{CargoConfig, ProjectManifest}; diff --git a/rust/extractor/src/rust_analyzer.rs b/rust/extractor/src/rust_analyzer.rs index 2ebbcac6b59..f0ca9a22320 100644 --- a/rust/extractor/src/rust_analyzer.rs +++ b/rust/extractor/src/rust_analyzer.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use ra_ap_base_db::SourceDatabase; use ra_ap_hir::Semantics; use ra_ap_ide_db::RootDatabase; -use ra_ap_load_cargo::{load_workspace_at, LoadCargoConfig}; +use ra_ap_load_cargo::{LoadCargoConfig, load_workspace_at}; use ra_ap_paths::{AbsPath, Utf8PathBuf}; use ra_ap_project_model::ProjectManifest; use ra_ap_project_model::{CargoConfig, ManifestPath}; diff --git a/rust/extractor/src/translate/base.rs b/rust/extractor/src/translate/base.rs index 9c8e919e5aa..6618feae4c2 100644 --- a/rust/extractor/src/translate/base.rs +++ b/rust/extractor/src/translate/base.rs @@ -4,23 +4,23 @@ use crate::rust_analyzer::FileSemanticInformation; use crate::trap::{DiagnosticSeverity, TrapFile, TrapId}; use crate::trap::{Label, TrapClass}; use itertools::Either; -use ra_ap_base_db::ra_salsa::InternKey; use ra_ap_base_db::CrateOrigin; +use ra_ap_base_db::ra_salsa::InternKey; use ra_ap_hir::db::ExpandDatabase; use ra_ap_hir::{ Adt, Crate, ItemContainer, Module, ModuleDef, PathResolution, Semantics, Type, Variant, }; -use ra_ap_hir_def::type_ref::Mutability; use ra_ap_hir_def::ModuleId; +use ra_ap_hir_def::type_ref::Mutability; use ra_ap_hir_expand::ExpandTo; -use ra_ap_ide_db::line_index::{LineCol, LineIndex}; use ra_ap_ide_db::RootDatabase; +use ra_ap_ide_db::line_index::{LineCol, LineIndex}; use ra_ap_parser::SyntaxKind; use ra_ap_span::{EditionedFileId, TextSize}; use ra_ap_syntax::ast::HasName; use ra_ap_syntax::{ - ast, AstNode, NodeOrToken, SyntaxElementChildren, SyntaxError, SyntaxNode, SyntaxToken, - TextRange, + AstNode, NodeOrToken, SyntaxElementChildren, SyntaxError, SyntaxNode, SyntaxToken, TextRange, + ast, }; #[macro_export] diff --git a/rust/extractor/src/translate/mappings.rs b/rust/extractor/src/translate/mappings.rs index 6ad8a7d1df6..3068e5cea52 100644 --- a/rust/extractor/src/translate/mappings.rs +++ b/rust/extractor/src/translate/mappings.rs @@ -1,6 +1,6 @@ use ra_ap_hir::{Enum, Function, HasContainer, Module, Semantics, Struct, Trait, Union}; use ra_ap_ide_db::RootDatabase; -use ra_ap_syntax::{ast, ast::RangeItem, AstNode}; +use ra_ap_syntax::{AstNode, ast, ast::RangeItem}; pub(crate) trait TextValue { fn try_get_text(&self) -> Option; diff --git a/shared/tree-sitter-extractor/src/extractor/mod.rs b/shared/tree-sitter-extractor/src/extractor/mod.rs index fcefe87106c..18a0cfc9452 100644 --- a/shared/tree-sitter-extractor/src/extractor/mod.rs +++ b/shared/tree-sitter-extractor/src/extractor/mod.rs @@ -7,13 +7,13 @@ use std::collections::BTreeSet as Set; use std::env; use std::path::Path; +use tracing_subscriber::EnvFilter; +use tracing_subscriber::Layer; use tracing_subscriber::filter::Filtered; use tracing_subscriber::fmt::format::DefaultFields; use tracing_subscriber::fmt::format::Format; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; -use tracing_subscriber::EnvFilter; -use tracing_subscriber::Layer; use tree_sitter::{Language, Node, Parser, Range, Tree}; pub mod simple; @@ -591,11 +591,7 @@ impl<'a> Visitor<'a> { } } } - if is_valid { - Some(args) - } else { - None - } + if is_valid { Some(args) } else { None } } fn type_matches(&self, tp: &TypeName, type_info: &node_types::FieldTypeInfo) -> bool { @@ -615,7 +611,7 @@ impl<'a> Visitor<'a> { } node_types::FieldTypeInfo::ReservedWordInt(int_mapping) => { - return !tp.named && int_mapping.contains_key(&tp.kind) + return !tp.named && int_mapping.contains_key(&tp.kind); } } false diff --git a/shared/tree-sitter-extractor/tests/integration_test.rs b/shared/tree-sitter-extractor/tests/integration_test.rs index cc453eeef74..34d475df5d0 100644 --- a/shared/tree-sitter-extractor/tests/integration_test.rs +++ b/shared/tree-sitter-extractor/tests/integration_test.rs @@ -4,7 +4,7 @@ use codeql_extractor::trap; use tree_sitter_ql; mod common; -use common::{create_source_dir, expect_trap_file, SourceArchive}; +use common::{SourceArchive, create_source_dir, expect_trap_file}; /// A very simple happy-path test. /// We run the extractor using the tree-sitter-ql grammar and a single source file, diff --git a/shared/tree-sitter-extractor/tests/multiple_languages.rs b/shared/tree-sitter-extractor/tests/multiple_languages.rs index f14100f6e0c..766de2bc782 100644 --- a/shared/tree-sitter-extractor/tests/multiple_languages.rs +++ b/shared/tree-sitter-extractor/tests/multiple_languages.rs @@ -3,7 +3,7 @@ use codeql_extractor::trap; use tree_sitter_ql; mod common; -use common::{create_source_dir, expect_trap_file, SourceArchive}; +use common::{SourceArchive, create_source_dir, expect_trap_file}; /// Like the `simple_extractor` test but with multiple languages. /// This is in a separate crate because the simple extractor API sets up a