Skip to content

convert-to-jsdoc-comments: fixer converts only the last line of consecutive line comments #1764

Description

@chendoron

Expected behavior

When several // comments sit on consecutive lines above a declaration, I'd expect the fixer to convert the whole group into one JSDoc block:

/**
 * one
 * two
 * three
 */
type Foo = string;

Actual behavior

Only the last line is converted, and the earlier lines are left above the new block:

// one
// two
/**
 * three
 */
type Foo = string;

The report is anchored on the last comment too, so it reads as though only that line is at fault.

This may well be by design, since ESLint hands the rule one comment token at a time and each // line is its own token. If so it might be worth a note in the docs — a paragraph written as stacked // lines is common enough that --fix over a codebase produces a lot of this, and the output is worse than the input.

ESLint Config

import jsdoc from 'eslint-plugin-jsdoc';
import tseslint from 'typescript-eslint';

export default [
  {
    files: ['**/*.ts'],
    languageOptions: { parser: tseslint.parser },
    plugins: { jsdoc },
    rules: {
      'jsdoc/convert-to-jsdoc-comments': [
        'error',
        { contexts: ['TSTypeAliasDeclaration'] },
      ],
    },
  },
];

ESLint sample

// one
// two
// three
type Foo = string;

Run eslint --fix on it.

Environment

  • Node version: 24.14.1
  • ESLint version: 9.39.4
  • eslint-plugin-jsdoc version: 64.3.5

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions