-
-
Notifications
You must be signed in to change notification settings - Fork 864
fix(lint): detect array index in any position of template string #8947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,13 +150,17 @@ impl Rule for NoArrayIndexKey { | |
| let template_elements = template_expression.elements(); | ||
| for element in template_elements { | ||
| if let AnyJsTemplateElement::JsTemplateElement(template_element) = element { | ||
| let cap_index_value = template_element | ||
| .expression() | ||
| .ok()? | ||
| .as_js_identifier_expression()? | ||
| .name() | ||
| .ok(); | ||
| capture_array_index = cap_index_value; | ||
| // Check if this element is an identifier expression (potential array index) | ||
| if let Some(identifier_expr) = | ||
| template_element.expression().ok()?.as_js_identifier_expression() | ||
| { | ||
| if let Ok(name) = identifier_expr.name() { | ||
| // Found a potential array index reference, use it and stop searching | ||
| // This fixes the issue where index position in template doesn't matter | ||
| capture_array_index = Some(name); | ||
| break; | ||
| } | ||
|
Comment on lines
+153
to
+162
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential regression: template literal now ignores later identifiers Lines 153-162: breaking on the first identifier means 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| } | ||
| } | ||
ematipico marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. snapshots need to be updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit