unicorn/no-zero-fractions Style
它的作用
防止使用零小数部分。
这为什么不好?
例如,在 JavaScript 中,1、1.0 和 1. 之间没有区别,因此为了保持一致性和简洁性,建议优先使用前者。
示例
以下是此规则的错误代码示例:
javascript
const foo = 1.0;
const foo = -1.0;
const foo = 123_456.000_000;以下是此规则的正确代码示例:
javascript
const foo = 1;
const foo = -1;
const foo = 123456;
const foo = 1.1;如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/no-zero-fractions": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"unicorn/no-zero-fractions": "error",
},
});bash
oxlint --deny unicorn/no-zero-fractions版本
此规则在 v0.0.18 中加入。
