{"record":{"id":"6a817b6d1e7c3142","repo":"oxc-project/oxc","slug":"add-a-prefix-to-the-relative-url","errorCode":null,"errorMessage":"Add a `./` prefix to the relative URL.","messagePattern":"Add a `\\./` prefix to the relative URL\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/relative_url_style.rs","lineNumber":24,"sourceCode":"use 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);\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/relative_url_style.rs#L6-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst u = new URL('api/v1/users', baseUrl);\n\n// after\nconst u = new URL('./api/v1/users', baseUrl);","handlingStrategy":"validation","validationCode":"// Same rule, opposite config: make the prefix mandatory\n// .oxlintrc.json:\n// \"unicorn/relative-url-style\": [\"error\", \"always\"]\nconst u = new URL('./api/v1/users', baseUrl);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"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-14T00:17:10.932Z"}