-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Make it possible to set StyleGuideBaseURL per department #7295
Conversation
06ec0b4
to
9bf9e21
Compare
I like that approach, but I think we should also mention it somewhere in the documentation. |
CHANGELOG.md
Outdated
@@ -5,6 +5,7 @@ | |||
### New features | |||
|
|||
* [#7274](https://github.com/rubocop-hq/rubocop/issues/7274): Add new `Lint/SendWithMixinArgument` cop. ([@koic][]) | |||
* [#7295](https://github.com/rubocop-hq/rubocop/pull/7295): Add a plugin for `StyleGuideBaseURL`. ([@koic][]) |
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.
I think calling this a plugin
might be a bit misleading - something like "Make it possible to set StyleGuideBaseURL
per department." sounds better to me.
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.
Thanks for your review. I update it.
StyleGuideBaseURL
9bf9e21
to
d5f1483
Compare
I tried adding a document about this. |
### Summary Resolves rubocop/rubocop-rails#107 and follow up rubocop/rubocop-rails#109 (comment). This PR makes it possible to set a style guide URL (`StyleGuideBaseURL`) for each department. For example, RuboCop Rails gem (Rails department) supports The Rails Style Guide. In that case, set .rubocop.yml as follows. ```yaml # .rubocop.yml require: - rubocop-rails AllCops: StyleGuideBaseURL: https://rubystyle.guide Rails: StyleGuideBaseURL: https://rails.rubystyle.guide ``` In practice `Rails: StyleGuideBaseURL: https://rails.rubystyle.guide` will be set in config/default.yml of rubocop-rails. ```console % cat example.rb # frozen_string_literal: true time = Time.new ``` ```console % bundle exec rubocop --display-style-guide example.rb Inspecting 1 file W Offenses: example.rb:3:1: W: Lint/UselessAssignment: Useless assignment to variable - time. (https://rubystyle.guide#underscore-unused-vars) time = Time.new ^^^^ example.rb:3:13: C: Rails/TimeZone: Do not use Time.new without zone. Use one of Time.zone.now, Time.current, Time.new.in_time_zone, Time.new.utc, Time.new.getlocal, Time.new.xmlschema, Time.new.iso8601, Time.new.jisx0301, Time.new.rfc3339, Time.new.httpdate, Time.new.to_i, Time.new.to_f instead. (https://rails.rubystyle.guide#time, http://danilenko.org/2012/7/6/rails_timezones) time = Time.new ^^^ 1 file inspected, 2 offenses detected ``` The style guide URLs set for each department is displayed. - https://rubystyle.guide#underscore-unused-vars for `Lint/UselessAssignment` cop - https://rails.rubystyle.guide#time for for `Rails/TimeZone` cop So `AllCops` style guide URL is used when there is no style guide URL for a specific department. ### Other Information Note that tasks/cops_documentation.rake will require the following patch: ```diff diff --git a/tasks/cops_documentation.rake b/tasks/cops_documentation.rake index bd93ffe31..751222fcb 100644 --- a/tasks/cops_documentation.rake +++ b/tasks/cops_documentation.rake @@ -155,7 +155,9 @@ task generate_cops_documentation: :yard_for_generate_documentation do def references(config, cop) cop_config = config.for_cop(cop) - urls = RuboCop::Cop::MessageAnnotator.new(config, cop_config, {}).urls + urls = RuboCop::Cop::MessageAnnotator.new( + config, cop.name, cop_config, {} + ).urls return '' if urls.empty? content = h3('References') ``` AFAIK, rubocop-performance, rubocop-rails, rubocop-rspec, and rubocop-minitest repositories are targeted.
d5f1483
to
bf67a9e
Compare
Great work! Thanks! |
Follow up rubocop/rubocop#7295. This commit fixes the following error. ```console % bundle exec rake The `SafeMode` option will be removed in `RuboCop` 0.76. Please update `rubocop-performance` to 1.15.0 or higher. Files: 25 Modules: 3 ( 3 undocumented) Classes: 26 ( 0 undocumented) Constants: 50 ( 45 undocumented) Attributes: 0 ( 0 undocumented) Methods: 53 ( 47 undocumented) 28.03% documented rake aborted! ArgumentError: wrong number of arguments (given 3, expected 4) tasks/cops_documentation.rake:154:in `new' tasks/cops_documentation.rake:154:in `references' tasks/cops_documentation.rake:24:in `cops_body' tasks/cops_documentation.rake:197:in `print_cop_with_doc' tasks/cops_documentation.rake:173:in `block in print_cops_of_department' tasks/cops_documentation.rake:172:in `each' tasks/cops_documentation.rake:172:in `print_cops_of_department' tasks/cops_documentation.rake:268:in `block in main' tasks/cops_documentation.rake:267:in `each' tasks/cops_documentation.rake:267:in `main' tasks/cops_documentation.rake:278:in `block in <top (required)>' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `load' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Tasks: TOP => default => generate_cops_documentation (See full trace by running task with --trace) ```
Follow rubocop/rubocop#7295 This commit fixes the following error. ```console % bundle exec rake Files: 1 Modules: 3 ( 3 undocumented) Classes: 1 ( 0 undocumented) Constants: 1 ( 1 undocumented) Attributes: 0 ( 0 undocumented) Methods: 2 ( 2 undocumented) 14.29% documented rake aborted! ArgumentError: wrong number of arguments (given 3, expected 4) tasks/cops_documentation.rake:156:in `new' tasks/cops_documentation.rake:156:in `references' tasks/cops_documentation.rake:24:in `cops_body' tasks/cops_documentation.rake:197:in `print_cop_with_doc' tasks/cops_documentation.rake:173:in `block in print_cops_of_department' tasks/cops_documentation.rake:172:in `each' tasks/cops_documentation.rake:172:in `print_cops_of_department' tasks/cops_documentation.rake:268:in `block in main' tasks/cops_documentation.rake:267:in `each' tasks/cops_documentation.rake:267:in `main' tasks/cops_documentation.rake:278:in `block in <top (required)>' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `load' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Tasks: TOP => default => generate_cops_documentation (See full trace by running task with --trace) ```
Follow rubocop/rubocop#7295 This commit fixes the following error. ```console % bundle exec rake Files: 1 Modules: 3 ( 3 undocumented) Classes: 1 ( 0 undocumented) Constants: 1 ( 1 undocumented) Attributes: 0 ( 0 undocumented) Methods: 2 ( 2 undocumented) 14.29% documented rake aborted! ArgumentError: wrong number of arguments (given 3, expected 4) tasks/cops_documentation.rake:156:in `new' tasks/cops_documentation.rake:156:in `references' tasks/cops_documentation.rake:24:in `cops_body' tasks/cops_documentation.rake:197:in `print_cop_with_doc' tasks/cops_documentation.rake:173:in `block in print_cops_of_department' tasks/cops_documentation.rake:172:in `each' tasks/cops_documentation.rake:172:in `print_cops_of_department' tasks/cops_documentation.rake:268:in `block in main' tasks/cops_documentation.rake:267:in `each' tasks/cops_documentation.rake:267:in `main' tasks/cops_documentation.rake:278:in `block in <top (required)>' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `load' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Tasks: TOP => default => generate_cops_documentation (See full trace by running task with --trace) ```
Follow up rubocop/rubocop#7295. This commit fixes the following error. ```console % bundle exec rake The `SafeMode` option will be removed in `RuboCop` 0.76. Please update `rubocop-performance` to 1.15.0 or higher. Files: 25 Modules: 3 ( 3 undocumented) Classes: 26 ( 0 undocumented) Constants: 50 ( 45 undocumented) Attributes: 0 ( 0 undocumented) Methods: 53 ( 47 undocumented) 28.03% documented rake aborted! ArgumentError: wrong number of arguments (given 3, expected 4) tasks/cops_documentation.rake:154:in `new' tasks/cops_documentation.rake:154:in `references' tasks/cops_documentation.rake:24:in `cops_body' tasks/cops_documentation.rake:197:in `print_cop_with_doc' tasks/cops_documentation.rake:173:in `block in print_cops_of_department' tasks/cops_documentation.rake:172:in `each' tasks/cops_documentation.rake:172:in `print_cops_of_department' tasks/cops_documentation.rake:268:in `block in main' tasks/cops_documentation.rake:267:in `each' tasks/cops_documentation.rake:267:in `main' tasks/cops_documentation.rake:278:in `block in <top (required)>' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `load' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Tasks: TOP => default => generate_cops_documentation (See full trace by running task with --trace) ```
Follow up rubocop/rubocop#7295. This commit fixes the following error. ```console % bundle exec rake The `SafeMode` option will be removed in `RuboCop` 0.76. Please update `rubocop-performance` to 1.15.0 or higher. Files: 25 Modules: 3 ( 3 undocumented) Classes: 26 ( 0 undocumented) Constants: 50 ( 45 undocumented) Attributes: 0 ( 0 undocumented) Methods: 53 ( 47 undocumented) 28.03% documented rake aborted! ArgumentError: wrong number of arguments (given 3, expected 4) tasks/cops_documentation.rake:154:in `new' tasks/cops_documentation.rake:154:in `references' tasks/cops_documentation.rake:24:in `cops_body' tasks/cops_documentation.rake:197:in `print_cop_with_doc' tasks/cops_documentation.rake:173:in `block in print_cops_of_department' tasks/cops_documentation.rake:172:in `each' tasks/cops_documentation.rake:172:in `print_cops_of_department' tasks/cops_documentation.rake:268:in `block in main' tasks/cops_documentation.rake:267:in `each' tasks/cops_documentation.rake:267:in `main' tasks/cops_documentation.rake:278:in `block in <top (required)>' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `load' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Tasks: TOP => default => generate_cops_documentation (See full trace by running task with --trace) ```
Follow up rubocop/rubocop#7295. This commit fixes the following error. ```console % bundle exec rake The `SafeMode` option will be removed in `RuboCop` 0.76. Please update `rubocop-performance` to 1.15.0 or higher. Files: 25 Modules: 3 ( 3 undocumented) Classes: 26 ( 0 undocumented) Constants: 50 ( 45 undocumented) Attributes: 0 ( 0 undocumented) Methods: 53 ( 47 undocumented) 28.03% documented rake aborted! ArgumentError: wrong number of arguments (given 3, expected 4) tasks/cops_documentation.rake:154:in `new' tasks/cops_documentation.rake:154:in `references' tasks/cops_documentation.rake:24:in `cops_body' tasks/cops_documentation.rake:197:in `print_cop_with_doc' tasks/cops_documentation.rake:173:in `block in print_cops_of_department' tasks/cops_documentation.rake:172:in `each' tasks/cops_documentation.rake:172:in `print_cops_of_department' tasks/cops_documentation.rake:268:in `block in main' tasks/cops_documentation.rake:267:in `each' tasks/cops_documentation.rake:267:in `main' tasks/cops_documentation.rake:278:in `block in <top (required)>' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `load' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Tasks: TOP => default => generate_cops_documentation (See full trace by running task with --trace) ```
Follow up rubocop/rubocop#7295. This commit fixes the following error. ```console % bundle exec rake The `SafeMode` option will be removed in `RuboCop` 0.76. Please update `rubocop-performance` to 1.15.0 or higher. Files: 25 Modules: 3 ( 3 undocumented) Classes: 26 ( 0 undocumented) Constants: 50 ( 45 undocumented) Attributes: 0 ( 0 undocumented) Methods: 53 ( 47 undocumented) 28.03% documented rake aborted! ArgumentError: wrong number of arguments (given 3, expected 4) tasks/cops_documentation.rake:154:in `new' tasks/cops_documentation.rake:154:in `references' tasks/cops_documentation.rake:24:in `cops_body' tasks/cops_documentation.rake:197:in `print_cop_with_doc' tasks/cops_documentation.rake:173:in `block in print_cops_of_department' tasks/cops_documentation.rake:172:in `each' tasks/cops_documentation.rake:172:in `print_cops_of_department' tasks/cops_documentation.rake:268:in `block in main' tasks/cops_documentation.rake:267:in `each' tasks/cops_documentation.rake:267:in `main' tasks/cops_documentation.rake:278:in `block in <top (required)>' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `load' /Users/koic/.rbenv/versions/2.6.3/bin/bundle:23:in `<main>' Tasks: TOP => default => generate_cops_documentation (See full trace by running task with --trace) ```
Summary
Resolves rubocop/rubocop-rails#107 and follow up rubocop/rubocop-rails#109 (comment).
This PR makes it possible to set a style guide URL (
StyleGuideBaseURL
) for each department.For example, RuboCop Rails gem (Rails department) supports The Rails Style Guide. In that case, set .rubocop.yml as follows.
In practice
Rails: StyleGuideBaseURL: https://rails.rubystyle.guide
will be set in config/default.yml of rubocop-rails.The style guide URLs set for each department is displayed.
Lint/UselessAssignment
copRails/TimeZone
copSo
AllCops
style guide URL is used when there is no style guide URL for a specific department.Other Information
Note that tasks/cops_documentation.rake will require the following patch:
AFAIK, rubocop-performance, rubocop-rails, rubocop-rspec, and rubocop-minitest repositories are targeted.
/cc @bquorning
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.