Fix tab_size validation to fall back to default indentation#228
Merged
Conversation
The guard checked Number(tab_size) < 1, but the raw tab_size value was used directly in the indentation math (SPACE.repeat(tab_size * size)). A non-numeric tab_size (e.g. a JS caller passing a string, bypassing the TS type) coerced to NaN, which passed the old guard (NaN < 1 is false) and silently produced zero-indented output instead of throwing. Fractional values were silently truncated by String.prototype.repeat. Now tab_size is coerced once and validated as a finite integer >= 1; non-numeric, fractional, NaN and Infinity values all throw.
Contributor
|
| 📦 Package | 📋 Versions |
|---|---|
| @babel/parser | 2 versions
|
| @babel/types | 2 versions
|
| @babel/helper-string-parser | 2 versions
|
| @babel/helper-validator-identifier | 2 versions
|
| @rolldown/binding-wasm32-wasi | 2 versions
|
| picomatch | 2 versions
|
| rolldown | 2 versions
|
| @oxc-project/types | 2 versions
|
| @rolldown/binding-android-arm64 | 2 versions
|
| @rolldown/binding-darwin-arm64 | 2 versions
|
| @rolldown/binding-darwin-x64 | 2 versions
|
| @rolldown/binding-freebsd-x64 | 2 versions
|
| @rolldown/binding-linux-arm-gnueabihf | 2 versions
|
| @rolldown/binding-linux-arm64-gnu | 2 versions
|
| @rolldown/binding-linux-arm64-musl | 2 versions
|
| @rolldown/binding-linux-ppc64-gnu | 2 versions
|
| @rolldown/binding-linux-s390x-gnu | 2 versions
|
| @rolldown/binding-linux-x64-gnu | 2 versions
|
| @rolldown/binding-linux-x64-musl | 2 versions
|
| @rolldown/binding-openharmony-arm64 | 2 versions
|
| @rolldown/binding-win32-arm64-msvc | 2 versions
|
| @rolldown/binding-win32-x64-msvc | 2 versions
|
💡 To find out what depends on a specific package, run: pnpm -r why example-package
📦 Package Bundle Size
No bundle size changes.
…rowing An invalid tab_size (0, negative, fractional, NaN, Infinity, or a non-numeric value from a JS caller bypassing the TS type) is now silently ignored, falling back to the default tab indentation, rather than throwing a TypeError.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tab_sizeguard checkedNumber(tab_size) < 1, but the rawtab_sizevalue (not the coerced number) was used later inSPACE.repeat(tab_size * size).tab_size(a JS caller bypassing the TS type, e.g. a value read from user config) coerced toNaN, which passed the old guard (NaN < 1isfalse) and silently produced zero-indented output instead of falling back sensibly.tab_sizevalues were silently truncated byString.prototype.repeatinstead of being normalized.tab_sizeis now coerced once; any invalid value (non-numeric, fractional,NaN,Infinity,< 1) is silently ignored and the default tab indentation is used instead. This does not throw — it's a fix, not a breaking change.Test plan
vitest run— all 259 tests pass (added cases for fractional/NaN/Infinity/non-numerictab_size, each asserting fallback to default indentation and that no error is thrown)tsc --noEmit— no type errorsoxlint/oxfmt --check— clean