Skip to content

Commit

Permalink
refactor: fix clippy lint
Browse files Browse the repository at this point in the history
  • Loading branch information
uhyo committed Dec 27, 2024
1 parent 4977c57 commit 7c3bc71
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion crates/ast/src/current_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cell::Cell;

thread_local! {
/// Current file to be used when generating Pos.
static CURRENT_FILE_OF_POS: Cell<usize> = Cell::new(0);
static CURRENT_FILE_OF_POS: Cell<usize> = const { Cell::new(0) };
}

pub fn get_current_file_of_pos() -> usize {
Expand Down
2 changes: 1 addition & 1 deletion crates/checker/src/operation_checker/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S, Pos>) -> Self {
Self {
definitions,
Expand Down
6 changes: 2 additions & 4 deletions crates/checker/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(_)
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn run_check(context: CliContext) -> Result<CliContext> {
info!("Check succeeded");
eprintln!("'check' finished");
Ok(CliContext::SchemaResolved {
schema,
schema: *schema,
operations,
file_store,
config,
Expand Down Expand Up @@ -74,7 +74,7 @@ struct CheckImplInput<'src, 'a> {

enum CheckImplOutput<'src> {
Ok {
schema: LoadedSchema<'src, TypeSystemDocument<'src>>,
schema: Box<LoadedSchema<'src, TypeSystemDocument<'src>>>,
operations: Vec<(
PathBuf,
OperationDocument<'src>,
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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))
},
)
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ fn load_glob_files<'a, S: AsRef<str> + 'a>(

fn resolve_loaded_schema<'src>(
schema_docs: Vec<LoadedSchema<'src, TypeSystemOrExtensionDocument<'src>>>,
) -> Result<LoadedSchema<TypeSystemOrExtensionDocument>, CliError> {
) -> Result<LoadedSchema<'src, TypeSystemOrExtensionDocument<'src>>, CliError> {
let mut introsection: Option<Schema<_, _>> = None;
let mut documents: Vec<TypeSystemOrExtensionDocument> = vec![];
for doc in schema_docs {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/plugin_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/config-file/src/load_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
2 changes: 1 addition & 1 deletion crates/config-file/src/parsing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where

struct FromStrVisitor<T>(PhantomData<T>);

impl<'de, T> Visitor<'de> for FromStrVisitor<T>
impl<T> Visitor<'_> for FromStrVisitor<T>
where
T: FromStr,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/graphql-loader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ thread_local! {
/// Loaded config.
static CONFIG: RefCell<Config> = RefCell::new(Config::default());
/// Result of last operation.
static RESULT: RefCell<Option<String>> = RefCell::new(None);
static RESULT: RefCell<Option<String>> = const { RefCell::new(None) };
/// Global set of tasks.
static TASKS: RefCell<tasks::Tasks> = RefCell::new(tasks::Tasks::new());
}
Expand Down
4 changes: 2 additions & 2 deletions crates/introspection/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use insta::assert_display_snapshot;
use insta::assert_snapshot;
use nitrogql_printer::GraphQLPrinter;
use sourcemap_writer::JustWriter;

Expand Down Expand Up @@ -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);
}
18 changes: 9 additions & 9 deletions crates/parser/src/parser/builder/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Utils for dealing with Pair<Rule>
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> {
Expand All @@ -13,8 +13,8 @@ pub trait PairExt<'a> {
fn all_children(self, rule: Rule) -> Vec<Pair<'a, Rule>>;
/// 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.
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/printer/src/json_printer/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> JSONWriterValue for JSONValue<'_, T>
where
T: JsonPrintable,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/printer/src/operation_type_printer/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/printer/src/ts_types/ts_types_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn ts_intersection(types: impl IntoIterator<Item = TSType>) -> 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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/semantics/src/type_system_to_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn convert_type<S: Deref<Target = str>, D>(ty: &graphql_type_system::Type<S, D>)
}

fn convert_arguments<S: Deref<Target = str>, D>(
arguments: &Vec<graphql_type_system::InputValue<S, D>>,
arguments: &[graphql_type_system::InputValue<S, D>],
) -> Option<ArgumentsDefinition> {
if arguments.is_empty() {
None
Expand Down

0 comments on commit 7c3bc71

Please sign in to comment.