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

Consider keeping @type comments single-line if possible #135

Closed
G-Rath opened this issue Nov 4, 2021 · 13 comments
Closed

Consider keeping @type comments single-line if possible #135

G-Rath opened this issue Nov 4, 2021 · 13 comments

Comments

@G-Rath
Copy link
Contributor

G-Rath commented Nov 4, 2021

Currently with jsdocSingleLineComment set to false, this:

/** @type {import('eslint').Linter.Config} */
const config = {
  // ...
};

Becomes

/**
 * @type {import('eslint').Linter.Config}
 */
const config = {
  // ...
};

Personally, I like having multi-line jsdoc comments for "documentation" comments aka generally anytime it has more than a sole @ tag; I'm less fussed about things like @private as they're typically on methods which should be documented anyway, but @types is very common when working in javascript codebases that are statically checked with TypeScript.

This also leads to casts being multi-lined which doesn't look quite right (and might even break the cast):

module.exports = (/** @type {string} */ (config));

// becomes

module.exports = /**
 * @type {string}
 */ (config);

Would it be possible for this plugin to only force a jsdoc comment to be multiline if it had anything except a single @ tag?

@RedGuy12
Copy link

RedGuy12 commented Nov 4, 2021 via email

@hosseinmd
Copy link
Owner

set jsdocSingleLineComment to true will solve your issue

@G-Rath
Copy link
Contributor Author

G-Rath commented Nov 5, 2021

@hosseinmd that won't solve my issue:

Personally, I like having multi-line jsdoc comments for "documentation" comments aka generally anytime it has more than a sole @ tag;

That's why I have it set to false, because of #93.

@hosseinmd hosseinmd reopened this Nov 5, 2021
@hosseinmd
Copy link
Owner

#93 closed becuase of this commit f755db1

Give me a solotion for your request.

@G-Rath
Copy link
Contributor Author

G-Rath commented Nov 5, 2021

Would it be possible for this plugin to only force a jsdoc comment to be multiline if it had anything except a single @ tag?

That's the high-level solution, maybe with an exclude for @description since that'd include what #93 was about.

So it'd look like:

// single-line because it's only got one @ tag
/** @internal */
export const myProperty1 = 1;

// multi-line because it's got multiple @ tags
/**
 * @type {number}
 * @internal
 */
export const myProperty2 = 1;

// multi-line because it exceeds the line length
/**
 * @type {import('@organisation/my-organisations-package').DeeplyNested.Type.Lives.here}
 */
export const myProperty3 = 1;

function receiveStructsSet(aSetObject){
  // single-line because it only has one @ tag
  const mySet = /** @type {goog.structs.Set} */ (aSetObject);
}

class MyClass {
  // multi-line because it doesn't have an @ tag
  /**
   * This describes my method, it is awesome
   */
  myMethod1() {
    // ...
  }

  // multi-line because it has a @description tag
  /**
   * @description This describes my method, it is awesome
   */
  myMethod2() {
    // ...
  }

  // single-line because it's just got one @ tag
  /** @private */
  myMethod3() {
    // ...
  }

  // single-line because it's just got one @ tag
  /** @private */
  myMethod4() {
    // ...
  }

  // multi-line because it's got multiple @ tag
  /**
   * @private
   * @internal
   */
  myMethod5() {
    // ...
  }

  // single-line because it's just got one @ tag
  /** @private */
  myMethod6() {
    // ...
  }

  // multi-line because it's got multiple @ tags
  /**
   * @private
   * @internal
   */
  myMethod7() {
    // ...
  }
}

I'm wondering if it might be worth supporting this as an option that takes an array that represents the tags to allow being single-line, with the default being @type 🤔

I'm happy to have a go at making a PR implementing this either as it's own new option, or as the default behaviour for jsdocSingleLineComment :)

@hosseinmd
Copy link
Owner

PR is welcome

@tjx666
Copy link

tjx666 commented Dec 31, 2022

I think jsdocSingleLineComment option should be a enum type, and provide:

  • singleLine
  • multipleLine
  • keep

Weather should be one line is diffrent in diffrent case. So there should be one option to keep they are

This is the only reasone forbid me to using this plugin

@tjx666
Copy link

tjx666 commented May 27, 2023

@G-Rath maybe this issue can be closed?

@G-Rath
Copy link
Contributor Author

G-Rath commented May 27, 2023

@tjx666 why do you say that?

@tjx666
Copy link

tjx666 commented May 27, 2023

Sorry for that message, lone time no see this issue, but see there is a option jsdocSingleLineComment...

@G-Rath
Copy link
Contributor Author

G-Rath commented May 27, 2023

jsdocSingleLineComment does not address this issue - please read the original body and my follow-on comments for why.

@hosseinmd
Copy link
Owner

I think jsdocSingleLineComment option should be a enum type, and provide:

  • singleLine
  • multipleLine
  • keep

Weather should be one line is diffrent in diffrent case. So there should be one option to keep they are

This is the only reasone forbid me to using this plugin

This is much better. But we should discuss options.

hosseinmd added a commit that referenced this issue Oct 6, 2023
@hosseinmd
Copy link
Owner

implemented
jsdocCommentLineStrategy ("singleLine","multiline","keep")

deprecated
jsdocSingleLineComment has backward compatibility

v1.1.0

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

No branches or pull requests

4 participants