CesiumGS / CesiumGS/cesium

Investigate why guard-for-in doesn't work for all cases

Open
#8,100 0 comments 0 reactions 0 assignees View on GitHub
category - packaging & tooling
Dominant language
JavaScript
Stars
15.7k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

We have the eslint rule

```js
'guard-for-in': 'error'
```

but it doesn't error on cases like

```js
for (var subMaterialId in materials) {
if (shaderComponent.indexOf(subMaterialId) > -1) {
return true;
}
}
```

which should actually look like:

```js
var materials = material._template.materials;
for (var subMaterialId in materials) {
if (materials.hasOwnProperty(subMaterialId)) {
if (shaderComponent.indexOf(subMaterialId) > -1) {
return true;
}
}
}
```

It seems like [`guard-for-in`](https://eslint.org/docs/rules/guard-for-in) is happy as long as there's an if statement after the for loop but it doesn't actually check with whether `hasOwnProperty` is called.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the two JavaScript examples with the `guard-for-in` rule and read the linked rule documentation. Compare the rule's accepted `if` statement with the required `hasOwnProperty` guard; done means identifying why the case is accepted and documenting the needed scope of the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.