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

Indentation after an decorator in an example #789

Closed
Ulrikop opened this issue Oct 6, 2021 · 5 comments · Fixed by #809
Closed

Indentation after an decorator in an example #789

Ulrikop opened this issue Oct 6, 2021 · 5 comments · Fixed by #809

Comments

@Ulrikop
Copy link

Ulrikop commented Oct 6, 2021

Expected behavior

Examples that use a decorator allow additional indentation, such as an example without a decorator.

Actual behavior

An example that has an additional indentation on a new line after a decorator throws There must be no indentation.

ESLint Config

{
  "env": {
    "es6": true
  },
  "parser": "@typescript-eslint/parser",
  "plugins": ["jsdoc"],
  "rules": {
    "jsdoc/check-indentation": "error"
  }
}

ESLint sample

/**
 * @example 
 * ```
 * @MyDecorator({
 *   myOptions: 42
 * })
 * export class MyClass {}
 * ```
 *
 * @example 
 * ```
 * MyDecorator({
 *   myOptions: 42
 * })
 * ```
 */
function MyDecorator(options: { myOptions: number }) {
  return (Base: Function) => {};
}

First @example throw There must be no indentation, the second @example is fine.

Environment

  • Node version: 12.18.4
  • ESLint version 7.32.0
  • eslint-plugin-jsdoc version: 36.1.0
  • @typescript-eslint/parser version: 4.33.0
@gajus
Copy link
Owner

gajus commented Oct 9, 2021

🎉 This issue has been resolved in version 36.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Oct 9, 2021
@Ulrikop
Copy link
Author

Ulrikop commented Oct 9, 2021

Thx for your quick help @brettz9
It looks like it works like a charm, Because of your \s in the regex @\w+\s it also works for decorators without params:

/**
 * @example 
 * ```
 * @MyDecorator
 * export class MyClass {}
 * ```
 */
function MyDecorator(Base: Function) {
}

perhaps a good scenario for the tests to avoid that it will break in a future refactoring?

but I've seen a case where there is a difference between example with decorator and without decorator:

/**
 * @example ```
 * @MyDecorator({
 *   myOptions: 42
 * })
 * export class MyClass {}
 * ```
 * 
 * @example ```
 * MyDecorator({
 *   myOptions: 42
 * })
 * ```
 */
function MyDecorator(options: { myOptions: number }) {
  return (Base: Function) => {};
}

first @example still throws an error, second, it doesn't.
It is ok for me, because we always add the beginning ``` to the next line, but I just wanted to give you the feedback. 👍

@brettz9
Copy link
Collaborator

brettz9 commented Oct 11, 2021

Thanks for the info. Am preoccupied now but hope to take a look within a couple weeks.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Dec 1, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Dec 1, 2021
@gajus
Copy link
Owner

gajus commented Dec 1, 2021

🎉 This issue has been resolved in version 37.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@brettz9
Copy link
Collaborator

brettz9 commented Dec 1, 2021

@Ulrikop : Sorry it took longer than expected for me to get to it, but the other @example variety is now fixed too. (v37.1.0)

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

Successfully merging a pull request may close this issue.

3 participants