refactor: use Array.includes() instead of indexOf() > -1#8529
Open
dashitongzhi wants to merge 1 commit into
Open
refactor: use Array.includes() instead of indexOf() > -1#8529dashitongzhi wants to merge 1 commit into
dashitongzhi wants to merge 1 commit into
Conversation
Replace legacy indexOf() > -1 pattern with more readable Array.includes() method across multiple files. Also replace map() with forEach() when the return value is not used (side-effect only). Changes: - src/utils/handle-errors.js: map -> forEach for console.log side effects - src/client-functions/selectors/create-snapshot-methods.js: hasClass method - src/client-functions/selectors/add-api.js: filterNodes and expandSelectorResults - src/utils/string.js: splitQuotedText and getConcatenatedValuesString - src/browser/provider/built-in/locally-installed.js: isValidBrowserName - src/client/ui/select-element.js: onWindowClick disabled class check - src/compiler/test-file/formats/typescript/get-test-list.js: replaceComments and getStringValue - src/compiler/test-file/formats/es-next/get-test-list.js: getStringValue - src/compiler/test-file/test-file-parser-base.js: checkExpDefineTargetName This improves code readability and follows modern JavaScript best practices.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors several membership checks to use includes() instead of the legacy indexOf(...) > -1 / < 0 patterns, and replaces a side-effect-only map() with forEach() to better match intent. This aligns with existing codebase usage of includes() and improves readability without changing behavior.
Changes:
- Replaced
indexOf(...) > -1/< 0checks withincludes()/!includes()across client, compiler, browser-provider, and utility code. - Replaced
messages.map(...)withmessages.forEach(...)where the return value was unused. - Minor readability improvements in string/newline checks via
String.prototype.includes.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/string.js | Uses includes() for quote-char and newline detection. |
| src/utils/handle-errors.js | Replaces side-effect-only map() with forEach() for logging. |
| src/compiler/test-file/test-file-parser-base.js | Uses includes() for method-name membership checks. |
| src/compiler/test-file/formats/typescript/get-test-list.js | Uses includes() for newline detection and token-type membership. |
| src/compiler/test-file/formats/es-next/get-test-list.js | Uses includes() for token-type membership. |
| src/client/ui/select-element.js | Uses includes() for disabled-class detection. |
| src/client-functions/selectors/create-snapshot-methods.js | Uses includes() for hasClass on snapshots. |
| src/client-functions/selectors/add-api.js | Uses includes() for node membership and deduplication in selector results. |
| src/browser/provider/built-in/locally-installed.js | Uses includes() to validate local browser names. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replace legacy
indexOf() > -1pattern with more readableArray.includes()method across multiple files. Also replacemap()withforEach()when the return value is not used (side-effect only).Changes Made
src/utils/handle-errors.js: Changedmap()toforEach()forconsole.logside effectssrc/client-functions/selectors/create-snapshot-methods.js:hasClassmethod now usesincludes()src/client-functions/selectors/add-api.js:filterNodesandexpandSelectorResultsnow useincludes()src/utils/string.js:splitQuotedTextandgetConcatenatedValuesStringnow useincludes()src/browser/provider/built-in/locally-installed.js:isValidBrowserNamenow usesincludes()src/client/ui/select-element.js:onWindowClickdisabled class check now usesincludes()src/compiler/test-file/formats/typescript/get-test-list.js:replaceCommentsandgetStringValuenow useincludes()src/compiler/test-file/formats/es-next/get-test-list.js:getStringValuenow usesincludes()src/compiler/test-file/test-file-parser-base.js:checkExpDefineTargetNamenow usesincludes()Benefits
includes()is more semantic and self-documenting thanindexOf() > -1forEach()instead ofmap()when return value is not used makes intent clearer and avoids confusionTotal: 9 files changed, 12 insertions(+), 12 deletions(-)