Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ fn trim_leading_zeros(raw: &str) -> &str {
}

fn bigint_literal_from_numeric(raw: &str, base: NumberBase) -> Option<String> {
if raw.contains('e') || raw.contains('E') {
return None;
}

let literal = match base {
NumberBase::Binary | NumberBase::Hex => format!("{raw}n"),
NumberBase::Octal => {
Expand Down Expand Up @@ -220,6 +224,8 @@ fn test() {
r"BigInt(0888)",
r"BigInt(1.0)",
r"BigInt(1e2)",
r"BigInt(1e6)",
r"BigInt(1E6)",
r"BigInt(/* comment */1)",
r"BigInt(9007199254740993)",
r"BigInt(0x20000000000001)",
Expand Down Expand Up @@ -248,6 +254,9 @@ fn test() {
r"BigInt(9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)",
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999n",
),
(r"BigInt(1e2)", r"BigInt(1e2)"),
(r"BigInt(1e6)", r"BigInt(1e6)"),
(r"BigInt(1E6)", r"BigInt(1E6)"),
];

Tester::new(PreferBigintLiterals::NAME, PreferBigintLiterals::PLUGIN, pass, fail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Use a bigint literal (e.g. `123n`) instead of calling `BigInt` with a literal argument.

⚠ eslint-plugin-unicorn(prefer-bigint-literals): Prefer bigint literals over `BigInt(...)`.
╭─[prefer_bigint_literals.tsx:1:8]
1 │ BigInt(1e6)
· ───
╰────
help: Use a bigint literal (e.g. `123n`) instead of calling `BigInt` with a literal argument.

⚠ eslint-plugin-unicorn(prefer-bigint-literals): Prefer bigint literals over `BigInt(...)`.
╭─[prefer_bigint_literals.tsx:1:8]
1 │ BigInt(1E6)
· ───
╰────
help: Use a bigint literal (e.g. `123n`) instead of calling `BigInt` with a literal argument.

⚠ eslint-plugin-unicorn(prefer-bigint-literals): Prefer bigint literals over `BigInt(...)`.
╭─[prefer_bigint_literals.tsx:1:21]
1 │ BigInt(/* comment */1)
Expand Down
Loading