atlassian / better-ajv-errors

JSON Schema validation for Human 👨‍🎤
https://atlassian.github.io/better-ajv-errors/
Other
232 stars 44 forks source link

refactor: use map instead of for/in loop #135

Closed tylermarien closed 2 years ago

tylermarien commented 2 years ago

Using a for...in loop on an array is prone to errors because it loops over all enumerable properties (including functions). If another library adds a function to the Array prototype, then this breaks because it will include that function. This was happening in our case. Another library was modifying the Array prototype and causing errors in this code.

We could fix the problem by replacing the for...in loop with a for...of loop, but map is probably a better solution here since we are modifying every element in the array. I have changed the for...in loop to a map.

Difference between for...of and for...in

changeset-bot[bot] commented 2 years ago

🦋 Changeset detected

Latest commit: f06f9a5b78099aea7e33c693db741f45bee5c24d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ----------------- | ----- | | better-ajv-errors | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

atlassian-cla-bot[bot] commented 2 years ago

Hooray! All contributors have signed the CLA.

torifat commented 2 years ago

Thank you 🙏🏽