{"record":{"id":"a23ecff665565c96","repo":"oxc-project/oxc","slug":"unexpected-comment-inline-with-code","errorCode":null,"errorMessage":"Unexpected comment inline with code","messagePattern":"Unexpected comment inline with code","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_inline_comments.rs","lineNumber":19,"sourceCode":"use std::cell::LazyCell;\n\nuse lazy_regex::Regex;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse oxc_ast::{AstKind, Comment};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::deserialize_regex_option,\n};\n\nfn no_inline_comments_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected comment inline with code\")\n        .with_help(\"Move the comment to a separate line\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoInlineComments(Box<NoInlineCommentsConfig>);\n\n#[derive(Debug, Default, Clone, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoInlineCommentsConfig {\n    /// A regex pattern to ignore certain inline comments.\n    ///\n    /// Comments matching this pattern will not be reported.\n    ///\n    /// Example configuration:\n    /// ```json\n    /// {\n    ///     \"no-inline-comments\": [\"error\", { \"ignorePattern\": \"webpackChunkName\" }]","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_inline_comments.rs#L1-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst limit = 10; // TODO: raise later\n\n// after\n// TODO: raise later\nconst limit = 10;","handlingStrategy":"validation","validationCode":"const inline = source.split('\\n').some((l) => /[^:\\s]\\s+\\/\\//.test(l));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["eslint","oxlint","lint","comments","style"],"backgroundTag":"inline-comment-style","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"}