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

Rule proposal: multiline-comment-style #8320

Closed
not-an-aardvark opened this issue Mar 25, 2017 · 8 comments · Fixed by #9389
Closed

Rule proposal: multiline-comment-style #8320

not-an-aardvark opened this issue Mar 25, 2017 · 8 comments · Fixed by #9389
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules

Comments

@not-an-aardvark
Copy link
Member

Please describe what the rule should do:

This rule enforces the styling of multiline comments. It has the following options:

  • separate-lines disallows multiline block comments in favor of using consecutive line comments.
  • starred-block (default) disallows consecutive line comments in favor of using a block comment, and requires block somments to have a * at the beginning of each line.
  • bare-block disallows consecutive line comments in favor of using a block comment, and prohibits block comments from having a * at the beginning of each line.

The rule always ignores configuration comments (using the same heuristic as the other existing comment rules). When using the separate-lines or bare-block options, the rule ignores JSDoc comments.

What category of rule is this? (place an "X" next to just one item)

[x] Enforces code style
[ ] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

/* eslint multiline-comment-style: [error, separate-lines] */

/* This line
calls foo() */
foo();

/*
 * This line
 * calls foo()
 */
foo();
/* eslint multiline-comment-style: [error, starred-block] */

// this line
// calls foo()
foo();

/* this line
calls foo() */
foo();

/* this comment
 * is missing a newline after /*
 */

/*
 * this comment
 * is missing a newline at the end */

/*
* the star in this line should have a space before it
 */

/*
 * the star on the following line should have a space before it
*/
/* eslint multiline-comment-style: [error, bare-block] */

// this line
// calls foo()
foo();

/*
 * this line
 * calls foo()
 */
foo();

Why should this rule be included in ESLint (instead of a plugin)?

Comment styling is an extremely common stylistic concern. Many styleguides require a particular format for multiline comments, including

Since ESLint doesn't provide a rule to lint for comment style, it's difficult for project maintainers to automatically enforce a styleguide. Adding a rule for this would make it easier to use consistent formatting and to satisfy a very common styleguide requirement.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Mar 25, 2017
@not-an-aardvark not-an-aardvark self-assigned this Mar 25, 2017
@not-an-aardvark not-an-aardvark added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Mar 25, 2017
@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Apr 7, 2017
@JPeer264
Copy link
Contributor

I could try to implement this, but I have absolutely no clue how to implement an autofixer for this. But I guess this can be also implemented later.

@not-an-aardvark
Copy link
Member Author

I've already started working on an implementation for this. (Sorry, I should have mentioned that earlier.)

not-an-aardvark added a commit that referenced this issue May 5, 2017
This code is currently messy and incomplete. There are also some edge cases that the rule's design needs to address (e.g. allowing "banner" comments which are created from several consecutive line comments).
@melloc
Copy link

melloc commented Aug 2, 2017

@not-an-aardvark Will this also enforce a space after * when using starred-block? (Or would that be better as an option to spaced-comment?)

@Nostradamos
Copy link

Nostradamos commented Aug 10, 2017

Any eta for this? Doesn't seem to be merged to master yet, but would be very nice to have.

@platinumazure
Copy link
Member

Ping @not-an-aardvark, are you still working on this or can someone else take a crack at it?

@not-an-aardvark
Copy link
Member Author

I'm not actively working on this right now, someone else can feel free to take it.

I have a WIP commit here, so feel free to work from my partial implementation and test cases.

I have a few minor usability concerns with the current design of the rule -- for example, it disallows "banner comments" like the one below, since they're just consecutive line comments:

//------------------------------
// this is a banner comment
//------------------------------

But maybe we can address those after the initial implementation.

@luxaritas
Copy link

luxaritas commented Aug 13, 2017

What about use cases like this?

// Same line, "flat"
/* this line
calls foo() */

// Same line, lining up the text
/* this line
    calls foo() */

// Include newline, "flat"
/*
this line
calls foo()
*/

// Include newline, indented (to an arbitrary amount of spaces/tabs)
/*
    this line
    calls foo
*/

@not-an-aardvark
Copy link
Member Author

@lfp6 could you clarify your question? I'm not sure what you're asking about with regard to those examples.

aladdin-add pushed a commit to aladdin-add/eslint that referenced this issue Oct 3, 2017
This code is currently messy and incomplete. There are also some edge cases that the rule's design needs to address (e.g. allowing "banner" comments which are created from several consecutive line comments).
aladdin-add pushed a commit to aladdin-add/eslint that referenced this issue Oct 6, 2017
This code is currently messy and incomplete. There are also some edge cases that the rule's design needs to address (e.g. allowing "banner" comments which are created from several consecutive line comments).
ilyavolodin pushed a commit that referenced this issue Oct 14, 2017
* New: multiline-comment-style rule (fixes #8320)

This code is currently messy and incomplete. There are also some edge cases that the rule's design needs to address (e.g. allowing "banner" comments which are created from several consecutive line comments).

* Chore: add multiline-comment-style in eslint:recommended.

* finished :(

* Fix: review suggestions
Squashed commits:
[914bea1] fix: fixer would cause invalid syntax.
[a4dd76c] Fix: isJSDoc checking each line starts with "*".
[e16985a] prefer fixer.replaceText().

 .

* Update multiline-comment-style.md
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Apr 13, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants