close

no-inline-comments

Unreleased

Configuration

rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-inline-comments': 'error',
    },
  },
]);

Rule Details

Some style guides disallow a comment on the same line as code. Comments alone on a line, or on a line consisting entirely of whitespace, are allowed.

This rule disallows comments on the same line as code.

Examples of incorrect code for this rule:

var a = 1; // declaring a to 1

function getRandomNumber() {
  return 4; // chosen by fair dice roll.
  // guaranteed to be random.
}

/* A block comment before code */ var b = 2;

var c = 3; /* A block comment after code */

Examples of correct code for this rule:

// This is a comment above a line of code
var foo = 5;

var bar = 5;
//This is a comment below a line of code

JSX exception

Comments that are the only content of a JSX expression container are not considered inline, since there is no code on either side of them.

var a = (
  <div>
    {/* comment */}
    <h1>Some heading</h1>
  </div>
);

Options

This rule accepts a single options object with the following property:

  • ignorePattern (string) - a pattern of comments to ignore

ignorePattern

Examples of correct code for this rule with the { "ignorePattern": "webpackChunkName:\\s.+" } option:

{ "no-inline-comments": ["error", { "ignorePattern": "webpackChunkName:\\s.+" }] }
import(/* webpackChunkName: "my-chunk-name" */ './locale/en');

Original Documentation