Skip to content
← Back to rules

unicorn/no-length-as-slice-end Restriction

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

它的作用

禁止将 length 作为 slice 调用的结束参数。

为什么这不好?

length 作为 slice 调用的结束参数是多余的,而且可能会让人困惑。

示例

此规则的错误代码示例:

javascript
foo.slice(1, foo.length);

此规则的正确代码示例:

javascript
foo.slice(1);

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/no-length-as-slice-end": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/no-length-as-slice-end": "error",
  },
});
bash
oxlint --deny unicorn/no-length-as-slice-end

版本

此规则在 v0.7.0 中加入。

参考资料