{"record":{"id":"fd438de39b903189","repo":"oxc-project/oxc","slug":"expecting-object-for-eslint-no-magic-numbers-confi","errorCode":null,"errorMessage":"Expecting object for eslint/no-magic-numbers configuration","messagePattern":"Expecting object for eslint/no-magic-numbers configuration","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs","lineNumber":85,"sourceCode":"    /// When true, numeric literals used as TypeScript numeric literal types are ignored.\n    ignore_numeric_literal_types: bool,\n    /// When true, numeric literals in readonly class properties are ignored.\n    ignore_readonly_class_properties: bool,\n    /// When true, numeric literals used to index TypeScript types are ignored.\n    ignore_type_indexes: bool,\n}\n\nimpl TryFrom<&serde_json::Value> for NoMagicNumbersConfig {\n    type Error = OxcDiagnostic;\n\n    fn try_from(raw: &serde_json::Value) -> Result<Self, Self::Error> {\n        if raw.is_null() {\n            return Ok(NoMagicNumbersConfig::default());\n        }\n\n        raw.get(0).map_or_else(\n            || {\n                Err(OxcDiagnostic::warn(\n                    \"Expecting object for eslint/no-magic-numbers configuration\",\n                ))\n            },\n            |object| {\n                fn get_bool_property(object: &serde_json::Value, index: &str) -> bool {\n                    object.get(index).and_then(serde_json::Value::as_bool).unwrap_or_default()\n                }\n                Ok(Self {\n                    ignore: object\n                        .get(\"ignore\")\n                        .and_then(serde_json::Value::as_array)\n                        .map(|v| {\n                            v.iter()\n                                .map(|v| {\n                                    if v.is_number() {\n                                        NoMagicNumbersNumber::Float(v.as_f64().unwrap())\n                                    } else {\n                                        NoMagicNumbersNumber::BigInt(v.as_str().unwrap().to_owned())","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs#L67-L103","documentation":"Configuration-load diagnostic from oxlint's eslint/no-magic-numbers rule (crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs:85). NoMagicNumbersConfig::try_from expects the ESLint array form where the options object sits at index 0 (the config layer wraps rule options as Value::Array and the rule reads raw.get(0)); when there is no options object there — a bare scalar, an empty array, or a shape produced by hand-written/unnormalized configs or direct API calls — it returns this 'Expecting object' diagnostic. Note that from_configuration (line 308) calls try_from(...).unwrap(), so a bad shape aborts config loading with this message instead of being reported as a soft config warning.","triggerScenarios":"Calling NoMagicNumbers::from_configuration with a non-array, non-null serde_json::Value (e.g. json!(\"strict\"), json!(42), or json!([])); supplying rule options in a shape the config normalizer does not produce, such as nested or duplicated options objects in .oxlintrc.json overrides or programmatic LintService/napi usage that bypasses normalization.","commonSituations":"Hand-editing .oxlintrc.json or extends-chains that produce unexpected rule-config shapes; tools that generate oxlint configs from ESLint configs incorrectly; API/napi integrations passing options directly instead of the severity+options array form; version differences between oxlint releases changing accepted shapes.","solutions":["Write the rule config in the standard ESLint array form: \"no-magic-numbers\": [\"error\", { \"enforceConst\": true, \"ignore\": [1, 2] }]","Validate .oxlintrc.json against the documented schema and re-run oxlint --version-matched configs after upgrades","If invoking the linter programmatically, pass Value::Null (defaults) or Value::Array([optionsObject]) — never a bare scalar — to from_configuration","Report a bug to the oxc repo if the normal config loader itself triggers this, since the loader is expected to always wrap options into an array"],"exampleFix":"// .oxlintrc.json — before (malformed options shape)\n\"no-magic-numbers\": \"strict\"\n\n// after\n\"no-magic-numbers\": [\"error\", { \"enforceConst\": true }]","handlingStrategy":"validation","validationCode":"// Validate the no-magic-numbers entry shape before running oxlint\nfunction validateRuleConfig(name, value) {\n  if (name !== 'no-magic-numbers') return true;\n  if (value === 'error' || value === 'warn' || value === 'off') return true; // severity-only\n  if (Array.isArray(value) && (value.length === 1 || typeof value[1] === 'object')) return true;\n  console.error(`bad config shape for ${name}`);\n  return false;\n}","typeGuard":"const isNoMagicNumbersConfig = (v) =>\n  v == null ||\n  (Array.isArray(v) && (v.length === 0 || (typeof v[0] === 'object' && v[0] !== null)));","tryCatchPattern":"try {\n  NoMagicNumbers.from_configuration(value);\n} catch (e) {\n  // unwrap() on a non-array/non-null options value panics with this diagnostic;\n  // log it as a config error and fall back to default options\n}","preventionTips":["Always write rule options in the [severity, optionsObject] array form","Generate configs with oxlint's own tooling or migrate from ESLint configs with the official converter rather than by hand","Validate .oxlintrc.json in CI (JSON schema + smoke 'oxlint --lint-config' style run) before merging"],"tags":["lint","configuration","oxlintrc","json","schema-validation"],"backgroundTag":"linter-config-validation","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"}