Extend rule GCI530 "no-torch" to detect HTML5 Web API usage#113
Open
HuMoreau wants to merge 4 commits into
Open
Extend rule GCI530 "no-torch" to detect HTML5 Web API usage#113HuMoreau wants to merge 4 commits into
HuMoreau wants to merge 4 commits into
Conversation
MP-Aubay
requested changes
May 20, 2026
| errors: [expectedError], | ||
| }, | ||
| { | ||
| code: "track.applyConstraints({ advanced: [{ torch: false }] });", |
Contributor
There was a problem hiding this comment.
This test case should be a valid one no ? Activating torch is the problematic one, or the aim is to avoid using torch feature at all ?
@utarwyn any thought on this ?
Author
There was a problem hiding this comment.
After a little thought, to me it should be a compliant test case, waiting for more input
Author
There was a problem hiding this comment.
I'll work on it when I'll have a minute
Member
There was a problem hiding this comment.
@HuMoreau if you have some time to work on it 🤞
thank you !
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.
Summary
Extends the no-torch rule to detect programmatic torch mode enablement via HTML5 MediaTrackConstraints (in addition to the existing React Native react-native-torch detection).
Changes
Rule logic (eslint-plugin/lib/rules/no-torch.js):
Added detection for track.applyConstraints({ advanced: [{ torch: ... }] }) calls
Extracted helper functions to module level for clarity and reusability
Maintains existing React Native torch import detection
Unit tests (eslint-plugin/tests/lib/rules/no-torch.test.js):
Added 3 new invalid cases covering HTML5 Web API usage (torch: true, torch: false, mixed constraints)
Added 3 new valid cases to prevent false positives (no torch, empty advanced, non-torch constraints)
Updated ecmaVersion for consistency with existing tests
Documentation (eslint-plugin/docs/rules/no-torch.md):
Added "React Native" section for existing detection
Added "HTML5 Web API (MediaTrackConstraints)" section with non-compliant and compliant examples
Added MDN reference for MediaTrackConstraints
E2E test (test-project/src/no-torch.js):
Added Web API example function showing both compliant and non-compliant patterns
Organized examples with section comments
Changelog: Updated [Unreleased] section under Changed
Testing
All 19 existing unit tests pass ✅
New tests cover both valid and invalid HTML5 Web API patterns ✅
Code style aligned with project conventions (module-level constants and helpers) ✅
Related
Closes #48