oxc-project/oxc · warning · OxcDiagnostic
Remove the `./` prefix from the relative URL.
Error message
Remove the `./` prefix from the relative URL.
What it means
This is the `never` diagnostic of oxlint's `unicorn/relative-url-style` rule (the default). It flags relative URL strings passed to `new URL()` that carry a redundant `./` prefix — `new URL('./foo', base)` — because `./foo` and `foo` resolve identically, and asks you to drop the prefix for consistency.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/relative_url_style.rs:20
AstKind,
ast::{Argument, NewExpression},
};
use oxc_diagnostics::OxcDiagnostic;
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);View on GitHub (pinned to e1e7af627c)
Solutions
- Remove the prefix: `new URL('foo', base)`.
- If your team prefers the explicit prefix, switch config to `"always"` so the rule enforces `./foo` instead of complaining about it.
- Run `oxlint --fix` under the `never` config to strip prefixes automatically.
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
// Pick one relative-URL style and enforce it in config
// .oxlintrc.json (default "never"):
// "unicorn/relative-url-style": "error"
const u = new URL('api/v1/users', baseUrl); Prevention
- Decide `never` vs `always` once per repo and encode it in `.oxlintrc.json`; both diagnostics come from the same rule.
- Do not mix `'./x'` and `'x'` across a codebase — the rule exists to stop the drift.
- Remember `./x` and `x` resolve identically; this is purely a consistency choice.
When it happens
Trigger: A string-literal first argument to `new URL('./path', base)` (the constructor call is matched via `is_new_expression` on `URL`) when the rule config is `never` (default). Absolute URLs, protocol-relative URLs, and non-literal arguments are ignored; the `url::Url` crate is used to classify the string as relative and prefixed.
Common situations: Teams standardizing URL construction across a codebase where some paths are written `'./x'` and others `'x'`; the inverse preference (`always`) exists for codebases that like the explicit `./` to signal 'relative' at a glance — same rule, opposite config, so the 'right' fix depends on which way your `.oxlintrc.json` sets it.
Related errors
- Add a `./` prefix to 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/ba5203cc953ccce9.
Report an issue: GitHub.