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

--show-cops CLI option #395

Merged
merged 1 commit into from
Aug 14, 2013
Merged

--show-cops CLI option #395

merged 1 commit into from
Aug 14, 2013

Conversation

dirkbolte
Copy link
Contributor

When working with rubocop the last days I had issues to isolate cop names for either specifying them with --only or when adding a rubocop:disable comment.
For making this easier I thought about an option to list all available cops. The output is not pretty but it's a start.

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 27, 2013

I guess it would be nice if cops were displayed in categories - style, lint, rails.

@jonas054
Copy link
Collaborator

@dirkbolte Did you know that --debug shows the cop names together with the offence reports? Would that have solved your problem, or do you think --show-cops is better?

@yujinakayama
Copy link
Collaborator

👍 for this feature.

I've been thinking something like this too, since there's no list of available cops currently. Most users notice existence of each cop only when an offence is reported for their code for the first time.

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 27, 2013

This feature reminded me that it wouldn't be bad if all cops had some description we can show alongside their names.

@dirkbolte
Copy link
Contributor Author

@jonas054 I never tried --debug as I considered this for rubocop debug purposes only. Actually the cop output of --debug was something I intended to suggest as a next pull request.
The intention of this CLI option was to give a short overview of what is possible because otherwise, it is pretty hard to find the actual cops. So what about I extend the output to the following:

  • Add categories in display
  • Add descriptions
  • Show current config of each cop (enabled/disabled/settings)

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 27, 2013

The last bit will not be possible, since the enabled cops are calculated on a directory bases - unless we assume that with option we'll display the settings for the current directory (which is a reasonable suggestion).

As for the descriptions - I'd suggest you take them from default config file and add a DESCRIPTION constant to each method. Overall - I like your suggestions and probably a lot of people will find such functionality useful.

@jonas054
Copy link
Collaborator

@dirkbolte Sounds good! I have something that's been on my mind for a while. We have, or will have, these pieces of information related to each cop:

  1. The message from the cop. Implemented as a constant MSG or sometimes a method error_message.
  2. The description of the class in a comment. Used for generating documentation.
  3. The comment in the configuration files describing the cop.
  4. The DESCRIPTION constant that @bbatsov just mentioned.

Can we unify these and avoid duplication?

@dirkbolte
Copy link
Contributor Author

My first approach would be to use a DESCRIPTION constant as suggested, extract the first line as a short message for the display (to have a similar behavior as Yard). If this constant isn't set, no description would be printed (do we don't have to adjust all cops at once).
I hope this matches your idea and we have a common base by this.
Next to that I would add the active config if rubocop would run in this directory (and mark this in the output accordingly).
I will upload a possible implementation for this in the next days.

@dirkbolte
Copy link
Contributor Author

The last commit should contain all the features we talked about in this thread, although the code still looks a little ugly.

cops.categories.each { |cat| expect(@stdout).to include(cat) }
end

# it 'prints all cops in their right category' do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this part commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix that. Forgot to re-enable it.

Am 04.08.2013 um 21:53 schrieb Jonas Arvidsson [email protected]:

In spec/rubocop/cli_spec.rb:

  •    @stdout = $stdout.string
    
  •  end
    
  •  it 'prints all available cops and their description' do
    
  •    subject
    
  •    cops.each do |cop|
    
  •     expect(@stdout).to include cop.cop_name
    
  •     expect(@stdout).to include cop.short_description
    
  •   end
    
  •  end
    
  •  it 'prints all categories' do
    
  •    subject
    
  •    cops.categories.each { |cat| expect(@stdout).to include(cat) }
    
  •  end
    
    +# it 'prints all cops in their right category' do
    Why is this part commented out?


Reply to this email directly or view it on GitHub.

@dirkbolte
Copy link
Contributor Author

I added the changes and moved all comments in the default configs to 'Description'. Branch is rebased to upstream.

I also added a spec to ensure that all future cops have a description.

An issue with the implementation is that descriptions do not wrap cleanly at 80 characters when calling --show-cops.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 11, 2013

Seems to me you used some code that's available only in Ruby 2.0 since the build is failing for all other Rubies.

@@ -142,6 +143,8 @@
* New cop `EndBlock` tracks uses of `END` blocks.
* New cop `DotPosition` tracks the dot position in multi-line method calls.
* New cop `Attr` tracks uses of `Module#attr`.
* Add support for auto-correction of some offences with `-a`/`--auto-correct`.
* Added `--show-cops` option to show available cops.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this entry to the latest version of RuboCop, since 0.11.0 was already released.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 12, 2013

Looks good now. I've added some minor style remarks as inline comments in the code - address them, squash the commits into one and we're good to merge this.

@dirkbolte
Copy link
Contributor Author

Will do. Thanks for the feedback.

Am 12.08.2013 um 10:33 schrieb Bozhidar Batsov [email protected]:

Looks good now. I've added some minor style remarks as inline comments in the code - address them, squash the commits into one and we're good to merge this.


Reply to this email directly or view it on GitHub.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 14, 2013

The code looks OK now. Just don't forget to squash the commits together into one.

* added option to cli
* extended cop to get description out of configuration
* changed default configuration to have a description field for all cops
@dirkbolte
Copy link
Contributor Author

Hope that squash is ok. Thanks for the patience.

bbatsov added a commit that referenced this pull request Aug 14, 2013
@bbatsov bbatsov merged commit 25bc0f1 into rubocop:master Aug 14, 2013
@bbatsov
Copy link
Collaborator

bbatsov commented Aug 14, 2013

You're welcome :-)

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

Successfully merging this pull request may close these issues.

4 participants