-
-
Notifications
You must be signed in to change notification settings - Fork 264
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
[Fix #107] Fix style guide URLs #109
Conversation
Hmm, maybe we should come up with a way for plugins to provide their own base url as well, so we can avoid this repetition? |
My explanation was lacking. This PR is a workaround patch. So I prepared this PR that workaround patch because release cycle is different between RuboCop core and RuboCop Rails. This patch can be released independently of RuboCop core. |
Understood. Thanks for the extra details! |
### 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.
Fixes rubocop#107. This PR fixes style guide URLs when specifying `rubocop --display-style-guide` option. The following is an execution using RuboCop Rails. ```console % bundle exec rubocop --display-style-guide --only Style/StringLiterals Inspecting 2 files C. Offenses: Gemfile:3:8: C: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://rails.rubystyle.guide#consistent-string-literals) source "https://rubygems.org" ^^^^^^^^^^^^^^^^^^^^^^ 2 files inspected, 1 offense detected ``` The correct URL is `https://rubystyle.guide#consistent-string-literals` instead of `https://rails.rubystyle.guide#consistent-string-literals`.
9b802df
to
0092e77
Compare
### 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.
Fixes #107.
This PR fixes style guide URLs when specifying
rubocop --display-style-guide
option.The following is an execution using RuboCop Rails.
The correct URL is
https://rubystyle.guide#consistent-string-literals
instead ofhttps://rails.rubystyle.guide#consistent-string-literals
.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.