Skip to content

Commit 157518d

Browse files
committed
fix: feedback v2
1 parent fa38812 commit 157518d

File tree

18 files changed

+71
-51
lines changed

18 files changed

+71
-51
lines changed

crates/biome_graphql_analyze/src/lint/nursery/use_input_name.rs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use biome_graphql_syntax::{
88
GraphqlSyntaxToken,
99
};
1010
use biome_rowan::{AstNode, TextRange};
11-
use biome_rule_options::use_input_name::UseInputNameOptions;
11+
use biome_rule_options::use_input_name::{CheckInputType, UseInputNameOptions};
1212

1313
declare_lint_rule! {
1414
/// Require mutation argument to be always called "input"
@@ -37,15 +37,16 @@ declare_lint_rule! {
3737
///
3838
/// ### `checkInputType`
3939
///
40-
/// When the option `checkInputType` is enabled, the input type requires to be called `<mutation name>Input`.
40+
/// With the option `checkInputType` on, the input type name requires to be called `<mutation name>Input`.
41+
/// This can either be "loose" (case-insensitive) or "strict" (case-sensitive).
4142
/// Using the name of the mutation in the input type name will make it easier to find the mutation that the input type belongs to.
4243
///
43-
/// Default `false`
44+
/// Default `"off"`
4445
///
4546
/// ```json,options
4647
/// {
4748
/// "options": {
48-
/// "checkInputType": true
49+
/// "checkInputType": "loose"
4950
/// }
5051
/// }
5152
/// ```
@@ -56,27 +57,45 @@ declare_lint_rule! {
5657
/// }
5758
/// ```
5859
///
59-
/// ### `caseSensitiveInputType`
60+
/// ```graphql,use_options
61+
/// type Mutation {
62+
/// SetMessage(input: setMessageInput): String
63+
/// }
64+
/// ```
6065
///
61-
/// Treat input type names as case-sensitive.
66+
/// ```graphql,use_options
67+
/// type Mutation {
68+
/// SetMessage(input: SetMessageInput): String
69+
/// }
70+
/// ```
6271
///
63-
/// Default `true`
6472
///
6573
/// ```json,options
6674
/// {
6775
/// "options": {
68-
/// "checkInputType": true,
69-
/// "caseSensitiveInputType": false
76+
/// "checkInputType": "strict"
7077
/// }
7178
/// }
7279
/// ```
7380
///
74-
/// ```graphql,use_options
81+
/// ```graphql,expect_diagnostic,use_options
82+
/// type Mutation {
83+
/// SetMessage(input: InputMessage): String
84+
/// }
85+
/// ```
86+
///
87+
/// ```graphql,expect_diagnostic,use_options
7588
/// type Mutation {
7689
/// SetMessage(input: setMessageInput): String
7790
/// }
7891
/// ```
7992
///
93+
/// ```graphql,use_options
94+
/// type Mutation {
95+
/// SetMessage(input: SetMessageInput): String
96+
/// }
97+
/// ```
98+
///
8099
pub UseInputName {
81100
version: "next",
82101
name: "useInputName",
@@ -131,10 +150,10 @@ impl Rule for UseInputName {
131150
));
132151
}
133152

134-
let check_input_type = ctx.options().check_input_type();
135-
if check_input_type {
136-
let is_case_sensitive_input_type = ctx.options().case_sensitive_input_type();
137-
153+
let check_input_type = ctx.options().check_input_type;
154+
if let Some(check_input_type) = check_input_type
155+
&& check_input_type != CheckInputType::Off
156+
{
138157
let any_type = argument.ty().ok()?;
139158

140159
let ty = find_input_type(any_type)?;
@@ -144,8 +163,8 @@ impl Rule for UseInputName {
144163
let def_value_token = def_name.value_token().ok()?;
145164

146165
let valid_str = format!("{}Input", def_value_token.text_trimmed());
147-
if (is_case_sensitive_input_type && ty_string != valid_str)
148-
|| (!is_case_sensitive_input_type
166+
if (check_input_type == CheckInputType::Strict && ty_string != valid_str)
167+
|| (check_input_type == CheckInputType::Loose
149168
&& !ty_string.eq_ignore_ascii_case(&valid_str))
150169
{
151170
return Some(UseInputNameState::InvalidTypeName(

crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-sensitive-input-type/invalid.graphql renamed to crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-insensitive/invalid.graphql

File renamed without changes.

crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-sensitive-input-type/invalid.graphql.snap renamed to crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-insensitive/invalid.graphql.snap

File renamed without changes.

crates/biome_graphql_analyze/tests/specs/nursery/useInputName/check-input-type/invalid.options.json renamed to crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-insensitive/invalid.options.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"useInputName": {
77
"level": "error",
88
"options": {
9-
"checkInputType": true,
10-
"caseSensitiveInputType": true
9+
"checkInputType": "loose"
1110
}
1211
}
1312
}

crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-sensitive-input-type/valid.graphql renamed to crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-insensitive/valid.graphql

File renamed without changes.

crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-sensitive-input-type/valid.graphql.snap renamed to crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-insensitive/valid.graphql.snap

File renamed without changes.

crates/biome_graphql_analyze/tests/specs/nursery/useInputName/check-input-type/valid.options.json renamed to crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-insensitive/valid.options.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"useInputName": {
77
"level": "error",
88
"options": {
9-
"checkInputType": true,
10-
"caseSensitiveInputType": true
9+
"checkInputType": "loose"
1110
}
1211
}
1312
}

crates/biome_graphql_analyze/tests/specs/nursery/useInputName/check-input-type/invalid.graphql renamed to crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-sensitive/invalid.graphql

File renamed without changes.

crates/biome_graphql_analyze/tests/specs/nursery/useInputName/check-input-type/invalid.graphql.snap renamed to crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-sensitive/invalid.graphql.snap

File renamed without changes.

crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-sensitive-input-type/invalid.options.json renamed to crates/biome_graphql_analyze/tests/specs/nursery/useInputName/case-sensitive/invalid.options.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"useInputName": {
77
"level": "error",
88
"options": {
9-
"checkInputType": true,
10-
"caseSensitiveInputType": false
9+
"checkInputType": "strict"
1110
}
1211
}
1312
}

0 commit comments

Comments
 (0)