oxc/number-arg-out-of-range Correctness
它的作用
检查数字相关函数的基数或精度参数是否超出限制。
为什么这不好?
Number.prototype.toString 的基数参数应在 2 到 36 之间。 Number.prototype.toFixed 和 Number.prototype.toExponential 的精度参数应在 0 到 20 之间。 Number.prototype.toPrecision 的精度参数应在 1 到 21 之间。
示例
以下是此规则的错误代码示例:
javascript
var x = 42;
var s_radix_64 = x.toString(64);
var s = x.toString(1);以下是此规则的正确代码示例:
javascript
var x = 42;
var s_radix_16 = x.toString(16);如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"oxc/number-arg-out-of-range": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"oxc/number-arg-out-of-range": "error",
},
});bash
oxlint --deny oxc/number-arg-out-of-range版本
此规则添加于 v0.0.3。
