Skip to content

Commit 4b045ee

Browse files
committed
fixes clippy
1 parent 9d4a06e commit 4b045ee

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

src/validation/rules/unique_variable_names.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ impl<'v> ValidationRule for UniqueVariableNames<'v> {
6363
"UniqueVariableNames"
6464
}
6565

66-
fn validate<'a>(
66+
fn validate(
6767
&self,
68-
ctx: &'a mut OperationVisitorContext,
68+
ctx: &mut OperationVisitorContext,
6969
error_collector: &mut ValidationErrorContext,
7070
) {
7171
visit_document(
7272
&mut UniqueVariableNames::new(),
73-
&ctx.operation,
73+
ctx.operation,
7474
ctx,
7575
error_collector,
7676
);

src/validation/rules/values_of_correct_type.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414

1515
use super::ValidationRule;
1616

17+
#[derive(Default)]
1718
pub struct ValuesOfCorrectType {}
1819

1920
impl ValuesOfCorrectType {
@@ -22,10 +23,7 @@ impl ValuesOfCorrectType {
2223
}
2324

2425
pub fn is_custom_scalar(&self, type_name: &str) -> bool {
25-
match type_name {
26-
"String" | "Int" | "Float" | "Boolean" | "ID" => false,
27-
_ => true,
28-
}
26+
!matches!(type_name, "String" | "Int" | "Float" | "Boolean" | "ID")
2927
}
3028

3129
pub fn validate_value(
@@ -37,7 +35,7 @@ impl ValuesOfCorrectType {
3735
if let Some(input_type) = visitor_context.current_input_type_literal() {
3836
let named_type = input_type.inner_type();
3937

40-
if let Some(type_def) = visitor_context.schema.type_by_name(&named_type) {
38+
if let Some(type_def) = visitor_context.schema.type_by_name(named_type) {
4139
if !type_def.is_leaf_type() {
4240
user_context.report_error(ValidationError {
4341
error_code: self.error_code(),
@@ -78,12 +76,7 @@ impl ValuesOfCorrectType {
7876
if let TypeDefinition::Enum(enum_type_def) = &type_def {
7977
match raw_value {
8078
Value::Enum(enum_value) => {
81-
if enum_type_def
82-
.values
83-
.iter()
84-
.find(|v| v.name.eq(enum_value))
85-
.is_none()
86-
{
79+
if enum_type_def.values.iter().any(|v| v.name.eq(enum_value)) {
8780
user_context.report_error(ValidationError {
8881
error_code: self.error_code(),
8982
message: format!(
@@ -193,14 +186,14 @@ impl ValidationRule for ValuesOfCorrectType {
193186
"ValuesOfCorrectType"
194187
}
195188

196-
fn validate<'a>(
189+
fn validate(
197190
&self,
198-
ctx: &'a mut OperationVisitorContext,
191+
ctx: &mut OperationVisitorContext,
199192
error_collector: &mut ValidationErrorContext,
200193
) {
201194
visit_document(
202195
&mut ValuesOfCorrectType::new(),
203-
&ctx.operation,
196+
ctx.operation,
204197
ctx,
205198
error_collector,
206199
);

src/validation/rules/variables_are_input_types.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::validation::utils::ValidationErrorContext;
1212
/// input types (scalar, enum, or input object).
1313
///
1414
/// See https://spec.graphql.org/draft/#sec-Variables-Are-Input-Types
15+
#[derive(Default)]
1516
pub struct VariablesAreInputTypes;
1617

1718
impl VariablesAreInputTypes {
@@ -29,7 +30,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for VariablesAreInputTypes
2930
) {
3031
if let Some(var_schema_type) = context
3132
.schema
32-
.type_by_name(&variable_definition.var_type.inner_type())
33+
.type_by_name(variable_definition.var_type.inner_type())
3334
{
3435
if !var_schema_type.is_input_type() {
3536
user_context.report_error(ValidationError {
@@ -50,14 +51,14 @@ impl ValidationRule for VariablesAreInputTypes {
5051
"VariablesAreInputTypes"
5152
}
5253

53-
fn validate<'a>(
54+
fn validate(
5455
&self,
55-
ctx: &'a mut OperationVisitorContext,
56+
ctx: &mut OperationVisitorContext,
5657
error_collector: &mut ValidationErrorContext,
5758
) {
5859
visit_document(
5960
&mut VariablesAreInputTypes::new(),
60-
&ctx.operation,
61+
ctx.operation,
6162
ctx,
6263
error_collector,
6364
);

src/validation/rules/variables_in_allowed_position.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use super::ValidationRule;
1616
/// Variable usages must be compatible with the arguments they are passed to.
1717
///
1818
/// See https://spec.graphql.org/draft/#sec-All-Variable-Usages-are-Allowed
19+
#[derive(Default)]
1920
pub struct VariablesInAllowedPosition<'a> {
2021
spreads: HashMap<Scope<'a>, HashSet<&'a str>>,
2122
variable_usages: HashMap<Scope<'a>, Vec<(&'a str, &'a Type)>>,
@@ -49,8 +50,7 @@ impl<'a> VariablesInAllowedPosition<'a> {
4950

5051
if let Some(usages) = self.variable_usages.get(from) {
5152
for (var_name, var_type) in usages {
52-
if let Some(ref var_def) = var_defs.iter().find(|var_def| var_def.name == *var_name)
53-
{
53+
if let Some(var_def) = var_defs.iter().find(|var_def| var_def.name == *var_name) {
5454
let expected_type = match (&var_def.default_value, &var_def.var_type) {
5555
(Some(_), Type::ListType(inner)) => Type::NonNullType(inner.clone()),
5656
(Some(default_value), Type::NamedType(_)) => {
@@ -143,7 +143,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for VariablesInAllowedPosi
143143
if let Some(scope) = &self.current_scope {
144144
self.spreads
145145
.entry(scope.clone())
146-
.or_insert_with(HashSet::new)
146+
.or_default()
147147
.insert(&fragment_spread.fragment_name);
148148
}
149149
}
@@ -158,7 +158,7 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for VariablesInAllowedPosi
158158
self.variable_defs
159159
.entry(scope.clone())
160160
.or_default()
161-
.push(&variable_definition);
161+
.push(variable_definition);
162162
}
163163
}
164164

@@ -168,13 +168,13 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for VariablesInAllowedPosi
168168
_: &mut ValidationErrorContext,
169169
variable_name: &'a str,
170170
) {
171-
if let (&Some(ref scope), Some(input_type)) = (
171+
if let (Some(scope), Some(input_type)) = (
172172
&self.current_scope,
173173
visitor_context.current_input_type_literal(),
174174
) {
175175
self.variable_usages
176176
.entry(scope.clone())
177-
.or_insert_with(Vec::new)
177+
.or_default()
178178
.push((variable_name, input_type));
179179
}
180180
}
@@ -185,14 +185,14 @@ impl<'v> ValidationRule for VariablesInAllowedPosition<'v> {
185185
"VariablesInAllowedPosition"
186186
}
187187

188-
fn validate<'a>(
188+
fn validate(
189189
&self,
190-
ctx: &'a mut OperationVisitorContext,
190+
ctx: &mut OperationVisitorContext,
191191
error_collector: &mut ValidationErrorContext,
192192
) {
193193
visit_document(
194194
&mut VariablesInAllowedPosition::new(),
195-
&ctx.operation,
195+
ctx.operation,
196196
ctx,
197197
error_collector,
198198
);

src/validation/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::{Serialize, Serializer};
44
use serde_with::{serde_as, SerializeAs};
55
use std::fmt::Debug;
66

7-
#[derive(Debug)]
7+
#[derive(Debug, Default)]
88
pub struct ValidationErrorContext {
99
pub errors: Vec<ValidationError>,
1010
}

src/validation/validate.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ impl ValidationPlan {
2626
}
2727
}
2828

29+
impl Default for ValidationPlan {
30+
fn default() -> Self {
31+
Self::new()
32+
}
33+
}
34+
2935
pub fn validate<'a>(
3036
schema: &'a schema::Document,
3137
operation: &'a query::Document,

0 commit comments

Comments
 (0)