oxc-project/oxc · error · OxcDiagnostic

Unary operator '{operator}' used.

Error message

Unary operator '{operator}' used.

What it means

Lint diagnostic from eslint/no-plusplus: the ++ or -- unary update operator was used (the operator name is interpolated into the message). The rule discourages them because pre/post increment semantics cause off-by-one bugs, especially inside expressions; the help suggests the compound-assignment form.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_plusplus.rs:15

use oxc_ast::{AstKind, ast::UpdateOperator};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use schemars::JsonSchema;
use serde::Deserialize;

use crate::{
    AstNode,
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
};

fn no_plusplus_diagnostic(span: Span, operator: UpdateOperator) -> OxcDiagnostic {
    let diagnostic = OxcDiagnostic::warn(format!(
        "Unary operator '{operator}' used.",
        operator = operator.as_str()
    ))
    .with_label(span);

    match operator {
        UpdateOperator::Increment => {
            diagnostic.with_help("Use the assignment operator `+=` instead.")
        }
        UpdateOperator::Decrement => {
            diagnostic.with_help("Use the assignment operator `-=` instead.")
        }
    }
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoPlusplus {

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Use compound assignment: i += 1 or i -= 1
  2. Enable allowForLoopAfterthoughts if ++ in for-loop updates is acceptable
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/eslint/no_plusplus.rs:15 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/40eaeb6df3f75690. Report an issue: GitHub.