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

Fix incorrect documentation URLs when using rubocop --show-docs-url #756

Merged
merged 1 commit into from Aug 24, 2022

Conversation

r7kamura
Copy link
Contributor

Added DocumentationBaseURL for rubocop --show-docs-url [COP1,COP2,...] command to work correctly for rubocop-rails cops.

Before

$ bundle exec rubocop --show-docs-url Rails/ActionControllerTestCase
https://docs.rubocop.org/rubocop/cops_rails.html#railsactioncontrollertestcase

After

$ bundle exec rubocop --show-docs-url Rails/ActionControllerTestCase
https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsactioncontrollertestcase

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@koic
Copy link
Member

koic commented Aug 24, 2022

Can you solve the following issue? This should apply to each different base URL.

% bundle exec rubocop --show-docs-url Rails/ActionControllerTestCase,Layout/ArgumentAlignment,RSpec/Be
https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsactioncontrollertestcase
https://docs.rubocop.org/rubocop-rails/cops_layout.html#layoutargumentalignment
https://docs.rubocop.org/rubocop-rails/cops_rspec.html#rspecbe

@r7kamura
Copy link
Contributor Author

So the existing implementation of the rubocop gem about DocumentationBaseURL is actually broken and this is a feature that should not currently be used until it is fixed?

If it looks like something can be easily fixed, I will try to work on that issue on rubocop gem.

@koic
Copy link
Member

koic commented Aug 24, 2022

this is a feature that should not currently be used until it is fixed?

It can be imagined that major 3rd party cop gem users will encounter this confusion with this upstream change. So these PRs should not be merged until the issue is resolved.

@@ -10,6 +10,7 @@ AllCops:
# Exclude db/schema.rb and db/[CONFIGURATION_NAMESPACE]_schema.rb by default.
# See: https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
- db/*schema.rb
DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@koic Oh, my mistake, I meant to define Rails.DocumentationBaseURL, but I had defined AllCops.DocumentationBaseURL. Maybe this will fix that problem

Copy link
Member

Choose a reason for hiding this comment

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

Great! Can you add a changelog entry?

@r7kamura
Copy link
Contributor Author

I have confirmed that it works well after adding bug fix at 971e509.

$ bundle exec rubocop --show-docs-url Rails/ActionControllerTestCase,Layout/ArgumentAlignment,RSpec/Be
https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsactioncontrollertestcase
https://docs.rubocop.org/rubocop/cops_layout.html#layoutargumentalignment
https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecbe

I'll squash the commits.

@r7kamura
Copy link
Contributor Author

So the existing implementation of the rubocop gem about DocumentationBaseURL is actually broken

It turns out that this was my misunderstanding after all, sorry for that. There was nothing wrong with the implementation of the rubocop gem.

I checked other related pull requests for the same bug, and they were also fine.

@koic
Copy link
Member

koic commented Aug 24, 2022

@r7kamura You've maybe overlooked the following :-)
#756 (comment)

@@ -0,0 +1 @@
* [#756](https://github.com/rubocop/rubocop-rails/pull/756): Add DocumentationBaseURL. ([@r7kamura][])
Copy link
Member

@koic koic Aug 24, 2022

Choose a reason for hiding this comment

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

How about the changelog entry for users like this:

Suggested change
* [#756](https://github.com/rubocop/rubocop-rails/pull/756): Add DocumentationBaseURL. ([@r7kamura][])
* [#756](https://github.com/rubocop/rubocop-rails/pull/756): Fix incorrect documentation base URL when using `rubocop --show-docs-url`. ([@r7kamura][])

And I think changelog/fix_add_documentationbaseurl.md is more appropriate than changelog/change_add_documentationbaseurl.md as the file name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point 🦀

I'll improve them also in the other related pull requests

@r7kamura r7kamura force-pushed the feature/url branch 2 times, most recently from 6a519e2 to 481eaea Compare August 24, 2022 02:15
@r7kamura r7kamura changed the title Add DocumentationBaseURL Fix incorrect documentation URLs when using rubocop --show-docs-url Aug 24, 2022
@koic
Copy link
Member

koic commented Aug 24, 2022

@r7kamura I checked locally and got the following warning. Can you investigate?

% bundle exec rubocop --show-docs-url Rails/ActionControllerTestCase,Layout/ArgumentAlignment,RSpec/Be
Warning: Rails does not support Enabled parameter.

Supported parameters are:

  - DocumentationBaseURL

https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsactioncontrollertestcase
https://docs.rubocop.org/rubocop/cops_layout.html#layoutargumentalignment
https://docs.rubocop.org/rubocop/cops_rspec.html#rspecbe

@koic
Copy link
Member

koic commented Aug 24, 2022

I also checked without options.

% bundle exec rubocop
Warning: Rails does not support Enabled parameter.

Supported parameters are:

  - DocumentationBaseURL

Inspecting 267 files
...........................................................................................................................................................................................................................................................................

267 files inspected, no offenses detected

@r7kamura
Copy link
Contributor Author

r7kamura commented Aug 24, 2022

I tried it in a completely clean environment. This did nothing wrong and could not reproduce that warning.

$ tree -a .
.
├── .rubocop.yml
├── Gemfile
└── Gemfile.lock

0 directories, 3 files
/tmp/rubocop-url 
$ cat .rubocop.yml 
require:
  - rubocop-rails
  - rubocop-rspec

AllCops:
  NewCops: enable
/tmp/rubocop-url 
$ cat Gemfile
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rubocop'
gem 'rubocop-rails', github: 'r7kamura/rubocop-rails', branch: 'feature/url'
gem 'rubocop-rspec', github: 'r7kamura/rubocop-rspec', branch: 'feature/url'
/tmp/rubocop-url 
$ bundle exec rubocop --show-docs-url Rails/ActionControllerTestCase,Layout/ArgumentAlignment,RSpec/Be
https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsactioncontrollertestcase
https://docs.rubocop.org/rubocop/cops_layout.html#layoutargumentalignment
https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecbe

I wondered if you might have added some settings to .rubocop.yml in your environment, so I made the following changes.

diff --git a/.rubocop.yml b/.rubocop.yml
index de58178..c1e1f37 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -4,3 +4,6 @@ require:
 
 AllCops:
   NewCops: enable
+
+Rails:
+  Enabled: true

Then the warning appeared.

$ bundle exec rubocop --show-docs-url Rails/ActionControllerTestCase,Layout/ArgumentAlignment,RSpec/Be
Warning: Rails does not support Enabled parameter.

Supported parameters are:

  - DocumentationBaseURL

https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsactioncontrollertestcase
https://docs.rubocop.org/rubocop/cops_layout.html#layoutargumentalignment
https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecbe

I think this is very similar to the following issue.

I will try to solve this by adding Enabled: true (or maybe Enabled: false ... or Enabled: ?) to the department section in config/default.yml.

@koic
Copy link
Member

koic commented Aug 24, 2022

I think this is very similar to the following issue.

Sure, this seems to solve the issue.

diff --git a/config/default.yml b/config/default.yml
index 2a8e141ce..3d8f29635 100644
--- a/config/default.yml
+++ b/config/default.yml
@@ -10,7 +10,6 @@ AllCops:
     # Exclude db/schema.rb and db/[CONFIGURATION_NAMESPACE]_schema.rb by default.
     # See: https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
     - db/*schema.rb
   # Enable checking Active Support extensions.
   # See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions
   ActiveSupportExtensionsEnabled: true
@@ -23,6 +22,10 @@ AllCops:
   # as the default.
   TargetRailsVersion: ~

 Rails:
+  Enabled: true
   DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails

 Lint/NumberConversion:
   # Add Rails' duration methods to the ignore list for `Lint/NumberConversion`
   # so that calling `to_i` on one of these does not register an offense.

DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
Enabled: true
Copy link
Member

Choose a reason for hiding this comment

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

Can you tweak it? Enabled is probably a more important parameter than DocumentationBaseURL.

Suggested change
DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
Enabled: true
Enabled: true
DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails

@koic koic merged commit 6fc6d22 into rubocop:master Aug 24, 2022
@koic
Copy link
Member

koic commented Aug 24, 2022

Thanks!

@r7kamura r7kamura deleted the feature/url branch August 24, 2022 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants