oxc-project/oxc · warning
Unexpected comment inline with code
Error message
Unexpected comment inline with code
What it means
Diagnostic from oxlint's no-inline-comments rule. It reports comments that sit on the same line as code (trailing comments after a statement), enforcing that explanatory comments live on their own line. The rule config provides an ignorePattern regex so markers such as lint directives or typed TODOs can be exempted.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_inline_comments.rs:19
use std::cell::LazyCell;
use lazy_regex::Regex;
use schemars::JsonSchema;
use serde::Deserialize;
use oxc_ast::{AstKind, Comment};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{
context::LintContext,
rule::{DefaultRuleConfig, Rule},
utils::deserialize_regex_option,
};
fn no_inline_comments_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected comment inline with code")
.with_help("Move the comment to a separate line")
.with_label(span)
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct NoInlineComments(Box<NoInlineCommentsConfig>);
#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoInlineCommentsConfig {
/// A regex pattern to ignore certain inline comments.
///
/// Comments matching this pattern will not be reported.
///
/// Example configuration:
/// ```json
/// {
/// "no-inline-comments": ["error", { "ignorePattern": "webpackChunkName" }]View on GitHub (pinned to e1e7af627c)
Solutions
- Move the comment to its own line above the code.
- Set ignorePattern for markers you allow inline (e.g. eslint-disable directives or TODOs).
- Delete comments that merely restate the code.
- Disable the rule if inline comments are the accepted house style.
Example fix
// before const limit = 10; // TODO: raise later // after // TODO: raise later const limit = 10;
Defensive patterns
Strategy: validation
Validate before calling
const inline = source.split('\n').some((l) => /[^:\s]\s+\/\//.test(l)); Prevention
- Write explanatory comments on their own line above the code.
- Set ignorePattern for markers you allow inline (TODO, lint directives).
- Add a lint step so inline comments are caught before merge.
When it happens
Trigger: const limit = 10; // TODO: raise later; doWork(); // side-effecting; any trailing // or /* */ comment on a line that also contains code, where the comment text does not match the configured ignorePattern.
Common situations: Adopting the rule mid-project when thousands of trailing notes exist; TODO/FIXME markers that need an ignorePattern exemption; generated code annotated inline by tooling.
Related errors
- Found a comment that would permit fallthrough, but case cann
- Unexpected '{term}' comment: {display}
- Use a regular expression literal instead of the `RegExp` con
- Expected '{curr_kind}' syntax before '{prev_kind}' syntax.
- Imports should be sorted alphabetically.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/a23ecff665565c96.
Report an issue: GitHub.