Open spacebat opened 1 year ago
Hi @spacebat 👋
Thank you for your issue! I think that's a great idea. I'd even make this the default behaviour, and add a flag if we want to have the comments removed. Let me try that.
Hi @spacebat
Thank you again for reporting that issue. Moments ago I released https://github.com/lxxxvi/ruboclean/releases/tag/v0.4.0 that introduces the --preserve-comment
flag.
However, for the moment I was only able to implement to preserve preceding comments, not inline comments.
Please note that, against what I said earlier, this option is not the default. You have to explicitly provide it in order to keep the comments.
--preserve-comments
as an argument name implies to me that comments will remain completely untouched. Unfortunately it appears that's not the case.
--preceeding-comments-only
or --permit-preceeding-comments
feels more descriptive of the current behavior.
Count me in as an interested voicing in completely preserving comments as-is. Inline comments are way more useful for our rules than moving the comments up to the top of the cop block
Hi @tylerwillingham
Thank you for your comment! I agree, the flag name can be misleading, I like your proposal --permit-preceeding-comments
though. Would you be interested in changing it and opening a PR?
Regarding the inline comments:
The main reason why I haven't implemented it (yet) is because it actualyl seems to be quite difficult to do. The problem is that Psych ignores comments when parsing a YAML file, and therefore we'd have to implement some sort of a YAML parser ourselves in order to remember where comments came from. I'd like to avoid this. Let me know if you have ideas how to implement it.
It would be nice if ruboclean had a flag that would preserve comments immediately preceding a cop entry in .rubocop.yml, and any that are inline in the entry. We have a lot of comments in our config explaining why things are disabled and so on, and I'm hesitant to delete them.