forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to set
StyleGuideBaseURL
per department
### 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.
- Loading branch information
Showing
6 changed files
with
55 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters