oxc-project/oxc · error · OxcDiagnostic

Function component is not

Error message

Function component is not {article} {}

What it means

Raised by react/function-component-definition when a function component's declaration style does not match the configured allowed styles (e.g. the rule is set to arrow functions but the component is a function declaration). The article is 'an' for arrow, 'a' otherwise.

Solutions

  1. Rewrite the component in the style required by the rule configuration (arrow function, named function, or function expression).
  2. Adjust the allowedStyles/namedComponents setting to permit the current style.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/react/function_component_definition.rs:22 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/23e5923239fc168a. Report an issue: GitHub.

Appendix: source

Thrown at crates/oxc_linter/src/rules/react/function_component_definition.rs:22

use oxc_ast::{
    AstKind,
    ast::{AssignmentTarget, FunctionType, VariableDeclarator},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

use crate::{
    AstNode,
    ast_util::iter_outer_expressions,
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
    utils::{arrow_function_returns, function_returns, is_hoc_call, is_react_component_name},
};

fn function_component_definition_diagnostic(span: Span, expected: FunctionStyle) -> OxcDiagnostic {
    let article = if expected == FunctionStyle::Arrow { "an" } else { "a" };
    OxcDiagnostic::warn(format!("Function component is not {article} {}", expected.description()))
        .with_label(span)
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
struct FunctionComponentDefinitionConfig {
    named_components: NamedComponents,
    unnamed_components: UnnamedComponents,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(untagged)]
enum NamedComponents {
    Single(NamedComponentStyle),
    Multiple(Vec<NamedComponentStyle>),
}

impl Default for NamedComponents {

View on GitHub (pinned to e1e7af627c)