π Enforce consistent relative URL style.
πΌ This rule is enabled in the following configs: β
recommended, π¨ recommended-css, π recommended-html, π recommended-markdown, βοΈ unopinionated.
π§π‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.
Enforce whether relative URLs use a ./ prefix in:
- JavaScript:
new URL(),URL.canParse(), andURL.parse()with two arguments. - CSS:
url(),image-set(), and@importtargets. - HTML and native JSX/TSX elements:
href,src,poster,srcset,imagesrcset,action,formaction, andciteattributes. JSX usessrcSet,imageSrcSet, andformAction. - Markdown: Links, images, reference definitions, and embedded HTML.
Autofixes preserve URL resolution. Under 'never', interpolated JavaScript templates starting with ./ receive suggestions that may change resolution.
JavaScript supports string literals and templates without substitutions. JSX also supports these literals inside braces, except for srcSet/imageSrcSet. Other expressions and custom components are skipped.
Escaped ./ prefixes, templated HTML/CSS URLs, and some complex Markdown or srcset syntax are left unchanged.
// β
const url = new URL('./foo', base);
// β
const url = new URL('foo', base);<!-- β -->
- [`prefer-nesting`](./prefer-nesting.md)
<!-- β
-->
- [`prefer-nesting`](prefer-nesting.md)Type: string
Default: 'never'
'never'(default): Remove a./prefix.'always': Add a./prefix.
'always' includes hidden paths such as .env. Current-directory and parent-directory references are unchanged.
/* eslint unicorn/relative-url-style: ["error", "always"] */
// β
const url = new URL('foo', base);
// β
const url = new URL('./foo', base);