{"record":{"id":"ba5203cc953ccce9","repo":"oxc-project/oxc","slug":"remove-the-prefix-from-the-relative-url","errorCode":null,"errorMessage":"Remove the `./` prefix from the relative URL.","messagePattern":"Remove the `\\./` prefix from the relative URL\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/relative_url_style.rs","lineNumber":20,"sourceCode":"    AstKind,\n    ast::{Argument, NewExpression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\nuse url::Url;\n\nuse crate::{\n    AstNode,\n    ast_util::is_new_expression,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn never_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Remove the `./` prefix from the relative URL.\").with_label(span)\n}\n\nfn always_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Add a `./` prefix to the relative URL.\").with_label(span)\n}\n\n#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)]\n#[serde(rename_all = \"kebab-case\")]\npub enum RelativeUrlStyleConfig {\n    #[default]\n    /// Never use a `./` prefix.\n    Never,\n    /// Always add a `./` prefix to the relative URL when possible.\n    Always,\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\npub struct RelativeUrlStyle(RelativeUrlStyleConfig);","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/relative_url_style.rs#L2-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst u = new URL('./api/v1/users', baseUrl);\n\n// after\nconst u = new URL('api/v1/users', baseUrl);","handlingStrategy":"validation","validationCode":"// Pick one relative-URL style and enforce it in config\n// .oxlintrc.json (default \"never\"):\n// \"unicorn/relative-url-style\": \"error\"\nconst u = new URL('api/v1/users', baseUrl);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["oxlint","unicorn","url","style","config-dependent"],"backgroundTag":"relative-url-prefix-style","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}