-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add new ESLint rule to enforce comment case/punctuation #34964
base: trunk
Are you sure you want to change the base?
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @opr! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
This is to determine if it's part of a "multi line" comment.
Since it's been removed, the tests don't need to check the fixer works.
adbdf6a
to
892fbef
Compare
I've created #36866 which applies fixes to all warnings on comments introduced by the rule addition in this PR. The main purpose of doing that PR was to find exceptions to the rule. I have added a regex for excluding various pragmas (think There is also now an exception to the rule where if your comment begins with an This PR now also only describes the |
@opr impressive work 👏🏻
I think that's a reasonable approach to give the rule some a few more months so it can mature. In the meantime we should observe whether we run into more edge cases 💯 Let's bring this PR in the #core-js channel on WordPress Slack to have more eyes looking at the final implementaiton. We could even land #36866 before that if we remove changes that are part of this PR 😄 |
Thanks @gziolo, I'll be there in #core-js on 30th November to discuss this with everyone :) That's the next office hours, right?
Great, I'll remove those parts and submit the PR for review. Thanks for your support on this! |
Description
Note: I have never written an ESLint rule from scratch before, so any suggestions for improvement will be really appreciated
As part of the new proposal to amend the Coding Standards this PR adds a new custom ESLint rule that will find comments that don't terminate with a sentence-ending punctuation mark (
!
,?
, or.
), comments that do not contain a space between the comment token and the first word, and comments where the first word is not capitalised.I do not know if there's a way to detect if a comment is commented out code, or if it's just a regular inline comment.
This rule only targets comments of type
Line
andBlock
functions that start and terminate on the same line. It won't consider multi-line block comments.The rule also considers whether a
Line
comment is followed or preceded directly by another comment. The reason for this is so comments of the below type are considered as one comment. The first and middle lines don't need to end with punctuation, and the middle and last line don't need to have capital letters. All lines do need to have spaces between the token and the words though.I also excludes comments that contain
translators:
, and@see
or@todo
type comments. There is a RegEx I used to check if comments were of this type:/translators:|@\w*\s/
. In plain English this rule translates to "Any string containingtranslators
or an @ sign followed immediately by a word and a whitespace character".I have elected not to include an automatic fixer function to this. This is on the basis that it degrades the Developer Experience when it adds periods/spaces/capitals to commented out code. A situation where this could be annoying is when developing with
Fix eslint errors on save
enabled in your IDE, commenting/uncommenting lines of code becomes tedious when punctuation gets added.How has this been tested?
There are ESLint tests that run against this rule.
To test this, you may also add a comment to a JavaScript file such as
// My comment without punctuation
and ensure that ESLint reports this as an error.Screenshots
Types of changes
New feature/build tools modification
Checklist:
*.native.js
files for terms that need renaming or removal).