oxc-project/oxc · warning · OxcDiagnostic
Add a `./` prefix to the relative URL.
Error message
Add a `./` prefix to the relative URL.
What it means
This is the `always` diagnostic of oxlint's `unicorn/relative-url-style` rule. When the rule is configured with `"always"`, it flips direction and flags relative URL strings that lack the `./` prefix — `new URL('foo', base)` — asking you to add `./` so the value visually announces itself as relative rather than absolute-ish.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/relative_url_style.rs:24
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use url::Url;
use crate::{
AstNode,
ast_util::is_new_expression,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn never_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Remove the `./` prefix from the relative URL.").with_label(span)
}
fn always_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Add a `./` prefix to the relative URL.").with_label(span)
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "kebab-case")]
pub enum RelativeUrlStyleConfig {
#[default]
/// Never use a `./` prefix.
Never,
/// Always add a `./` prefix to the relative URL when possible.
Always,
}
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
pub struct RelativeUrlStyle(RelativeUrlStyleConfig);
declare_oxc_lint!(
/// ### What it does
///View on GitHub (pinned to e1e7af627c)
Solutions
- Add the prefix: `new URL('./foo', base)`.
- If the mass of warnings is unwanted, revert config to the default `"never"` (or disable the rule) in `.oxlintrc.json`.
- Run `oxlint --fix` under the `always` config to add prefixes in bulk.
Example fix
// before
const u = new URL('api/v1/users', baseUrl);
// after
const u = new URL('./api/v1/users', baseUrl); Defensive patterns
Strategy: validation
Validate before calling
// Same rule, opposite config: make the prefix mandatory
// .oxlintrc.json:
// "unicorn/relative-url-style": ["error", "always"]
const u = new URL('./api/v1/users', baseUrl); Prevention
- If you switch the rule to `always`, run `oxlint --fix` once to normalize existing literals.
- Expect the opposite diagnostic whenever config flips — the message text tells you which mode is active.
- Keep the choice documented in the repo's lint README so new contributors do not 'fix' it back.
When it happens
Trigger: A string-literal first argument to `new URL('path', base)` classified as a relative URL without a leading `./`, while the rule config is set to `RelativeUrlStyleConfig::Always` in `.oxlintrc.json`. URLs that cannot take the prefix (absolute, scheme-bearing) are exempt.
Common situations: The same codebase gets opposite diagnostics depending on config; someone changed `relative-url-style` from the default `never` to `always`, and every previously-clean `new URL('foo', base)` now reports. The fix is mechanical, and the choice is purely a team style decision.
Related errors
- Remove the `./` prefix from the relative URL.
- Prefer `{} {}` over `{} {}` to check {}.
- Invalid escape sequence in template literal.
- No spaces inside empty pair of braces allowed
- Use uppercase characters for the value of the escape sequenc
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/6a817b6d1e7c3142.
Report an issue: GitHub.