Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upEnforce capitalization of the first letter of a comment (capitalized-comments) #682
Comments
dcousens
added
the
question
label
Nov 11, 2016
This comment has been minimized.
This comment has been minimized.
|
I'm not entirely consistent in my own code, though I think proper capitalization is better. There's no rule for this in ESLint, but there's a proposal to add it. When that gets added, I'll post an issue to consider it. |
feross
closed this
Nov 23, 2016
This comment has been minimized.
This comment has been minimized.
|
ESLint now has a I propose we enable it, as follows: "capitalized-comments": [
"error",
"always",
{
"ignoreInlineComments": true,
"ignoreConsecutiveComments": true
}
]This rule is also automatically fixable. |
feross
reopened this
Jan 7, 2017
feross
added
enhancement
and removed
question
labels
Jan 7, 2017
feross
added this to the
standard v9 milestone
Jan 7, 2017
feross
changed the title
Is there a convention for comments?
Enforce capitalization of the first letter of a comment (capitalized-comments)
Jan 7, 2017
This comment has been minimized.
This comment has been minimized.
|
Woo! |
This comment has been minimized.
This comment has been minimized.
|
@feross not disagreeing but why |
This comment has been minimized.
This comment has been minimized.
|
@timoxley Maybe you're right. I'll test the ecosystem impact of My thought was just that there could be reasons to do: function foo (/* host, port */) {
var host = arguments[0]
var port = arguments[1]
}I do this kind of thing in |
This comment has been minimized.
This comment has been minimized.
|
You typically see this for those who use the type systems analysis tools which pick up on inline comments for type declaration in standard JS code. IIRC |
This comment has been minimized.
This comment has been minimized.
|
@dcousens If we want to, we can explicitly allow certain uncapitalized words to start a comment without triggering this error. The rule supports exceptions. But a blanket exemption on inline comments is certainly simpler and won't need constant updating. |
This comment has been minimized.
This comment has been minimized.
|
The inline eslint pragmas need to all be lowercase: /* Eslint-env mocha */ // Does not work!
/* eslint-env mocha */ // Works!I wonder how many other transpilers/helpers would break because of forced uppercase. I tending to be thumbs down on this just because the value may not be worth the additional breakage (or the additional maintenance of a whitelist). |
This comment has been minimized.
This comment has been minimized.
|
I don't think we should - I don't feel this particular rule would be
useful, and might, in fact, become frustrating. With stuff like code
comments, function names and what not there's simply too many edge cases
…On Wed, Jan 11, 2017 at 5:55 PM Dan Flettre ***@***.***> wrote:
The inline eslint pragmas need to all be lowercase:
/* Eslint-env mocha */ // Does not work!/* eslint-env mocha */ // Works!
I wonder how many other transpilers/helpers would break because of forced
uppercase.
Flow? JSDoc?
I tending to thumbs down on this just because the value may not be worth
the additional breakage (or the additional maintenance of a whitelist).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#682 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACWlerpT-XhPG3RABtA1JNit7X5DsGOXks5rRQlxgaJpZM4KvDVD>
.
|
This comment has been minimized.
This comment has been minimized.
|
@Flet All eslint pragmas are special-cased by the rule already.
JSDoc is not affected because those declarations all start with a symbol ( @yoshuawuyts Personally, I think this is a pretty well-thought-out rule: http://eslint.org/docs/rules/capitalized-comments I'd like to try shipping it in the |
This comment has been minimized.
This comment has been minimized.
Yeah I'm a little concerned about accidentally breaking non-eslint/less popular/custom pragmas. Would be interested to see ecosystem impact. |
This comment has been minimized.
This comment has been minimized.
|
Wouldn't commented out code be affected as well? If so, this seems pretty overreaching. |
This comment has been minimized.
This comment has been minimized.
|
@jprichardson That's a good point that I hadn't considered. This rule basically prevents commented code from being committed. For example, this would error: function foo (x) {
// if (x === 1) return 10
return x
}In one way, it would be nice to prevent commented code from ending up in a codebase. But sometimes this is not avoidable, so I think I agree with @jprichardson now: this is a bit overreaching. @timoxley's point is good too. |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I agree in most cases, leaving commented code in place is a bad idea, especially since tools like Git are so pervasive. However, there are legitimate reasons to have commented code, like config files. Here is a real example from my codebase: export const EXODUS_SERVER = EXODUS_PRODUCTION_SERVER
// export const EXODUS_SERVER = EXODUS_STAGING_SERVER
So now if I just implemented a new feature on the server, I can quickly uncomment the aforementioned block to this: // export const EXODUS_SERVER = EXODUS_PRODUCTION_SERVER
export const EXODUS_SERVER = EXODUS_STAGING_SERVERand then the whole app is using I'm sure there's other cases that are equally as valid where this rule my impede. |
This comment has been minimized.
This comment has been minimized.
My thoughts exactly. |
This comment has been minimized.
This comment has been minimized.
You just have missed this part
|
This comment has been minimized.
This comment has been minimized.
|
@jprichardson I did, so I edited |
This comment has been minimized.
This comment has been minimized.
|
This rule has a big ecosystem impact:
To reduce the impact, I investigated allowing commented out code by using the So, if we only catch comments with real words that need to be capitalized, we get:
New rule is:
This is automatically fixable, so it's a quick fix. But jury's out on whether we actually want to do this. |
This comment has been minimized.
This comment has been minimized.
feross
removed this from the
standard v9 milestone
Feb 9, 2017
This comment has been minimized.
This comment has been minimized.
|
No please
…On Thu, Feb 9, 2017, 02:36 Feross Aboukhadijeh ***@***.***> wrote:
For example, here are some diffs after running standard --fix:
[image: screen shot 2017-02-08 at 5 35 16 pm]
<https://cloud.githubusercontent.com/assets/121766/22765421/0ecc8e72-ee25-11e6-87d3-65b96fd1ab6d.png>
[image: screen shot 2017-02-08 at 5 35 28 pm]
<https://cloud.githubusercontent.com/assets/121766/22765422/0ecf4612-ee25-11e6-8100-de3b35a87740.png>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#682 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACWlemDgdfp2g8B_ljW5oOn2jiiPmWBmks5ram2UgaJpZM4KvDVD>
.
|
This comment has been minimized.
This comment has been minimized.
|
Leaving open for more feedback, but yeah, I tend to agree with you @yoshuawuyts |
This comment has been minimized.
This comment has been minimized.
|
This has good intentions but my feeling is that the benefits are minimal and mostly aesthetic (i.e. does not reduce risk of any class of bugs) and yet the likelihood of it being a nuisance is high. Also don't like the risk of hard-to-detect logic corruption caused by uppercasing commented out source which is later uncommented. |
This comment has been minimized.
This comment has been minimized.
|
@dcousens thoughts? |
This comment has been minimized.
This comment has been minimized.
|
Along similar lines, maybe one could consider enforcing a particular formatting for multi-line jsdoc |
This comment has been minimized.
This comment has been minimized.
|
Agreed with @timoxley, its junk to think about, but, its harmless by definition and IMHO, not worth the community impact at all. |
This comment has been minimized.
This comment has been minimized.
|
Alright, it's decided. |
feross
closed this
Feb 9, 2017
This comment has been minimized.
This comment has been minimized.
|
This has been a great thread :) |


computersarecool commentedNov 10, 2016
I am wondering if this project favors sentence case or all lower case for comments?
i.e.
// This is my commentor
// this is my commentOr if it even matters.