{"record":{"id":"b66abfa6ae804f84","repo":"oxc-project/oxc","slug":"do-not-rename-import-export-or-destructured-assi","errorCode":null,"errorMessage":"Do not rename import, export, or destructured assignments to the same name","messagePattern":"Do not rename import, export, or destructured assignments to the same name","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_useless_rename.rs","lineNumber":23,"sourceCode":"        BindingPattern, BindingProperty, ImportOrExportKind,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    fixer::{RuleFix, RuleFixer},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_useless_rename_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Do not rename import, export, or destructured assignments to the same name\",\n    )\n    .with_help(\"Use the variable's original name or rename it to a different name\")\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoUselessRename(Box<NoUselessRenameConfig>);\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoUselessRenameConfig {\n    /// When set to `true`, allows using the same name in destructurings.\n    ignore_destructuring: bool,\n    /// When set to `true`, allows renaming imports to the same name.\n    ignore_import: bool,\n    /// When set to `true`, allows renaming exports to the same name.\n    ignore_export: bool,\n}","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/oxc-project/oxc/blob/36ec0ef2bae567d1a8413ada2fe795f1af1f2785/crates/oxc_linter/src/rules/eslint/no_useless_rename.rs#L5-L41","documentation":"Diagnostic from the `no-useless-rename` rule. An import, export, or destructuring assignment renames a binding to exactly the same name: `import { foo as foo }`, `export { bar as bar }`, `let { a: a } = obj`. The rename is a no-op. The rule's config includes options (e.g. `allowDestructuringAsRename`... implemented via `NoUselessRenameConfig` with camelCase serde fields) to tolerate destructuring when desired.","triggerScenarios":"`import { readFile as readFile } from 'fs'`, `export { default as default }`, `const { x: x } = point`, `import * as ns`-style module renames that repeat the namespace. Fires on ImportSpecifier/ExportSpecifier/ObjectPattern property pairs where imported/exported/local names are identical.","commonSituations":"Codemods that mechanically add aliases to every specifier; editors auto-completing `x as x`; migration scripts converting CommonJS requires to named imports with redundant aliases.","solutions":["Drop the alias: `import { foo as foo }` -> `import { foo }`.","For destructuring: `const { x: x } = obj` -> `const { x } = obj`.","Set `{ \"allowDestructuring\": true }` in config if you want same-name destructuring kept.","Apply the autofix; the rule provides a RuleFix that removes the redundant rename text."],"exampleFix":"// before\nimport { readFile as readFile } from 'node:fs';\nconst { x: x } = point;\n\n// after\nimport { readFile } from 'node:fs';\nconst { x } = point;","handlingStrategy":"validation","validationCode":"const hasRedundantRename = /\\{\\s*[\\w$]+\\s+as\\s+[\\w$]+\\s*\\}/.test(importLine) &&\n  importLine.match(/\\{\\s*([\\w$]+)\\s+as\\s+([\\w$]+)/)?.slice(1)?.every(n => n === importLine.match(/as\\s+([\\w$]+)/)?.[1]);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only add `as alias` when the local name differs from the exported one.","Review codemod output for mechanically added aliases.","Configure allowDestructuring if same-name destructuring is your convention."],"tags":["lint","eslint","oxlint","imports","exports","destructuring"],"backgroundTag":"no-useless-rename","analyzedSha":"36ec0ef2bae567d1a8413ada2fe795f1af1f2785","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}