@@ -25,7 +25,7 @@ declare_lint_rule! {
2525 ///
2626 /// ### Invalid
2727 ///
28- /// ```js ,expect_diagnostic
28+ /// ```jsx ,expect_diagnostic
2929 /// import Script from 'next/script'
3030 ///
3131 /// export default function Page() {
@@ -35,7 +35,7 @@ declare_lint_rule! {
3535 /// }
3636 /// ```
3737 ///
38- /// ```js ,expect_diagnostic
38+ /// ```jsx ,expect_diagnostic
3939 /// import Script from 'next/script'
4040 ///
4141 /// export default function Page() {
@@ -46,7 +46,7 @@ declare_lint_rule! {
4646 /// ```
4747 ///
4848 /// ### Valid
49- /// ```js
49+ /// ```jsx
5050 /// import Script from 'next/script'
5151 ///
5252 /// export default function Page() {
@@ -56,7 +56,7 @@ declare_lint_rule! {
5656 /// }
5757 /// ```
5858 ///
59- /// ```js
59+ /// ```jsx
6060 /// import Script from 'next/script'
6161 ///
6262 /// export default function Page() {
@@ -107,7 +107,6 @@ impl Rule for UseInlineScriptId {
107107 match argument {
108108 AnyJsExpression :: JsObjectExpression ( obj_expr) => {
109109 collect_property_names ( & obj_expr, & mut attribute_names) ?;
110- continue ;
111110 }
112111 AnyJsExpression :: JsIdentifierExpression ( ident_expr) => {
113112 let reference = ident_expr. name ( ) . ok ( ) ?;
@@ -121,25 +120,24 @@ impl Rule for UseInlineScriptId {
121120 if let AnyJsExpression :: JsObjectExpression ( obj_expr) = expression {
122121 collect_property_names ( & obj_expr, & mut attribute_names) ?;
123122 }
124- continue ;
125- }
126- _ => {
127- continue ;
128123 }
124+ _ => { }
129125 }
130126 }
131- _ => continue ,
127+ _ => { }
132128 }
133129 }
134130
135- let has_children = !jsx_element. parent :: < JsxElement > ( ) ?. children ( ) . is_empty ( ) ;
136- if has_children || attribute_names. contains ( "dangerouslySetInnerHTML" ) {
137- if !attribute_names. contains ( "id" ) {
138- return Some ( jsx_element. syntax ( ) . text_range_with_trivia ( ) ) ;
139- }
131+ let has_children = jsx_element
132+ . parent :: < JsxElement > ( )
133+ . is_some_and ( |parent| !parent. children ( ) . is_empty ( ) ) ;
134+ if ( has_children || attribute_names. contains ( "dangerouslySetInnerHTML" ) )
135+ && !attribute_names. contains ( "id" )
136+ {
137+ return Some ( jsx_element. syntax ( ) . text_range_with_trivia ( ) ) ;
140138 }
141139
142- return None ;
140+ None
143141 }
144142
145143 fn diagnostic ( ctx : & RuleContext < Self > , _state : & Self :: State ) -> Option < RuleDiagnostic > {
@@ -165,9 +163,15 @@ fn collect_property_names(
165163) -> Option < ( ) > {
166164 for member in obj_expr. members ( ) {
167165 let member = member. ok ( ) ?;
168- let property_member = member. as_js_property_object_member ( ) ?;
169- let name = property_member. name ( ) . ok ( ) ?. name ( ) ?;
170- set. insert ( name. to_string ( ) ) ;
166+ if let Some ( property_member) = member. as_js_property_object_member ( )
167+ && let Some ( name) = property_member. name ( ) . ok ( ) . and_then ( |n| n. name ( ) )
168+ {
169+ set. insert ( name. to_string ( ) ) ;
170+ } else if let Some ( shorthand) = member. as_js_shorthand_property_object_member ( )
171+ && let Some ( name) = shorthand. name ( ) . ok ( ) . and_then ( |n| n. name ( ) . ok ( ) )
172+ {
173+ set. insert ( name. to_string ( ) ) ;
174+ }
171175 }
172176 Some ( ( ) )
173177}
0 commit comments