{"record":{"id":"608b33702b669e60","repo":"oxc-project/oxc","slug":"prefer-object-fromentries-over-manual-object-con","errorCode":null,"errorMessage":"Prefer `Object.fromEntries` over manual object construction from entries.","messagePattern":"Prefer `Object\\.fromEntries` over manual object construction from entries\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_object_from_entries.rs","lineNumber":21,"sourceCode":"    ast::{Expression, MemberExpression, ObjectPropertyKind, PropertyKind},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::CompactStr;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    ast_util::is_method_call,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::{call_expr_member_expr_property_span, does_expr_match_any_path},\n};\n\nfn prefer_object_from_entries_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `Object.fromEntries` over manual object construction from entries.\")\n        .with_help(\"Use `Object.fromEntries(pairs)` instead of manually building objects with `reduce` or `forEach`.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct PreferObjectFromEntries(Box<PreferObjectFromEntriesConfig>);\n\n#[derive(Debug, Clone, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct PreferObjectFromEntriesConfig {\n    /// Additional functions to treat as equivalents to `Object.fromEntries`.\n    functions: Vec<CompactStr>,\n}\n\nimpl Default for PreferObjectFromEntriesConfig {\n    fn default() -> Self {\n        Self { functions: vec![\"_.fromPairs\".into(), \"lodash.fromPairs\".into()] }\n    }","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/1f902a69625cd14e6d8dc58feca94da099d2d251/crates/oxc_linter/src/rules/unicorn/prefer_object_from_entries.rs#L3-L39","documentation":"Diagnostic from the unicorn/prefer-object-from-entries lint rule. It fires when code builds an object manually from a key/value collection — typically `entries.reduce((acc, [k, v]) => { acc[k] = v; return acc; }, {})` or an equivalent loop — where `Object.fromEntries(entries)` produces the same object declaratively. The flagged input is the manual construction expression. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_object_from_entries.rs:21 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the reduce/loop accumulation with `Object.fromEntries(entries)`","Use `Object.fromEntries(map)` directly for Maps","Apply the rule's auto-fix where the pattern is recognized"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1f902a69625cd14e6d8dc58feca94da099d2d251","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}