Skip to content

Commit d6bdf4a

Browse files
dyc3autofix-ci[bot]ematipicocoderabbitai[bot]
authored
perf(noMagicNumbers): reduce allocations (#9982)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 7a360dd commit d6bdf4a

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

.changeset/odd-wasps-fly.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Improved performance of [noMagicNumbers](https://biomejs.dev/linter/rules/no-magic-numbers/).
6+
Biome now maps ESLint `no-magic-numbers` sources more accurately during `biome migrate eslint`.

crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_js_analyze/src/lint/style/no_magic_numbers.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ declare_lint_rule! {
5555
version: "2.1.0",
5656
name: "noMagicNumbers",
5757
language: "ts",
58-
sources: &[RuleSource::EslintTypeScript("no-magic-numbers").same()],
58+
sources: &[RuleSource::Eslint("no-magic-numbers").inspired(), RuleSource::EslintTypeScript("no-magic-numbers").same()],
5959
recommended: false,
6060
}
6161
}
@@ -407,5 +407,9 @@ const ALWAYS_IGNORED_IN_ARITHMETIC_OPERATIONS: &[&str] = &[
407407
];
408408

409409
fn is_allowed_number(numeric_literal: &AnyJsNumericLiteral) -> bool {
410-
ALWAYS_IGNORED_IN_ARITHMETIC_OPERATIONS.contains(&numeric_literal.to_trimmed_string().as_str())
410+
match numeric_literal {
411+
AnyJsNumericLiteral::JsNumberLiteralExpression(expr) => expr.value_token(),
412+
AnyJsNumericLiteral::JsBigintLiteralExpression(expr) => expr.value_token(),
413+
}
414+
.is_ok_and(|token| ALWAYS_IGNORED_IN_ARITHMETIC_OPERATIONS.contains(&token.text_trimmed()))
411415
}

0 commit comments

Comments
 (0)