Skip to content

Commit 2089ba6

Browse files
authored
Tune up project linting (#1317)
- move lints configuration to `Cargo.toml` - omit using `#[deny]` for rustc lints for better future compatibility - use `#[expect]` instead of `#[allow]` asap
1 parent 9f12fe3 commit 2089ba6

File tree

80 files changed

+355
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+355
-139
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
resolver = "1" # unifying Cargo features asap for Book tests
33
members = [
44
"benches",
5+
"book",
56
"juniper_codegen",
67
"juniper",
78
"juniper_hyper",

benches/Cargo.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@ authors = ["Christoph Herzog <[email protected]>"]
66
publish = false
77

88
[dependencies]
9-
dataloader = "0.18" # for Book only
10-
futures = "0.3"
119
juniper = { path = "../juniper" }
1210

1311
[dev-dependencies]
1412
criterion = "0.5"
1513
tokio = { version = "1.0", features = ["rt-multi-thread"] }
1614

15+
[lints.clippy]
16+
allow_attributes = "warn"
17+
allow_attributes_without_reason = "warn"
18+
[lints.rust]
19+
closure_returning_async_block = "warn"
20+
future_incompatible = { level = "warn", priority = -1 }
21+
impl_trait_redundant_captures = "warn"
22+
non_ascii_idents = "forbid"
23+
unsafe_code = "forbid"
24+
unused_crate_dependencies = "warn"
25+
1726
[[bench]]
1827
name = "benchmark"
1928
harness = false

benches/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#[cfg(test)]
2+
mod for_benches_only {
3+
use criterion as _;
4+
use tokio as _;
5+
}
6+
17
use juniper::{
28
DefaultScalarValue, EmptyMutation, EmptySubscription, ExecutionError, FieldError, GraphQLEnum,
39
GraphQLObject, RootNode, Value, Variables, graphql_object,

book/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "juniper_book"
3+
version = "0.0.0"
4+
edition = "2024"
5+
authors = ["Kai Ren <[email protected]>"]
6+
publish = false
7+
8+
[dependencies]
9+
dataloader = "0.18" # for Book only
10+
11+
[lints.clippy]
12+
allow_attributes = "warn"
13+
allow_attributes_without_reason = "warn"
14+
[lints.rust]
15+
closure_returning_async_block = "warn"
16+
future_incompatible = { level = "warn", priority = -1 }
17+
impl_trait_redundant_captures = "warn"
18+
non_ascii_idents = "forbid"
19+
unsafe_code = "forbid"
20+
unused_crate_dependencies = "warn"

book/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Crate keeping dependencies for running Book tests.
2+
3+
use dataloader as _;

book/src/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Exposing simple enums and structs as [GraphQL] types is just a matter of adding
2727
For more advanced mappings, [Juniper] provides multiple macros to map your [Rust] types to a [GraphQL schema][schema]. The most important one is the [`#[graphql_object]` attribute][2] that is used for declaring a [GraphQL object] with resolvers (typically used for declaring [`Query` and `Mutation` roots][1]).
2828

2929
```rust
30-
# # ![allow(unused_variables)]
30+
# #![expect(unused_variables, reason = "example")]
3131
# extern crate juniper;
3232
#
3333
# use std::fmt::Display;

book/src/types/enums.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ enum StarWarsEpisode {
112112

113113
By default, all [enum][3] variants are included in the generated [GraphQL enum][0] type as values. To prevent including a specific variant, annotate it with the `#[graphql(ignore)]` attribute:
114114
```rust
115-
# #![allow(dead_code)]
115+
# #![expect(dead_code, reason = "example")]
116116
# extern crate juniper;
117117
# use juniper::GraphQLEnum;
118118
#

book/src/types/input_objects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Input objects
77
88
In [Juniper], defining a [GraphQL input object][0] is quite straightforward and similar to how [trivial GraphQL objects are defined](objects/index.md) - by using the [`#[derive(GraphQLInputObject)]` attribute][2] on a [Rust struct][struct]:
99
```rust
10-
# #![allow(unused_variables)]
10+
# #![expect(unused_variables, reason = "example")]
1111
# extern crate juniper;
1212
# use juniper::{GraphQLInputObject, GraphQLObject, graphql_object};
1313
#

book/src/types/interfaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ trait Person {
356356

357357
By default, all [struct][24] fields or [trait][20] methods are considered as [GraphQL fields][4]. If a helper method is needed, or it should be ignored for some reason, then it should be marked with the `#[graphql(ignore)]` attribute:
358358
```rust
359-
# #![allow(dead_code)]
359+
# #![expect(dead_code, reason = "example")]
360360
# extern crate juniper;
361361
# use std::marker::PhantomPinned;
362362
# use juniper::{graphql_interface, GraphQLInterface};

book/src/types/objects/complex_fields.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl Person {
165165

166166
By default, all methods of an [`impl` block][6] are exposed as [GraphQL fields][4]. If a method should not be exposed as a [GraphQL field][4], it should be defined in a separate [`impl` block][6] or marked with the `#[graphql(ignore)]` attribute:
167167
```rust
168-
# #![allow(dead_code)]
168+
# #![expect(dead_code, reason = "example")]
169169
# extern crate juniper;
170170
# use juniper::graphql_object;
171171
#

book/src/types/objects/context.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _Context_ is a feature in [Juniper] that lets [field][4] resolvers access global
55

66
Let's say that we have a simple `User`s database in a `HashMap`:
77
```rust
8-
# #![allow(dead_code)]
8+
# #![expect(dead_code, reason = "example")]
99
# use std::collections::HashMap;
1010
#
1111
struct Database {

book/src/types/objects/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct Person {
152152

153153
By default, all [struct] fields are included into the generated [GraphQL object][0] type. To prevent inclusion of a specific field annotate it with the `#[graphql(ignore)]` attribute:
154154
```rust
155-
# #![allow(dead_code)]
155+
# #![expect(dead_code, reason = "example")]
156156
# extern crate juniper;
157157
# use juniper::GraphQLObject;
158158
#

juniper/Cargo.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,19 @@ serde_json = "1.0.18"
8484
serial_test = "3.0"
8585
tokio = { version = "1.0", features = ["macros", "time", "rt-multi-thread"] }
8686

87+
[lints.clippy]
88+
allow_attributes = "warn"
89+
allow_attributes_without_reason = "warn"
90+
[lints.rust]
91+
closure_returning_async_block = "warn"
92+
future_incompatible = { level = "warn", priority = -1 }
93+
impl_trait_redundant_captures = "warn"
94+
missing_docs = "warn"
95+
non_ascii_idents = "forbid"
96+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(nightly)'] }
97+
unused_crate_dependencies = "warn"
98+
8799
[[bench]]
88100
name = "bench"
89101
harness = false
90102
path = "benches/bench.rs"
91-
92-
[lints.rust]
93-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(nightly)'] }

juniper/src/ast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub enum Type<'a> {
3535
/// Lists and objects variants are _spanned_, i.e. they contain a reference to
3636
/// their position in the source file, if available.
3737
#[derive(Clone, Debug, PartialEq)]
38-
#[allow(missing_docs)]
38+
#[expect(missing_docs, reason = "self-explanatory")]
3939
pub enum InputValue<S = DefaultScalarValue> {
4040
Null,
4141
Scalar(S),
@@ -100,7 +100,7 @@ pub struct InlineFragment<'a, S> {
100100
/// }
101101
/// ```
102102
#[derive(Clone, PartialEq, Debug)]
103-
#[allow(missing_docs)]
103+
#[expect(missing_docs, reason = "self-explanatory")]
104104
pub enum Selection<'a, S = DefaultScalarValue> {
105105
Field(Spanning<Field<'a, S>>),
106106
FragmentSpread(Spanning<FragmentSpread<'a, S>>),
@@ -113,15 +113,15 @@ pub struct Directive<'a, S> {
113113
pub arguments: Option<Spanning<Arguments<'a, S>>>,
114114
}
115115

116-
#[allow(missing_docs)]
116+
#[expect(missing_docs, reason = "self-explanatory")]
117117
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
118118
pub enum OperationType {
119119
Query,
120120
Mutation,
121121
Subscription,
122122
}
123123

124-
#[allow(missing_docs)]
124+
#[expect(missing_docs, reason = "self-explanatory")]
125125
#[derive(Clone, PartialEq, Debug)]
126126
pub struct Operation<'a, S> {
127127
pub operation_type: OperationType,

juniper/src/executor/look_ahead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type BorrowedSpanning<'a, T> = Spanning<T, &'a Span>;
2828
/// variables get automatically resolved.
2929
///
3030
/// [0]: https://en.wikipedia.org/wiki/Look-ahead_(backtracking)
31+
#[expect(missing_docs, reason = "self-explanatory")]
3132
#[derive(Clone, Debug, PartialEq)]
32-
#[allow(missing_docs)]
3333
#[must_use]
3434
pub enum LookAheadValue<'a, S: ScalarValue + 'a> {
3535
Null,

juniper/src/executor/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct Registry<'r, S = DefaultScalarValue> {
5656
pub types: FnvHashMap<Name, MetaType<'r, S>>,
5757
}
5858

59-
#[allow(missing_docs)]
59+
#[expect(missing_docs, reason = "self-explanatory")]
6060
#[derive(Clone)]
6161
pub enum FieldPath<'a> {
6262
Root(SourcePosition),
@@ -349,7 +349,6 @@ where
349349
{
350350
type Type = T;
351351

352-
#[allow(clippy::type_complexity)]
353352
fn into_resolvable(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>, S> {
354353
Ok(self.map(|(ctx, v)| (ctx, Some(v))))
355354
}
@@ -377,7 +376,6 @@ where
377376
{
378377
type Type = T;
379378

380-
#[allow(clippy::type_complexity)]
381379
fn into_resolvable(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>, S2> {
382380
self.map(|o| o.map(|(ctx, v)| (ctx, Some(v))))
383381
.map_err(FieldError::map_scalar_value)

juniper/src/executor_tests/async_await/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ enum UserKind {
1111
}
1212

1313
struct User {
14-
#[allow(dead_code)]
1514
id: i32,
1615
name: String,
1716
kind: UserKind,

juniper/src/executor_tests/interfaces_unions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ mod interface {
55
types::scalars::{EmptyMutation, EmptySubscription},
66
};
77

8-
#[allow(dead_code)] // TODO: Consider this for the GraphQL interfaces in the expansion.
8+
// TODO: Consider this for the GraphQL interfaces in the expansion.
9+
#[expect(dead_code, reason = "GraphQL schema testing")]
910
#[graphql_interface(for = [Cat, Dog])]
1011
trait Pet {
1112
fn name(&self) -> &str;

juniper/src/executor_tests/introspection/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod enums;
22
mod input_object;
33

44
// This asserts that the input objects defined public actually became public
5-
#[allow(unused_imports)]
5+
#[expect(unused_imports, reason = "`pub` assertion")]
66
use self::input_object::{NamedPublic, NamedPublicWithDescription};
77

88
use crate::{
@@ -23,7 +23,8 @@ enum Sample {
2323
struct Scalar(i32);
2424

2525
/// A sample interface
26-
#[allow(dead_code)] // TODO: Consider this for the GraphQL interfaces in the expansion.
26+
// TODO: Consider this for the GraphQL interfaces in the expansion.
27+
#[expect(dead_code, reason = "GraphQL schema testing")]
2728
#[graphql_interface(name = "SampleInterface", for = Root)]
2829
trait Interface {
2930
/// A sample field in the interface

juniper/src/http/mod.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,9 @@ impl<S: ScalarValue> GraphQLBatchResponse<S> {
361361
}
362362

363363
#[cfg(feature = "expose-test-schema")]
364-
#[allow(missing_docs)]
365364
pub mod tests {
365+
//! HTTP integration tests.
366+
366367
use std::time::Duration;
367368

368369
use serde_json::Value as Json;
@@ -373,8 +374,13 @@ pub mod tests {
373374
/// the http framework integration we are testing.
374375
#[derive(Debug)]
375376
pub struct TestResponse {
377+
/// Status code of the HTTP response.
376378
pub status_code: i32,
379+
380+
/// Body of the HTTP response, if any.
377381
pub body: Option<String>,
382+
383+
/// `Content-Type` header value of the HTTP response.
378384
pub content_type: String,
379385
}
380386

@@ -393,7 +399,7 @@ pub mod tests {
393399
fn post_graphql(&self, url: &str, body: &str) -> TestResponse;
394400
}
395401

396-
#[allow(missing_docs)]
402+
/// Runs integration tests suite for the provided [`HttpIntegration`].
397403
pub fn run_http_test_suite<T: HttpIntegration>(integration: &T) {
398404
println!("Running HTTP Test suite for integration");
399405

@@ -662,7 +668,10 @@ pub mod tests {
662668

663669
use super::{WS_INTEGRATION_EXPECT_DEFAULT_TIMEOUT, WsIntegration, WsIntegrationMessage};
664670

665-
#[allow(missing_docs)]
671+
/// Runs integration tests suite for the [legacy `graphql-ws` GraphQL over WebSocket
672+
/// Protocol][0].
673+
///
674+
/// [0]:https://github.com/apollographql/subscriptions-transport-ws/blob/v0.11.0/PROTOCOL.md
666675
pub async fn run_test_suite<T: WsIntegration>(integration: &T) {
667676
println!("Running `graphql-ws` test suite for integration");
668677

@@ -791,7 +800,10 @@ pub mod tests {
791800

792801
use super::{WS_INTEGRATION_EXPECT_DEFAULT_TIMEOUT, WsIntegration, WsIntegrationMessage};
793802

794-
#[allow(missing_docs)]
803+
/// Runs integration tests suite the [new `graphql-transport-ws` GraphQL over WebSocket
804+
/// Protocol][new].
805+
///
806+
/// [new]: https://github.com/enisdenjo/graphql-ws/blob/v5.14.0/PROTOCOL.md
795807
pub async fn run_test_suite<T: WsIntegration>(integration: &T) {
796808
println!("Running `graphql-transport-ws` test suite for integration");
797809

juniper/src/integrations/bigdecimal.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ use std::str::FromStr as _;
1212

1313
use crate::{InputValue, ScalarValue, Value, graphql_scalar};
1414

15+
// TODO: Try remove on upgrade of `bigdecimal` crate.
16+
mod for_minimal_versions_check_only {
17+
use num_bigint as _;
18+
}
19+
1520
/// Big decimal type.
1621
///
1722
/// Allows storing any real number to arbitrary precision; which avoids common

juniper/src/integrations/bson.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
1616
use crate::{InputValue, ScalarValue, Value, graphql_scalar};
1717

18+
// TODO: Try remove on upgrade of `bson` crate.
19+
mod for_minimal_versions_check_only {
20+
use tap as _;
21+
}
22+
1823
/// [BSON ObjectId][0] represented as a HEX string.
1924
///
2025
/// [`ObjectID` scalar][1] compliant.

juniper/src/integrations/chrono_tz.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
1414
use crate::{InputValue, ScalarValue, Value, graphql_scalar};
1515

16+
// TODO: Try remove on upgrade of `chrono-tz` crate.
17+
mod for_minimal_versions_check_only {
18+
use regex as _;
19+
}
20+
1621
/// Timezone based on [`IANA` database][0].
1722
///
1823
/// See ["List of tz database time zones"][3] `TZ database name` column for

juniper/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![cfg_attr(not(any(doc, test)), doc = env!("CARGO_PKG_NAME"))]
44
// Due to `schema_introspection` test.
55
#![cfg_attr(test, recursion_limit = "256")]
6-
#![warn(missing_docs)]
76

87
// Required for using `juniper_codegen` macros inside this crate to resolve
98
// absolute `::juniper` path correctly, without errors.
@@ -99,7 +98,7 @@ pub use crate::{
9998
};
10099

101100
/// An error that prevented query execution
102-
#[allow(missing_docs)]
101+
#[expect(missing_docs, reason = "self-explanatory")]
103102
#[derive(Clone, Debug, Eq, PartialEq)]
104103
pub enum GraphQLError {
105104
ParseError(Spanning<ParseError>),

juniper/src/parser/lexer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Lexer<'a> {
1515
/// A single scalar value literal
1616
///
1717
/// This is only used for tagging how the lexer has interpreted a value literal
18-
#[allow(missing_docs)]
18+
#[expect(missing_docs, reason = "self-explanatory")]
1919
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2020
pub enum ScalarToken<'a> {
2121
String(&'a str),
@@ -24,7 +24,7 @@ pub enum ScalarToken<'a> {
2424
}
2525

2626
/// A single token in the input source
27-
#[allow(missing_docs)]
27+
#[expect(missing_docs, reason = "self-explanatory")]
2828
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2929
pub enum Token<'a> {
3030
Name(&'a str),

0 commit comments

Comments
 (0)