Skip to content

Extend rule GCI530 "no-torch" to detect HTML5 Web API usage#113

Merged
utarwyn merged 7 commits into
green-code-initiative:mainfrom
HuMoreau:530-JS
Jul 16, 2026
Merged

Extend rule GCI530 "no-torch" to detect HTML5 Web API usage#113
utarwyn merged 7 commits into
green-code-initiative:mainfrom
HuMoreau:530-JS

Conversation

@HuMoreau

Copy link
Copy Markdown
Contributor

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

Comment thread eslint-plugin/docs/rules/no-torch.md Outdated
Comment thread eslint-plugin/tests/lib/rules/no-torch.test.js Outdated
Comment thread test-project/src/no-torch.js Outdated
Comment thread test-project/yarn.lock Outdated
@MP-Aubay MP-Aubay moved this from Backlog to In Progress in Hackathon kanban - JS/TS May 20, 2026
@utarwyn
utarwyn force-pushed the 530-JS branch 2 times, most recently from 35dc6ca to 3c45244 Compare July 16, 2026 20:53
utarwyn
utarwyn previously approved these changes Jul 16, 2026
@utarwyn
utarwyn dismissed MP-Aubay’s stale review July 16, 2026 20:54

feedbacks have been pushed

utarwyn
utarwyn previously approved these changes Jul 16, 2026
@utarwyn
utarwyn merged commit 9653388 into green-code-initiative:main Jul 16, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Hackathon kanban - JS/TS Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

Extend the no-torch rule to plain HTML5 Web APIs

4 participants