github / github/codeql

LGTM.com - false positive: "Unused index variable" when using array to set order of execution

Đang mở
#9,242 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
acknowledged false-positive JS
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

**Description of the false positive**

I am creating a button toolbar, and I have an array called `buttonsOrder` that holds the position of each button to be inserted into the toolbar (say `[5,4,2,1,6,3,7]`), where the 1st button will be inserted 5th, the 2nd will be inserted 4th, the 3rd inserted 2nd, etc. The maximum value of each array element is guaranteed to be the same as the length of the array (due to the nature of the data contained), and so to do this I am using the for loop below:

```
for (let i = 1; i <= buttonsOrder.length; i++) {
if (i == buttonsOrder[0]) {
// Insert 1st button
}
if (i == buttonsOrder[1]) {
// Insert 2nd button
}
...
}
```

This ensures the order of the buttons by only executing each index's corresponding code on its respective iteration, however, it is detected by LGTM as not using the index variable (due to me comparing `i` to the _value_ of each index, rather than using `i` _as_ an index). I am not aware of a better way to do what I am trying to do, although if it exists, please excuse my ignorance.

**URL to the alert on the project page on LGTM.com**

https://lgtm.com/projects/g/programmer2514/BetterDiscord-CollapsibleUI/snapshot/768904a74c3558d87e320c9b6618089032d8e627/files/CollapsibleUI.plugin.js?sort=name&dir=ASC&mode=heatmap#xc9cf67112902b80f:1

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.