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 option to show cops disabed by inline comments #900
add option to show cops disabed by inline comments #900
Conversation
You've added reporting outside of the formatter classes, and I see some problems with that. For example, you can' get this information in JSON format ( |
Yeah, I thought about adding formatter support, but was hesitant since those seem designed for offenses. I don't think this should go in as a cop, as it's not really an offense (and how would you disable it inline?). Agree though, that this needs to be added to the JSON formatter (think it would make sense in the summary object) and I'll append with support for it tonight. As for the rest of the formatters, they don't seem to support summary stats so maybe this info just isn't part of those formatters directly. In the current implementation it should still be printed to the output. (IE the fuubar formatter would do the nice progress bar =======> then afterwards it would print the ignored cops). Workable compromise? |
Yeah, if that cop is disabled inline there's a risk that RuboCop implodes and erases itself from disk. I should have thought of that. 😉 I hope @bbatsov and @yujinakayama can offer their opinions on the matter. I still think a cop is a less intrusive solution. |
I'm not overly fond of the cop idea, because this cop should be disabled by default and currently disabled cops can't be run with Generally I like more the |
An optional idea: When I think this would solve the issue about mixed outputs and also allows you to just check the disabled lines without waiting for long running cop inspection. What do you think? |
That could work, but I would imagine the most common use-case for this would be in a CI report in which case you'd run both of them together anyway. Since the JSON formatter is the only one really effected by this (since the JSON is presumably parsed so the extra text at the end wouldn't work) why don't I just add support for that formatter? |
Okay, I moved the summary into the formatters. It does feel better in there, as just dumping the text at the end would potentially choke clients consuming the JSON formatter. That said, the formatters don't lend themselves to extension and I had alter the base formatter's signature like so: # @api public
#
# Invoked after all files are inspected, or interrupted by user.
#
# @param inspected_files [Array(String)]
# the inspected file paths.
# This would be same as `target_files` passed to `#started`
# unless RuboCop is interrupted by user.
# @param summary [Hash]
# optional meta information about the completed run.
# @return [void]
def finished(inspected_files, summary = {})
end Since this is a breaking change to the public API, maybe we can go with my previous commit and save this for v.19? That said, maybe consider adding a splat to the end of the base formatter methods to facilitate future extensions without breaking consumers? What's everyone think? |
@@ -20,6 +20,11 @@ def cop_enabled_at_line?(cop, line_number) | |||
disabled_line_ranges.none? { |range| range.include?(line_number) } | |||
end | |||
|
|||
def disabled_line_ranges | |||
disabled = @cop_disabled_line_ranges || {} | |||
disabled.select { |key, value| value.any? } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key -> _key
@yujinakayama It'd be nice if we checked for unused block arguments.
I'm not sure I like the addition of the |
It was said in rubocop#900 that it is a bug for --only to not enable the cop.
|
||
AllCops: | ||
Excludes: | ||
- vendor/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh? What's this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, (I bundle locally so without it the spec's try and analyze every gem's files). Will fix.
I think this feature is a good idea, but I don't like how its addition requires so many changes in the core logic. A new cop is the way to go. We could do a little bit of hard-coding in |
I agree, the current implementation adds too much complexity for a feature. Here's my idea I finally figured out:
|
👍 for @yujinakayama's idea |
I like it. I'll make the changes tonight. |
Ok, here's a first-pass at @yujinakayama's suggestion. What's everyone think? |
@@ -13,6 +13,7 @@ def initialize(cop_classes, config, options = nil) | |||
@config = config | |||
@options = options || { auto_correct: false, debug: false } | |||
@errors = [] | |||
@cops_disabled_in_comments = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Will fix tonight.
@@ -102,8 +103,7 @@ def add_flags_with_optional_args(opts) | |||
|
|||
def add_boolean_flags(opts) | |||
option(opts, '-d', '--debug', 'Display debug info.') | |||
option(opts, | |||
'-D', '--display-cop-names', | |||
option(opts, '-D', '--display-cop-names', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not include unrelated changes to the commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this was a holdover from the previous take which had an added option.
Think I got all of @yujinakayama's suggestions in there, but I'm sure a second set of eyes will prove otherwise. 😏 |
The build is broken. |
Heh, jruby always seems to get me. I may need to do a push disabling the global rescue in cli.rb so Travis can show me the error, since I don't have jruby locally, but regardless, I'll get this resolved. |
@@ -4,6 +4,7 @@ | |||
|
|||
module Rubocop | |||
# This class handles command line options. | |||
# rubocop:disable ClassLength |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please increment the max class length in .rubocop-todo.yml
rather than disabling.
Nope, I have nothing to add to your comments. |
@@ -17,4 +17,4 @@ CyclomaticComplexity: | |||
# Offense count: 105 | |||
# Configuration parameters: CountComments. | |||
MethodLength: | |||
Max: 22 | |||
Max: 22 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you've removed the last newline in the file? No big deal, but it does seem a bit odd.
I only had one tiny remark. And I'm still moping over our choice of formatter rather than cop solution. 😄 No, that's alright. |
Think that fixes the rbx/jruby errors, @yujinakayama's catches, and even adds back in the missing line for @jonas054. 😄 |
@fshowalter Please, rebase this on top of the current |
Rebased. Last chance @jonas054 😉 |
No, I've had my chances. 😄 Godspeed, young Showalter! |
…ments add option to show cops disabed by inline comments
Sometimes its tempting for developers, especially juniors who may have trouble understanding some of RuboCop's warnings, to abuse the
# rubocop:disable
functionality. This pull request adds an option (-x
or--show-disabled
) that, after a run, prints a list of all the files, line ranges and corresponding cops that were ignored during the run due to# rubocop:disable
comments.