From 7c3bc71fca32fe0af66212c95dfdb8a2110164c1 Mon Sep 17 00:00:00 2001 From: uhyo Date: Fri, 27 Dec 2024 22:44:26 +0900 Subject: [PATCH] refactor: fix clippy lint --- crates/ast/src/current_file.rs | 2 +- .../checker/src/operation_checker/context.rs | 2 +- crates/checker/src/types.rs | 6 ++---- crates/cli/src/check.rs | 10 +++++----- crates/cli/src/main.rs | 2 +- crates/cli/src/plugin_host.rs | 2 +- crates/config-file/src/load_config.rs | 2 +- crates/config-file/src/parsing_utils.rs | 2 +- crates/graphql-loader/src/main.rs | 2 +- crates/introspection/src/tests/mod.rs | 4 ++-- crates/parser/src/parser/builder/utils.rs | 18 +++++++++--------- crates/printer/src/json_printer/helpers.rs | 2 +- .../src/operation_type_printer/visitor.rs | 2 +- crates/printer/src/ts_types/ts_types_util.rs | 2 +- crates/semantics/src/type_system_to_ast.rs | 2 +- 15 files changed, 29 insertions(+), 31 deletions(-) diff --git a/crates/ast/src/current_file.rs b/crates/ast/src/current_file.rs index 09819df0..604a82fc 100644 --- a/crates/ast/src/current_file.rs +++ b/crates/ast/src/current_file.rs @@ -2,7 +2,7 @@ use std::cell::Cell; thread_local! { /// Current file to be used when generating Pos. - static CURRENT_FILE_OF_POS: Cell = Cell::new(0); + static CURRENT_FILE_OF_POS: Cell = const { Cell::new(0) }; } pub fn get_current_file_of_pos() -> usize { diff --git a/crates/checker/src/operation_checker/context.rs b/crates/checker/src/operation_checker/context.rs index 20a1c5ba..7c8a03ae 100644 --- a/crates/checker/src/operation_checker/context.rs +++ b/crates/checker/src/operation_checker/context.rs @@ -7,7 +7,7 @@ pub struct OperationCheckContext<'schema, 'src, S> { phantom: std::marker::PhantomData<&'src ()>, } -impl<'schema, 'src, S> OperationCheckContext<'schema, 'src, S> { +impl<'schema, S> OperationCheckContext<'schema, '_, S> { pub fn new(definitions: &'schema Schema) -> Self { Self { definitions, diff --git a/crates/checker/src/types.rs b/crates/checker/src/types.rs index 10db35b6..515f6bf7 100644 --- a/crates/checker/src/types.rs +++ b/crates/checker/src/types.rs @@ -53,7 +53,7 @@ pub fn is_subtype<'src, S: Text<'src>>( } else { other }; - return is_subtype(definitions, target_inner.as_inner(), other); + is_subtype(definitions, target_inner.as_inner(), other) } Type::List(target_inner) => { if let Type::List(other_inner) = other { @@ -71,9 +71,7 @@ pub fn is_subtype<'src, S: Text<'src>>( } else { None }; - let Some(target_def) = definitions.get_type(target_name) else { - return None; - }; + let target_def = definitions.get_type(target_name)?; let other_def = other_name.and_then(|other_name| definitions.get_type(other_name)); match **target_def { TypeDefinition::Scalar(_) diff --git a/crates/cli/src/check.rs b/crates/cli/src/check.rs index 72854775..678c7fff 100644 --- a/crates/cli/src/check.rs +++ b/crates/cli/src/check.rs @@ -46,7 +46,7 @@ pub fn run_check(context: CliContext) -> Result { info!("Check succeeded"); eprintln!("'check' finished"); Ok(CliContext::SchemaResolved { - schema, + schema: *schema, operations, file_store, config, @@ -74,7 +74,7 @@ struct CheckImplInput<'src, 'a> { enum CheckImplOutput<'src> { Ok { - schema: LoadedSchema<'src, TypeSystemDocument<'src>>, + schema: Box>>, operations: Vec<( PathBuf, OperationDocument<'src>, @@ -138,7 +138,7 @@ fn check_impl<'src>(input: CheckImplInput<'src, '_>) -> CheckImplOutput<'src> { } } else { CheckImplOutput::Ok { - schema: loaded_schema, + schema: Box::new(loaded_schema), operations, } } @@ -217,7 +217,7 @@ fn resolve_operations( .iter() .map( |(path, doc, ext, file_by_index)| -> std::result::Result<_, _> { - let doc = resolve_operation_imports((&path, &doc, &ext), &operation_resolver)?; + let doc = resolve_operation_imports((path, doc, ext), &operation_resolver)?; Ok((path.clone(), doc, ext.clone(), *file_by_index)) }, ) @@ -249,7 +249,7 @@ impl<'a, 'src> Operations<'a, 'src> { } } -impl<'a, 'src> OperationResolver<'src> for Operations<'a, 'src> { +impl<'src> OperationResolver<'src> for Operations<'_, 'src> { fn resolve( &self, path: &Path, diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 001ef4b3..1cadbe09 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -323,7 +323,7 @@ fn load_glob_files<'a, S: AsRef + 'a>( fn resolve_loaded_schema<'src>( schema_docs: Vec>>, -) -> Result, CliError> { +) -> Result>, CliError> { let mut introsection: Option> = None; let mut documents: Vec = vec![]; for doc in schema_docs { diff --git a/crates/cli/src/plugin_host.rs b/crates/cli/src/plugin_host.rs index f8694600..f00f594a 100644 --- a/crates/cli/src/plugin_host.rs +++ b/crates/cli/src/plugin_host.rs @@ -10,7 +10,7 @@ impl<'host> PluginHost<'host> { } } -impl<'host> nitrogql_plugin::PluginHost for PluginHost<'host> { +impl nitrogql_plugin::PluginHost for PluginHost<'_> { fn load_virtual_file(&mut self, content: String) -> &'static str { let index = self .file_store diff --git a/crates/config-file/src/load_config.rs b/crates/config-file/src/load_config.rs index bb45204c..89921ced 100644 --- a/crates/config-file/src/load_config.rs +++ b/crates/config-file/src/load_config.rs @@ -97,6 +97,6 @@ pub async fn load_config( None => Ok(None), Some((path, source)) => parse_config(&source) .map(|config| Some((path.clone(), config))) - .ok_or_else(|| ConfigFileError::Validation(path)), + .ok_or(ConfigFileError::Validation(path)), } } diff --git a/crates/config-file/src/parsing_utils.rs b/crates/config-file/src/parsing_utils.rs index 497adbdb..6d61d7ce 100644 --- a/crates/config-file/src/parsing_utils.rs +++ b/crates/config-file/src/parsing_utils.rs @@ -71,7 +71,7 @@ where struct FromStrVisitor(PhantomData); -impl<'de, T> Visitor<'de> for FromStrVisitor +impl Visitor<'_> for FromStrVisitor where T: FromStr, { diff --git a/crates/graphql-loader/src/main.rs b/crates/graphql-loader/src/main.rs index 0ab159b0..577984bf 100644 --- a/crates/graphql-loader/src/main.rs +++ b/crates/graphql-loader/src/main.rs @@ -15,7 +15,7 @@ thread_local! { /// Loaded config. static CONFIG: RefCell = RefCell::new(Config::default()); /// Result of last operation. - static RESULT: RefCell> = RefCell::new(None); + static RESULT: RefCell> = const { RefCell::new(None) }; /// Global set of tasks. static TASKS: RefCell = RefCell::new(tasks::Tasks::new()); } diff --git a/crates/introspection/src/tests/mod.rs b/crates/introspection/src/tests/mod.rs index 68e37ea5..46d236c8 100644 --- a/crates/introspection/src/tests/mod.rs +++ b/crates/introspection/src/tests/mod.rs @@ -1,4 +1,4 @@ -use insta::assert_display_snapshot; +use insta::assert_snapshot; use nitrogql_printer::GraphQLPrinter; use sourcemap_writer::JustWriter; @@ -1335,5 +1335,5 @@ fn read_introspection() { let mut buffer = String::new(); let mut writer = JustWriter::new(&mut buffer); schema.print_graphql(&mut writer); - assert_display_snapshot!(buffer); + assert_snapshot!(buffer); } diff --git a/crates/parser/src/parser/builder/utils.rs b/crates/parser/src/parser/builder/utils.rs index ca649dea..a8b4c650 100644 --- a/crates/parser/src/parser/builder/utils.rs +++ b/crates/parser/src/parser/builder/utils.rs @@ -1,7 +1,7 @@ //! Utils for dealing with Pair use super::super::Rule; -use nitrogql_ast::base::{Ident, Keyword, Pos, Punc}; +use nitrogql_ast::base::{Ident, Keyword, Pos}; use pest::iterators::Pair; pub trait PairExt<'a> { @@ -13,8 +13,8 @@ pub trait PairExt<'a> { fn all_children(self, rule: Rule) -> Vec>; /// Generate a Pos for this pair. fn to_pos(&self) -> Pos; - /// Generate a Punc from this pair. - fn to_punc(&self) -> Punc<'a>; + // /// Generate a Punc from this pair. + // fn to_punc(&self) -> Punc<'a>; /// Generate a Keyword from this pair. fn to_keyword(&self) -> Keyword<'a>; /// Generate an Ident from this pair. @@ -57,12 +57,12 @@ impl<'a> PairExt<'a> for Pair<'a, Rule> { // convert 1-based to 0-based Pos::new(line - 1, column - 1) } - fn to_punc(&self) -> Punc<'a> { - Punc { - position: self.to_pos(), - token: self.as_str(), - } - } + // fn to_punc(&self) -> Punc<'a> { + // Punc { + // position: self.to_pos(), + // token: self.as_str(), + // } + // } fn to_keyword(&self) -> Keyword<'a> { Keyword { position: self.to_pos(), diff --git a/crates/printer/src/json_printer/helpers.rs b/crates/printer/src/json_printer/helpers.rs index d2b355c9..bee74e0a 100644 --- a/crates/printer/src/json_printer/helpers.rs +++ b/crates/printer/src/json_printer/helpers.rs @@ -8,7 +8,7 @@ use super::to_json::JsonPrintable; pub struct JSONValue<'a, T: JsonPrintable>(pub &'a T); -impl<'a, T> JSONWriterValue for JSONValue<'a, T> +impl JSONWriterValue for JSONValue<'_, T> where T: JsonPrintable, { diff --git a/crates/printer/src/operation_type_printer/visitor.rs b/crates/printer/src/operation_type_printer/visitor.rs index d40af472..0c325f22 100644 --- a/crates/printer/src/operation_type_printer/visitor.rs +++ b/crates/printer/src/operation_type_printer/visitor.rs @@ -128,7 +128,7 @@ pub struct OperationTypePrinterContext<'a, 'src, S: Text<'src>> { pub fragment_definitions: HashMap<&'src str, &'a FragmentDefinition<'src>>, } -impl<'a, 'src> OperationPrinterVisitor for OperationTypePrinterVisitor<'a, 'src> { +impl OperationPrinterVisitor for OperationTypePrinterVisitor<'_, '_> { fn print_header(&self, writer: &mut impl SourceMapWriter) { writeln!( writer, diff --git a/crates/printer/src/ts_types/ts_types_util.rs b/crates/printer/src/ts_types/ts_types_util.rs index 8ead6285..0c2805b0 100644 --- a/crates/printer/src/ts_types/ts_types_util.rs +++ b/crates/printer/src/ts_types/ts_types_util.rs @@ -32,7 +32,7 @@ pub fn ts_intersection(types: impl IntoIterator) -> TSType { let object_type = object_props .is_empty() .not() - .then(|| TSType::Object(object_props)); + .then_some(TSType::Object(object_props)); if others.is_empty() { object_type.unwrap_or(TSType::Unknown) } else { diff --git a/crates/semantics/src/type_system_to_ast.rs b/crates/semantics/src/type_system_to_ast.rs index bfb0e343..955ed3f8 100644 --- a/crates/semantics/src/type_system_to_ast.rs +++ b/crates/semantics/src/type_system_to_ast.rs @@ -178,7 +178,7 @@ fn convert_type, D>(ty: &graphql_type_system::Type) } fn convert_arguments, D>( - arguments: &Vec>, + arguments: &[graphql_type_system::InputValue], ) -> Option { if arguments.is_empty() { None