{"record":{"id":"4091d74abf38cb69","repo":"oxc-project/oxc","slug":"unsafe-lifecycle-method-method-name-is-not-all","errorCode":null,"errorMessage":"Unsafe lifecycle method `{method_name}` is not allowed","messagePattern":"Unsafe lifecycle method `(.+?)` is not allowed","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/no_unsafe.rs","lineNumber":26,"sourceCode":"use crate::{\n    AstNode,\n    config::ReactVersion,\n    context::{ContextHost, LintContext},\n    rule::{DefaultRuleConfig, Rule},\n    utils::{get_parent_component, is_es5_component},\n};\n\nfn no_unsafe_diagnostic(method_name: &str, span: Span) -> OxcDiagnostic {\n    let replacement = match method_name {\n        \"componentWillMount\" | \"UNSAFE_componentWillMount\" => \"componentDidMount\",\n        \"componentWillReceiveProps\" | \"UNSAFE_componentWillReceiveProps\" => {\n            \"getDerivedStateFromProps\"\n        }\n        \"componentWillUpdate\" | \"UNSAFE_componentWillUpdate\" => \"componentDidUpdate\",\n        _ => \"alternative lifecycle methods\",\n    };\n\n    OxcDiagnostic::warn(format!(\"Unsafe lifecycle method `{method_name}` is not allowed\"))\n        .with_help(format!(\n            \"Use `{replacement}` instead. See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html\"\n        ))\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Default)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\nstruct NoUnsafeConfig {\n    /// Whether to check for the non-prefixed lifecycle methods.\n    /// If `true`, this means `componentWillMount`, `componentWillReceiveProps`,\n    /// and `componentWillUpdate` will also be flagged, rather than just the\n    /// UNSAFE_ versions. It is recommended to set this to `true` to fully\n    /// avoid unsafe lifecycle methods.\n    check_aliases: bool,\n}\n\n#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/no_unsafe.rs#L8-L44","documentation":"Raised by react/no_unsafe when a class declares a legacy unsafe lifecycle method (`componentWillMount`, `componentWillReceiveProps`, `componentWillUpdate`, or their UNSAFE_-prefixed forms). At the throw site the method is scheduled for removal/already unsupported under async rendering (React 16.3+/17+ with StrictMode double-invocation), and the message indicates the supported replacement (componentDidMount, getDerivedStateFromProps, componentDidUpdate). no_unsafe_diagnostic fires from run() for each matching class method, gated by the configured React version.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/no_unsafe.rs:26 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Migrate componentWillMount to componentDidMount.","Migrate componentWillReceiveProps to getDerivedStateFromProps.","Migrate componentWillUpdate to componentDidUpdate or getSnapshotBeforeUpdate."],"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-14T00:17:10.932Z"}