# radix

> Require the radix argument of `parseInt()`

Without a radix, `parseInt` picks the base from the string, so `parseInt("0x10")` is `16`, while `parseInt("0x10", 10)` is `0`. With input from a user or a file, that's rarely what you want. The second argument says which base you mean.

The rule checks `parseInt` and `Number.parseInt`. It also reports a call without arguments, and a radix that can't work: `undefined`, or a literal that isn't a whole number from 2 to 36.

For a missing radix, the report comes with a suggestion that adds `10`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"radix" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"radix" = ["error", "always"] # "always" or "as-needed"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 4} */}
```js
const page = parseInt(query.page);
const size = Number.parseInt(query.size);
const level = parseInt(input, 1);
const depth = parseInt(input, "10");
```

Not reported:

{/* good */}
```js
const page = parseInt(query.page, 10);
const color = Number.parseInt(hex, 16);
const value = parseInt(input, base);
```

## Options

| Option | What it does |
| --- | --- |
| `"always"` (default) | Require the radix. |
| `"as-needed"` | Has no effect, as in ESLint 10. |

{/* bad {"options": ["as-needed"]} */}
```js
const page = parseInt(query.page);
```

If your project has an ESLint config and ESLint 9 or older installed, `"as-needed"` works like it does there. You can leave the radix out, and a radix of `10` is reported.
