Skip to content

Feature/new rule no polling without visibility check#119

Open
mhammed21 wants to merge 2 commits into
green-code-initiative:mainfrom
mhammed21:feature/new-rule-no-polling-without-visibility-check
Open

Feature/new rule no polling without visibility check#119
mhammed21 wants to merge 2 commits into
green-code-initiative:mainfrom
mhammed21:feature/new-rule-no-polling-without-visibility-check

Conversation

@mhammed21

Copy link
Copy Markdown

This PR adds a new ESLint rule no-polling-without-visibility-check (GCI2001) to the creedengo rules specifications.

Problem:
Polling loops using setInterval or recursive setTimeout that run regardless of page visibility waste energy. When a user switches tabs or minimizes the browser, these loops keep firing network requests and executing JavaScript for no reason — consuming CPU, network bandwidth, and battery on mobile devices.

Solution:
The rule detects setInterval and recursive setTimeout calls that are not guarded by a document.addEventListener('visibilitychange', ...) listener. Developers should pause polling when the page is hidden and resume it when visible again.

sonar.sources=src
sonar.projectKey=creedengo-javascript-test-project
sonar.host.url=http://localhost:9000
sonar.token=sqa_31a11e64c69be98c50572f3bcdb3811f0255dfcd

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.

Remove this :)

Comment thread test-project/yarn.lock
peerDependencies:
eslint: ^9.0.0 || ^10.0.0
checksum: 10c0/35357906578cb26b758f44fb8fdb12656de3a6d3297d97002f3a1c755066b81e1321badd1f4a01a9e9d156b0545b5611774c2ed83e80600168c134f0dc0846fd
checksum: 10c0/672076df8ce6a5d9a44bde94b519c8a00eb3082c7e5ea4cc6384fefec7c8d4c8f697dcb5ec58e0b603f4b3f485e4e3b123db711c06cd2957d0853263f0442c1d

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.

yarn.lock does not need to be commited

Comment thread CHANGELOG.md

### Added

- Add rule GCI2001 "Avoid polling without checking page visibility"

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.

Could you add the PR link ?

@@ -0,0 +1,19 @@
// Non compliant: setInterval without visibilitychange listener

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.

Could you add a compliant example here ? Maybe you will need another file to do it ?

@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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants