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

YARD-style directives #12705

Open
pointlessone opened this issue Feb 20, 2024 · 4 comments
Open

YARD-style directives #12705

pointlessone opened this issue Feb 20, 2024 · 4 comments

Comments

@pointlessone
Copy link
Contributor

pointlessone commented Feb 20, 2024

Is your feature request related to a problem? Please describe.

YARD doesn't provide any way to ignore comments. So a common case of wrapping a method in rubocop: disable...rubocop: enable ends up with the directive in the docs.

Describe the solution you'd like

I propose to add YARD-style directive syntax.

# Method docs go here.
# @rubocop disable Metrics/PerceivedComplexity
def create_apple_pie_from_scratch
  # ...
end
# @rubocop enable Metrics/PerceivedComplexity

This way YARD would treat it as a tag. By default the tag and its content wouldn't rendered.

We can keep the colon. It would be enough to only add an optional @ before rubocop to make it work.

Considered alternative

# @rubocop
#   rubocop: disable Metrics/PerceivedComplexity

This seem to work but looks like an obvious hack.

@jonas054
Copy link
Collaborator

jonas054 commented Feb 27, 2024

Although I find this idea reasonable, I want to mention a couple more alternatives for your consideration.

  1. Disable above the documentation comment.
# rubocop:disable Metrics/PerceivedComplexity

# Method docs go here.
def create_apple_pie_from_scratch
  # ...
end
# rubocop:enable Metrics/PerceivedComplexity
  1. Use an end-of-line comment to disable.
# Method docs go here.
def create_apple_pie_from_scratch # rubocop:disable Metrics/PerceivedComplexity
  # ...
end

Each of these has its own drawbacks, but maybe they are good enough to motivate not changing anything in the implementation of disable comments?

@pointlessone
Copy link
Contributor Author

pointlessone commented Feb 27, 2024

1 is an option. It seem to work. Visually it looks like the scope it a bit wider though. There's also potential of new code added in the gap even if small.

2 I must've a weird config or I did something wrong because that one get's me Style/CommentedKeyword violation.

I totally understand why not changing things is preferred. I just wish we as a broader Ruby community settled on some common directive syntax. More and more tools use custom syntax to add meaning to semantically inert comments and it's hard to make them all compatible and play well together if you have to use more than one at a time. It fast becomes like one of those "100 languages in one file" programs.

@pointlessone
Copy link
Contributor Author

Update: Apparently, Style/CommentedKeyword doesn't allow a space after colon. So even within RuboCop alone there's no coherent concept of a directive. 😔

@jonas054
Copy link
Collaborator

Ah yes, you're right. That's a bug in Style/CommentedKeyword. I will fix it.

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

No branches or pull requests

3 participants