Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Place auto-generated JSDoc comments above multiple decorators/annotations #659

Closed
david-sharer opened this issue Nov 30, 2020 · 1 comment

Comments

@david-sharer
Copy link

When using TypeScript w/ multiple Annotations, eslint-plugin-jsdoc is expecting the doc to appear in a strange place. #571 indicates that the doc comment should be above annotations (and it seems to work for single annotations), but in the case of multiple annotations the behavior does not match.

Expected behavior

The following code snippet does not trigger the rule jsdoc/require-jsdoc.

/** Defines the current user's settings. */
@Injectable({
  providedIn: 'root',
})
@State<Partial<UserSettingsStateModel>>
({
  name: 'userSettings',
  defaults: {
    isDev: !environment.production,
  },
})
export class UserSettingsState { }

Actual behavior

The above code triggers the rule jsdoc/require-jsdoc, even though VS Code detects the documentation correctly.

It considers this valid:

@Injectable({
  providedIn: 'root',
})
@State<Partial<UserSettingsStateModel>>
({
  name: 'userSettings',
  defaults: {
    isDev: !environment.production,
  },
})
/** Defines the current user's settings. */
export class UserSettingsState { }

When run with --fix and no documentation, it attempts to place the doc comment line so:
(AFAIK this is invalid, and VS Code does not pick it up)

@Injectable({
  providedIn: 'root',
})
@State<Partial<UserSettingsStateModel>>/**
 *
 */
({
  name: 'userSettings',
  defaults: {
    isDev: !environment.production,
  },
})
export class UserSettingsState { }

ESLint Config

module.exports = {
  root: true,
  overrides: [
    {
      files: ['*.ts'],
      parser: '@typescript-eslint/parser',
      parserOptions: {
        project: [
          'tsconfig.*?.json',
        ],
        createDefaultProgram: true,
      },
      extends: [ ],
      plugins: ['jsdoc'],
      rules: {
        'jsdoc/require-jsdoc': [
          'error',
          {
            require: {
              ClassDeclaration: true,
            },
          },
        ],
      },
    },
  ],
};

ESLint sample

import { Injectable } from '@angular/core';
import { environment } from '@environments/environment';
import { State } from '@ngxs/store';

/** Defines the user state model. */
export class UserSettingsStateModel {
  public isDev: boolean;
}

/** Contains user-settings state. */
@Injectable({
  providedIn: 'root',
})
@State<Partial<UserSettingsStateModel>>({
  name: 'userSettings',
  defaults: {
    isDev: !environment.production,
  },
})
export class UserSettingsState { }

Environment

  • Node version: v12.17.0
  • ESLint version v7.13.0
  • eslint-plugin-jsdoc version: 30.7.8
@gajus
Copy link
Owner

gajus commented Jan 3, 2021

🎉 This issue has been resolved in version 30.7.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants