Skip to content
← Back to rules

unicorn/relative-url-style Style

🛠️ 💡 An auto-fix and a suggestion are available for this rule.

它的作用

强制使用一致的相对 URL 风格。

为什么这不好?

new URL() 中使用相对 URL 时,URL 应该始终使用 ./ 前缀,或者始终不使用,且保持一致。

示例

以下是此规则在默认 "never" 选项下的错误代码示例:

js
new URL("./foo", base);

以下是此规则在默认 "never" 选项下的正确代码示例:

js
new URL("foo", base);

以下是此规则在 "always" 选项下的错误代码示例:

js
new URL("foo", base);

以下是此规则在 "always" 选项下的正确代码示例:

js
new URL("./foo", base);

配置

此规则接受以下字符串值之一:

"never"

绝不使用 ./ 前缀。

"always"

在可能的情况下,总是为相对 URL 添加 ./ 前缀。

如何使用

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

json
{
  "rules": {
    "unicorn/relative-url-style": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/relative-url-style": "error",
  },
});
bash
oxlint --deny unicorn/relative-url-style

版本

此规则已在 v1.44.0 中添加。

参考资料