{"record":{"id":"9a5fc16cc3037cb1","repo":"oxc-project/oxc","slug":"unexpected-empty-fn-kind","errorCode":null,"errorMessage":"Unexpected empty {fn_kind} `{}`","messagePattern":"Unexpected empty (.+?) `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_empty_function.rs","lineNumber":29,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_empty_function_diagnostic<S: AsRef<str>>(\n    span: Span,\n    fn_kind: &str,\n    fn_name: Option<S>,\n) -> OxcDiagnostic {\n    let message = match fn_name {\n        Some(name) => Cow::Owned(format!(\"Unexpected empty {fn_kind} `{}`\", name.as_ref())),\n        None => Cow::Borrowed(\"Unexpected empty function\"),\n    };\n    OxcDiagnostic::warn(message)\n        .with_help(format!(\"Consider removing this {fn_kind} or adding logic to it.\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoEmptyFunction {\n    allow: Allowed,\n}\n\nimpl From<NoEmptyFunctionConfig> for NoEmptyFunction {\n    fn from(config: NoEmptyFunctionConfig) -> Self {\n        let mut flags = Allowed::None;\n        for kind in &config.allow {\n            flags |= Allowed::from(*kind);\n        }","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_empty_function.rs#L11-L47","documentation":"This diagnostic comes from the `no_empty_function` rule in oxlint. It reports a function with an empty body when the function has a name. The message names the function kind, such as function, method, or arrow function, plus the function name. The config option `allow` takes a list of kinds that may stay empty, for example `[\"arrowFunctions\"]`, `[\"constructors\"]`, or `[\"methods\"]`; by default no kind is allowed.","triggerScenarios":"A named function, method, getter, setter, or constructor whose body is `{}`: `function noop() {}` or `class A { connect() {} }`. The rule reports it with its kind and name.","commonSituations":"Interface stubs during scaffolding: `class Store { load() {} save() {} }`. A required callback that the developer had no use for. A refactor removes the body and leaves the shell behind.","solutions":["Remove the function when nothing calls it.","Give it a body, or `throw new Error('not implemented');` for stubs.","Allow the empty kind in the rule config, for example `\"no-empty-function\": [\"warn\", { \"allow\": [\"constructors\"] }]`.","Suppress once with `// oxlint-disable-next-line no-empty-function`."],"exampleFix":"// before\nclass Connector {\n  close() {}\n}\n\n// after\nclass Connector {\n  close() {\n    this.socket?.close();\n  }\n}","handlingStrategy":"validation","validationCode":"// crude scan: named functions with empty bodies\nconst empty = /function\\s+([A-Za-z_$][\\w$]*)\\s*\\([^)]*\\)\\s*{\\s*}/.exec(src);\nif (empty) throw new Error('empty function: ' + empty[1]);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `throw new Error('not implemented')` in stubs so tests fail loudly.","Delete dead methods instead of leaving `{}`.","List the kinds your project allows as empty in the `allow` option."],"tags":["javascript","eslint","lint","functions","stub-code"],"backgroundTag":"lint-empty-function","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"}