{"record":{"id":"fad1ff9474e12a36","repo":"oxc-project/oxc","slug":"only-files-containing-jsx-may-use-the-extension","errorCode":null,"errorMessage":"Only files containing JSX may use the extension '.{ext}'","messagePattern":"Only files containing JSX may use the extension '\\.(.+?)'","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/jsx_filename_extension.rs","lineNumber":30,"sourceCode":"use oxc_str::CompactStr;\n\nuse crate::{context::LintContext, rule::Rule};\n\nfn no_jsx_with_filename_extension_diagnostic(\n    ext: &str,\n    span: Span,\n    allowed_extensions: &[CompactStr],\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"JSX not allowed in files with extension '.{ext}'\"))\n        .with_help(format!(\n            \"Rename the file to use an allowed extension: {}\",\n            allowed_extensions.iter().map(|e| format!(\".{e}\")).join(\", \")\n        ))\n        .with_label(span)\n}\n\nfn extension_only_for_jsx_diagnostic(ext: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Only files containing JSX may use the extension '.{ext}'\"))\n        .with_help(\"Rename the file with a good extension.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize, Serialize)]\n#[serde(rename_all = \"kebab-case\")]\nenum JsxFilenameExtensionAllowMode {\n    /// Always allow a JSX filename extension.\n    #[default]\n    Always,\n    /// Only allow JSX filename extension for files that contain JSX syntax.\n    AsNeeded,\n}\n\nimpl JsxFilenameExtensionAllowMode {\n    pub fn from(raw: &str) -> Self {\n        match raw {\n            \"as-needed\" => Self::AsNeeded,","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/jsx_filename_extension.rs#L12-L48","documentation":"Raised by react/jsx_filename_extension when configured with `allowAsRequired` and the file uses a JSX-permitting extension (like .jsx/.tsx) without containing any JSX. At the throw site the extension claims JSX content that is not there, which misleads module consumers and tooling about the file's contents. extension_only_for_jsx_diagnostic is produced by run_once() when the filename extension is allowed only for JSX files but no JSX element exists in the module.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/jsx_filename_extension.rs:30 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rename the file to .js or .ts if it contains no JSX.","Add JSX if the file was intended to contain markup."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}