Skip to content

Conversation

@Netail
Copy link
Member

@Netail Netail commented Nov 7, 2025

Summary

Port Typescript Eslint's prefer-regexp-exec

Closes #7797

Test Plan

Docs

@changeset-bot
Copy link

changeset-bot bot commented Nov 7, 2025

🦋 Changeset detected

Latest commit: e102487

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Nov 7, 2025
@Netail Netail force-pushed the feat/use-regexp-exec branch 2 times, most recently from 27349e6 to e0755fc Compare November 7, 2025 22:18
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 7, 2025

CodSpeed Performance Report

Merging #8034 will not alter performance

Comparing Netail:feat/use-regexp-exec (e102487) with main (dc1217c)1

Summary

✅ 53 untouched
⏩ 90 skipped2

Footnotes

  1. No successful run was found on main (c09e45c) during the generation of this report, so dc1217c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 90 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Netail Netail force-pushed the feat/use-regexp-exec branch 2 times, most recently from 9c31558 to b4237d6 Compare November 8, 2025 23:13
@Netail Netail force-pushed the feat/use-regexp-exec branch from e60eac6 to e102487 Compare November 10, 2025 13:44
Comment on lines +75 to +78
AnyJsExpression::JsIdentifierExpression(identifier) => {
// TODO: get static regexp value
return None;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure how how to resolve the value of a reference.

Could also use the type of the expression, then check the flags within the regex type? Not sure if that's valid?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

@Netail Netail Nov 11, 2025

Choose a reason for hiding this comment

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

They seem to call an Eslint API to get the value of a given node if it can be decided statically. (not through types) But not sure if biome provides such API?

https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getstaticvalue

Copy link
Contributor

Choose a reason for hiding this comment

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

We have the semantic model and the control flow graph, but iirc typed rules shouldn't be using those because they use the module graph. @arendjr, I'd appreciate your input here, you have more context on the type system and the module graph than I do.

Copy link
Contributor

Choose a reason for hiding this comment

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

Typed rules can also use the semantic model and the control flow graph, but the semantic model is largely redundant with functionality that is already provided by the typed service, which provides similar things, but with a higher level of abstraction that includes types and cross-module inference.

So far the abstract way of looking at it :)

Unfortunately we don't really have an API yet that can determine static values (AFAIK), but the typed service actually does try to determine static values when it can determine them. Simple example:

const foo = 1;
foo;

The type system will be able to determine that the reference to foo on the second line resolves to the concrete value 1, because in TypeScript concrete values can be used as types as well and we try to infer as specific as we can. So yes, I think using the type system is probably the way to go here, but some more work will be necessary. I don't think we have any specific detection for RegExp yet, and I haven't looked yet into what flags need to be checked, but that might require some custom logic too?

If you like, I might be interested to look into this next week.

Copy link
Member Author

@Netail Netail Nov 12, 2025

Choose a reason for hiding this comment

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

That would be awesome. For now I only need to check on the global flag. But some API to the regexp type could be to check if it has any given flag could be nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Port prefer-regexp-exec from typescript-eslint

3 participants