Skip to content

test: add unit tests for SuppressionsService.applySuppressions() - #20863

Merged
mdjermanovic merged 1 commit into
eslint:mainfrom
Kuldeep2822k:test-suppressions-service-remaining
May 12, 2026
Merged

mdjermanovic merged 1 commit into
eslint:mainfrom
Kuldeep2822k:test-suppressions-service-remaining

Conversation

@Kuldeep2822k

Copy link
Copy Markdown
Contributor

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:
Add unit tests for SuppressionsService.applySuppressions().

What changes did you make? (Give an overview)

This is the final follow-up to #20734 (load()), #20765 (suppress()), #20797 (prune()), and #20802 (save()), completing the full unit test coverage of SuppressionsService.

This PR adds unit tests for the applySuppressions() method in lib/services/suppressions-service.js:

Test Case Code Path What It Verifies
Suppress/report threshold violationsCount <= suppressionsCount vs > Messages are correctly suppressed or left as-is based on whether violations exceed the suppression count
Unused suppression tracking violationsCount < suppressionsCount and unmatched rules The unused return value correctly reflects the difference and fully unmatched suppressions
File not in suppressions !suppressions[relativeFilePath] → continue Messages are left untouched when the file has no matching suppressions
Non-mutation guarantee structuredClone(results) The original results array is not modified by the method

Since applySuppressions() is a pure synchronous method, tests call it directly with crafted inputs without needing sinon stubs.

With this PR, all public methods of SuppressionsService now have dedicated test coverage:

Method PR
load() #20734
suppress() #20765
prune() #20797
save() #20802
applySuppressions() This PR

The remaining helper methods (countViolationsByRule, suppressMessagesByRule, getRelativeFilePath) are all exercised indirectly through the tests above.

Is there anything you'd like reviewers to focus on?

The tests cover all branches in the method, including the early continue for unmatched files, the suppress-vs-report threshold, and the structuredClone non-mutation guarantee.

@Kuldeep2822k
Kuldeep2822k requested a review from a team as a code owner May 12, 2026 14:56
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage May 12, 2026
@eslint-github-bot eslint-github-bot Bot added the chore This change is not user-facing label May 12, 2026
@netlify

netlify Bot commented May 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 2b2abbe
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/6a033fa7c41eb9000834ca49

@mdjermanovic mdjermanovic left a comment

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.

LGTM, thanks!

@mdjermanovic
mdjermanovic merged commit d84393d into eslint:main May 12, 2026
43 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Triage to Complete in Triage May 12, 2026
@Kuldeep2822k
Kuldeep2822k deleted the test-suppressions-service-remaining branch May 14, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore This change is not user-facing

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

2 participants