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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that disable comments can include a descriptive comment #11590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bensheldon
Copy link

Updates the documentation to reflect that disabling comments can include descriptive text after the cop name. This feature was introduced in #3191 and as far as I can tell is still supported.

This is only a documentation update, I'll do my best to pick the relevant tasks below 馃檱馃徎


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@@ -739,11 +739,11 @@ Running `rubocop --autocorrect --disable-uncorrectable` will
create comments to disable all offenses that can't be automatically
corrected.

Do not write anything other than cop name in the disabling comment. E.g.:
Add a comment to explain why the cop has been disabled E.g.:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change the wording to something like "You can also...", so it sounds like a suggestion. I think you removed the . before e.g. by accident.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃憤馃徎 I updated the language to be You can also include... and re-added the period.

@bensheldon
Copy link
Author

@bbatsov I did some more digging into the git history and learned that the documentation I'm updating is actually much more recent than expected. It was introduced in 2020: #7995, whereas the behavior to allow the descriptive text was introduced in 2016.

Am I being accurate that disabling comments are intended to accept an additional "reason/comment"?

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 18, 2023

Yeah, it seems that actually that's not really supported. My bad. I keep forgetting how certain features work. @koic can add more on the topic I guess.

@koic
Copy link
Member

koic commented Feb 22, 2023

#7993 was misdetecting comments as cop name, #7995 fixes that.

Perhaps I wanted to be told about not recommending any description other than cop name. So, it can be written free text comment on the same line, but it is not recommended. It's probably better to write it on a separate line.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 22, 2023

@koic Agreed.

@bensheldon
Copy link
Author

So, it can be written free text comment on the same line, but it is not recommended. It's probably better to write it on a separate line.

That sounds like it is a supported feature, but not recommended (very Rubocop-y 馃槃 ). I can try to capture that in the documentation.

Is the reason purely that it's prone-to-breakage?

I think the trailing reason comment is very useful to have on the same-line (it's visually closest to the code being commented; it could be removed via Lint/UnneededDisable; it could be parsed/reported). So I like it as a feature, but I also trust you all if you don't think it's possible to support it.

I see two options and I'd like your advice:

  • Capture in the documentation that it is a feature, but it's not recommended because it's easy to mess up the parsing. I can also add some tests and attempt to make it less breakable and better define what is acceptable syntax.
  • Close this PR because ultimately it's not a supported feature.

Thanks for chatting through this with me!

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 27, 2023

Is the reason purely that it's prone-to-breakage?

For me the main problem is that this makes sense only for a single cop/department being listed on the line, but what happens if you have several? And obviously it's easier to parse the directive contents if you know there's no free-form text somewhere in there.

I do get your point, however, and I wonder what's the best approach in general. Normally I put some explanatory comments before directives and that seems fine to me overall.

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

Successfully merging this pull request may close these issues.

None yet

3 participants