Skip to content

refactor: SafeEmitter -> SourceCodeVisitor #19708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 4, 2025
Merged

Conversation

nzakas
Copy link
Member

@nzakas nzakas commented May 7, 2025

Prerequisites checklist

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
[x] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

This further refactors the traversal logic, moving it closer to being able to support asynchronous rules.

  • Replaced SafeEmitter with SourceCodeVisitor. This is a more accurate representation of what we want to happen (for a given name, retrieve functions to execute) vs. emitting events with multiple listeners. This will also make it easier to implement async rules in the future.
  • Updated SourceCodeTraverser so that traverseSync() is responsible for calling functions instead of ESQueryHelper.
  • Updated ESQueryHelper to only match and return selectors instead of emitting events.

Depends on #19679

Refs #18787

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

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage May 7, 2025
@eslint-github-bot eslint-github-bot bot added the chore This change is not user-facing label May 7, 2025
@github-actions github-actions bot added the core Relates to ESLint's core APIs and features label May 7, 2025
Copy link

netlify bot commented May 7, 2025

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 4306efe
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/684067fddb55ac00080d0702

@nzakas nzakas force-pushed the sourcecode-visitor branch from ec670bc to 4acbab9 Compare May 27, 2025 15:12
@nzakas nzakas marked this pull request as ready for review May 27, 2025 15:28
@nzakas nzakas requested a review from a team as a code owner May 27, 2025 15:28
@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jun 2, 2025
@mdjermanovic mdjermanovic moved this from Needs Triage to Implementing in Triage Jun 2, 2025
Comment on lines 199 to 202
const isAnyTypeSelectorMoreSpecific =
hasMoreAnyTypeSelectors &&
hasMoreNodeTypeSelectors &&
anyTypeSelector.compare(nodeTypeSelector) < 0;
Copy link
Member

Choose a reason for hiding this comment

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

I believe this should be isAnyTypeSelectorLessSpecific, not More.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I've found this specificity concept difficult to wrap my brain around. In CSS, higher specificity takes priority but here lower specificity does.

@nzakas nzakas force-pushed the sourcecode-visitor branch from a3ce474 to 586c617 Compare June 3, 2025 20:32
nzakas and others added 2 commits June 4, 2025 11:29
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Copy link
Member

@mdjermanovic mdjermanovic left a comment

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 7abe42e into main Jun 4, 2025
30 checks passed
@mdjermanovic mdjermanovic deleted the sourcecode-visitor branch June 4, 2025 17:37
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion chore This change is not user-facing core Relates to ESLint's core APIs and features
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy