Skip to content

Commit

Permalink
update rule description
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasweng committed May 21, 2024
1 parent a1e3258 commit 7740b79
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/biome_configuration/src/linter/rules.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion crates/biome_js_analyze/src/lint/nursery/use_top_level_regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ use biome_rowan::{AstNode, AstNodeList};
use crate::services::control_flow::AnyJsControlFlowRoot;

declare_rule! {
/// Require all regex literals to be declared at the top level.
/// Require regex literals to be declared at the top level.
///
/// This rule is useful to avoid performance issues when using regex literals inside functions called many times (hot paths). Regex literals create a new RegExp object when they are evaluated. (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) By declaring them at the top level, this overhead can be avoided.
///
/// It's important to note that this rule is not recommended for all cases. Placing regex literals at the top level can hurt startup times. In browser contexts, this can result in longer page loads.
///
/// Additionally, this rule ignores regular expressions with the `g` and/or `y` flags, as they maintain internal state and can cause
/// [side effects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex#avoiding_side_effects) when calling `test` and `exec` with them.
///
/// ## Examples
///
/// ### Invalid
Expand All @@ -32,6 +35,12 @@ declare_rule! {
/// }
/// ```
///
/// ```js
/// function foo(str) {
/// return /[a-Z]*/g.exec(str)
/// }
/// ```
///
pub UseTopLevelRegex {
version: "next",
name: "useTopLevelRegex",
Expand Down
2 changes: 1 addition & 1 deletion packages/@biomejs/backend-jsonrpc/src/workspace.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@biomejs/biome/configuration_schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7740b79

Please sign in to comment.