Skip to content

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

Open
HuMoreau wants to merge 4 commits into
green-code-initiative:mainfrom
HuMoreau:530-JS
Open

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

Conversation

@HuMoreau

Copy link
Copy Markdown

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
errors: [expectedError],
},
{
code: "track.applyConstraints({ advanced: [{ torch: false }] });",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a little thought, to me it should be a compliant test case, waiting for more input

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this should be valid 👍

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll work on it when I'll have a minute

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HuMoreau if you have some time to work on it 🤞
thank you !

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Extend the no-torch rule to plain HTML5 Web APIs

4 participants