Skip to content
← Back to rules

unicorn/no-zero-fractions Style

🛠️ An auto-fix is available for this rule.

它的作用

防止使用零小数部分。

这为什么不好?

例如,在 JavaScript 中,11.01. 之间没有区别,因此为了保持一致性和简洁性,建议优先使用前者。

示例

以下是此规则的错误代码示例:

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 中加入。

参考资料