Skip to content

Commit cd3ab77

Browse files
committed
fix: feedback
1 parent 9ab2f3d commit cd3ab77

File tree

5 files changed

+37
-24
lines changed

5 files changed

+37
-24
lines changed

crates/biome_js_analyze/src/lint/nursery/use_inline_script_id.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use biome_js_syntax::{
77
AnyJsExpression, AnyJsxAttribute, JsObjectExpression, JsVariableDeclarator, JsxElement,
88
jsx_ext::AnyJsxElement,
99
};
10-
use biome_rowan::{AstNode, AstNodeList, TextRange};
10+
use biome_rowan::{AstNode, AstNodeList, TextRange, TokenText};
1111
use biome_rule_options::use_inline_script_id::UseInlineScriptIdOptions;
1212
use rustc_hash::FxHashSet;
1313

@@ -71,8 +71,8 @@ declare_lint_rule! {
7171
name: "useInlineScriptId",
7272
language: "jsx",
7373
sources: &[RuleSource::EslintNext("inline-script-id").same()],
74-
recommended: false,
75-
severity: Severity::Warning,
74+
recommended: true,
75+
severity: Severity::Error,
7676
domains: &[RuleDomain::Next],
7777
}
7878
}
@@ -100,30 +100,32 @@ impl Rule for UseInlineScriptId {
100100
AnyJsxAttribute::JsxAttribute(a) => {
101101
if let Ok(name_value) = a.name_value_token() {
102102
let name = name_value.token_text();
103-
attribute_names.insert(name.to_string());
103+
attribute_names.insert(name);
104104
}
105105
}
106106
AnyJsxAttribute::JsxSpreadAttribute(spread) => {
107-
let argument = spread.argument().ok()?;
108-
match argument {
109-
AnyJsExpression::JsObjectExpression(obj_expr) => {
110-
collect_property_names(&obj_expr, &mut attribute_names)?;
111-
}
112-
AnyJsExpression::JsIdentifierExpression(ident_expr) => {
113-
if let Ok(reference) = ident_expr.name()
114-
&& let Some(binding) = semantic_model.binding(&reference)
115-
&& let Some(declarator) = binding
116-
.syntax()
117-
.ancestors()
118-
.find_map(JsVariableDeclarator::cast)
119-
&& let Some(initializer) = declarator.initializer()
120-
&& let Ok(expression) = initializer.expression()
121-
&& let AnyJsExpression::JsObjectExpression(obj_expr) = expression
122-
{
107+
if let Ok(argument) = spread.argument() {
108+
match argument {
109+
AnyJsExpression::JsObjectExpression(obj_expr) => {
123110
collect_property_names(&obj_expr, &mut attribute_names)?;
124111
}
112+
AnyJsExpression::JsIdentifierExpression(ident_expr) => {
113+
if let Ok(reference) = ident_expr.name()
114+
&& let Some(binding) = semantic_model.binding(&reference)
115+
&& let Some(declarator) = binding
116+
.syntax()
117+
.ancestors()
118+
.find_map(JsVariableDeclarator::cast)
119+
&& let Some(initializer) = declarator.initializer()
120+
&& let Ok(expression) = initializer.expression()
121+
&& let AnyJsExpression::JsObjectExpression(obj_expr) =
122+
expression
123+
{
124+
collect_property_names(&obj_expr, &mut attribute_names)?;
125+
}
126+
}
127+
_ => {}
125128
}
126-
_ => {}
127129
}
128130
}
129131
_ => {}
@@ -151,6 +153,9 @@ impl Rule for UseInlineScriptId {
151153
""<Emphasis>"next/script"</Emphasis>" components with inline content or `dangerouslySetInnerHTML` must specify "<Emphasis>"id"</Emphasis>" attribute."
152154
},
153155
)
156+
.note(markup!(
157+
"Without id attribute, Next.js cannot correctly track inline scripts and this can cause performance issues."
158+
))
154159
.note(markup! {
155160
"See the "<Hyperlink href="https://nextjs.org/docs/messages/inline-script-id">"Next.js docs"</Hyperlink>" for more details."
156161
})
@@ -160,18 +165,18 @@ impl Rule for UseInlineScriptId {
160165

161166
fn collect_property_names(
162167
obj_expr: &JsObjectExpression,
163-
set: &mut FxHashSet<String>,
168+
set: &mut FxHashSet<TokenText>,
164169
) -> Option<()> {
165170
for member in obj_expr.members() {
166171
let member = member.ok()?;
167172
if let Some(property_member) = member.as_js_property_object_member()
168173
&& let Some(name) = property_member.name().ok().and_then(|n| n.name())
169174
{
170-
set.insert(name.to_string());
175+
set.insert(name);
171176
} else if let Some(shorthand) = member.as_js_shorthand_property_object_member()
172177
&& let Some(name) = shorthand.name().ok().and_then(|n| n.name().ok())
173178
{
174-
set.insert(name.to_string());
179+
set.insert(name);
175180
}
176181
}
177182
Some(())

crates/biome_js_analyze/tests/specs/nursery/useInlineScriptId/invalid-01.jsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ invalid-01.jsx:6:5 lint/nursery/useInlineScriptId ━━━━━━━━━━
2828
7 │ )
2929
8}
3030
31+
i Without id attribute, Next.js cannot correctly track inline scripts and this can cause performance issues.
32+
3133
i See the Next.js docs for more details.
3234
3335
i This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

crates/biome_js_analyze/tests/specs/nursery/useInlineScriptId/invalid-02.jsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ invalid-02.jsx:6:5 lint/nursery/useInlineScriptId ━━━━━━━━━━
2828
7 │ )
2929
8}
3030
31+
i Without id attribute, Next.js cannot correctly track inline scripts and this can cause performance issues.
32+
3133
i See the Next.js docs for more details.
3234
3335
i This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

crates/biome_js_analyze/tests/specs/nursery/useInlineScriptId/invalid-03.jsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ invalid-03.jsx:7:5 lint/nursery/useInlineScriptId ━━━━━━━━━━
2929
8 │ )
3030
9 │ }
3131
32+
i Without id attribute, Next.js cannot correctly track inline scripts and this can cause performance issues.
33+
3234
i See the Next.js docs for more details.
3335
3436
i This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

crates/biome_js_analyze/tests/specs/nursery/useInlineScriptId/invalid-04.jsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ invalid-04.jsx:6:5 lint/nursery/useInlineScriptId ━━━━━━━━━━
2828
7 │ )
2929
8}
3030
31+
i Without id attribute, Next.js cannot correctly track inline scripts and this can cause performance issues.
32+
3133
i See the Next.js docs for more details.
3234
3335
i This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

0 commit comments

Comments
 (0)