Skip to content

chore(eslint-plugin): require underscore-delimited groups in numeric literals#3263

Merged
kriskowal merged 4 commits into
masterfrom
kriskowal-eslint-numeric-separators-style
Jun 6, 2026
Merged

chore(eslint-plugin): require underscore-delimited groups in numeric literals#3263
kriskowal merged 4 commits into
masterfrom
kriskowal-eslint-numeric-separators-style

Conversation

@kriskowal

Copy link
Copy Markdown
Member

Description

Adds eslint-plugin-unicorn's numeric-separators-style rule to the @endo/internal ESLint preset, enforcing underscore-delimited groupings on numeric literals. Decimal numbers of five or more digits group every three digits (1_234_567); hexadecimal, binary, and octal literals group by the rule's conventional widths (hex in twos, binary and octal in fours). The rule is autofixable, so eslint --fix applied the migration across the codebase in a separate commit. A final commit reflows seven autofix-touched files that Prettier wanted to re-wrap once the separators pushed a few expressions past the print-width threshold.

Security Considerations

None. Numeric separators are a syntactic transformation that does not change the runtime value of any literal.

Scaling Considerations

None.

Documentation Considerations

The @endo/eslint-plugin changeset notes that consumers of plugin:@endo/internal will see lint errors on numeric literals that violate the rule and must add eslint-plugin-unicorn to their devDependencies to satisfy the new peer dependency. eslint --fix rewrites violations automatically, so the migration cost downstream is one autofix run per consumer.

Testing Considerations

yarn lint is the test surface. The pre-PR run on this branch reports zero ESLint errors and zero Prettier warnings on the files this migration touches. Two pre-existing ESLint warnings on master remain unaddressed (in evasive-transform/src/index.js and ses/src/compartment.js); they predate this change and are out of scope here.

Compatibility Considerations

The rule strips separators from decimal literals below the minimum-digits threshold (1_000 becomes 1000). This matches the rule's defaults and is consistent with the convention that separators communicate magnitude only when the number is long enough to benefit from grouping.

Upgrade Considerations

None for production systems. Downstream consumers of @endo/eslint-plugin will need to install eslint-plugin-unicorn@^56.0.1 (a new peer dependency of the plugin); the published changeset describes the requirement.

@changeset-bot

changeset-bot Bot commented May 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 44f4d1b

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

This PR includes changesets to release 1 package
Name Type
@endo/eslint-plugin Minor

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

@kriskowal kriskowal requested review from kumavis and turadg May 15, 2026 01:52
@kriskowal kriskowal marked this pull request as ready for review May 15, 2026 01:54
@kriskowal kriskowal force-pushed the kriskowal-eslint-numeric-separators-style branch from b583f92 to 512438a Compare May 15, 2026 04:33

@turadg turadg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not opposed to the rule but I think the config needs adjusting. Consider omitting the rule for test files and removing the hex requirement

Comment thread packages/bundle-source/cache.js Outdated

if (nonce === undefined) {
nonce = crypto.randomInt(0xffff_ffff);
nonce = crypto.randomInt(0xff_ff_ff_ff);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I find the pairs harder to read that quadruplets. Consider groups of four.

Comment thread packages/cjs-module-analyzer/index.js Outdated
if (code < 97) return code === 95;
if (code < 123) return true;
if (code <= 0xffff)
if (code <= 0xff_ff)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another case in point of four-segment reading better

withInterrupt(async ({ cancelled }) => {
await null;
const logCheckIntervalMs = ping !== undefined ? Number(ping) : 5_000;
const logCheckIntervalMs = ping !== undefined ? Number(ping) : 5000;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why prefer no underscore for thousands?

Comment thread packages/cli/test/number-parse.test.js Outdated
t.is(
parseBigint('123456789012345678901234567890'),
123456789012345678901234567890n,
123_456_789_012_345_678_901_234_567_890n,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is worse. The reader wants to verify the numeral sequence matches the above. Consider suppressing the rule on this file

Comment thread packages/hex/test/decode.bench.js Outdated
// Deterministic PRNG, same seed shape as other Endo fuzz tests.
const defaultSeed = [0xb0b5c0ff, 0xeefacade, 0xb0b5c0ff, 0xeefacade];
const defaultSeed = [
0xb0_b5_c0_ff, 0xee_fa_ca_de, 0xb0_b5_c0_ff, 0xee_fa_ca_de,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These visually break the mnemonic. Please suppress this line or file

Comment thread packages/hex/test/encode.bench.js Outdated
// Deterministic PRNG, same seed shape as other Endo fuzz tests.
const defaultSeed = [0xb0b5c0ff, 0xeefacade, 0xb0b5c0ff, 0xeefacade];
const defaultSeed = [
0xb0_b5_c0_ff, 0xee_fa_ca_de, 0xb0_b5_c0_ff, 0xee_fa_ca_de,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto re mnemonic

Comment thread packages/marshal/src/encodePassable.js Outdated
let bits = BigInt(`0x${getSuffix(encoded, skip + 1)}`);
if (encoded.charAt(skip + 1) < '8') {
bits ^= 0xffffffffffffffffn;
bits ^= 0xff_ff_ff_ff_ff_ff_ff_ffn;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's salient here is the length and this is harder to count than groups of four.

Comment on lines -118 to 119
[9007199254740993n, { '@qclass': 'bigint', digits: '9007199254740993' }],
[9_007_199_254_740_993n, { '@qclass': 'bigint', digits: '9007199254740993' }],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto the comparison point

Comment thread packages/ocapn/src/syrup/encode.js Outdated
// See https://github.com/ocapn/ocapn/blob/main/draft-specifications/Model.md#string
const INVALID_STRING_CHARS_START = 0xd800;
const INVALID_STRING_CHARS_END = 0xdfff;
const INVALID_STRING_CHARS_START = 0xd8_00;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another case for fours: the comment above is in fours. The literal should match

@kriscendobot

Copy link
Copy Markdown

Mirror of endojs/endo-but-for-bots#244 (head 512438a).

kriskowal pushed a commit to kriskowal/garden that referenced this pull request May 29, 2026
@kriskowal kriskowal force-pushed the kriskowal-eslint-numeric-separators-style branch from 512438a to 46de187 Compare May 29, 2026 20:45
kriskowal pushed a commit to kriskowal/garden that referenced this pull request May 29, 2026
… recompute, CONFLICTING→MERGEABLE); message: boatman → steward upstream cross-link
kriskowal pushed a commit to kriskowal/garden that referenced this pull request May 29, 2026
…endo#3263 (force-push; CONFLICTING->MERGEABLE; numeric-separators)
@kriskowal kriskowal force-pushed the kriskowal-eslint-numeric-separators-style branch from 46de187 to 4d039c3 Compare May 29, 2026 20:54
@kriskowal kriskowal enabled auto-merge May 29, 2026 20:55
kriskowal pushed a commit to kriskowal/garden that referenced this pull request Jun 3, 2026
@kriskowal kriskowal force-pushed the kriskowal-eslint-numeric-separators-style branch from 4d039c3 to eef8f2f Compare June 3, 2026 05:59
@kriskowal kriskowal requested a review from turadg June 4, 2026 05:21
@kriskowal kriskowal disabled auto-merge June 4, 2026 05:22
kriskowal pushed a commit to kriskowal/garden that referenced this pull request Jun 4, 2026
@kriskowal kriskowal force-pushed the kriskowal-eslint-numeric-separators-style branch from eef8f2f to 0e861ff Compare June 4, 2026 05:35
kriskowal pushed a commit to kriskowal/garden that referenced this pull request Jun 4, 2026
…d bots#244 (content unchanged; MERGEABLE)
Comment on lines +48 to +54
{
onlyIfContainsSeparator: false,
number: { minimumDigits: 5, groupLength: 3 },
binary: { minimumDigits: 0, groupLength: 4 },
octal: { minimumDigits: 0, groupLength: 4 },
hexadecimal: { minimumDigits: 0, groupLength: 4 },
},

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@turadg The bulk of your feedback is addressed here, and with some one-off exceptions where the rules are disabled to make other representations more obviously equivalent.

Comment thread packages/ses/src/compartment.js Outdated
*/
/** @this {Compartment} */
/**
* @param {...any} args

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

driveby but no objection

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you for catching this.

@kriskowal kriskowal force-pushed the kriskowal-eslint-numeric-separators-style branch from 0e861ff to 44f4d1b Compare June 6, 2026 04:01
@kriskowal kriskowal enabled auto-merge June 6, 2026 04:02
@kriskowal kriskowal merged commit 5865ff1 into master Jun 6, 2026
16 of 17 checks passed
@kriskowal kriskowal deleted the kriskowal-eslint-numeric-separators-style branch June 6, 2026 04:05
@kriskowal kriskowal mentioned this pull request Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants