relative-url-style

March 27, 2026 ยท View on GitHub

๐Ÿ“ Enforce consistent relative URL style.

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

๐Ÿ”ง๐Ÿ’ก This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

When using a relative URL in new URL(), the URL should either never or always use the ./ prefix consistently.

Examples

// โŒ
const url = new URL('./foo', base);

// โœ…
const url = new URL('foo', base);

Options

Type: string
Default: 'never'

  • 'never' (default)
    • Never use a ./ prefix.
  • 'always'
    • Always add a ./ prefix to the relative URL when possible.
/* eslint unicorn/relative-url-style: ["error", "always"] */

// โŒ
const url = new URL('foo', base);

// โœ…
const url = new URL('./foo', base);