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

Add Rules to config/default.yml #6

Merged
merged 1 commit into from
Mar 26, 2024
Merged

Conversation

hoshinotsuyoshi
Copy link
Collaborator

@hoshinotsuyoshi hoshinotsuyoshi commented Mar 26, 2024

To avoid warning Warning: Grep/Grep does not support Rules parameter.

Problem: warning message

$ bundle exec rubocop
Warning: Grep/Grep does not support Rules parameter.

Supported parameters are:

  - Enabled

Inspecting 1 file
.

1 file inspected, no offenses detected

Detail

This warning originates from the following section of rubocop/rubocop:

https://github.com/rubocop/rubocop/blob/f9b3b1ed1ddb6129cd5bf7c16824261041f107d5/lib/rubocop/config_validator.rb#L179-L204

    def each_invalid_parameter(cop_name)
      default_config = ConfigLoader.default_configuration[cop_name]

      @config[cop_name].each_key do |param|
        next if COMMON_PARAMS.include?(param) || default_config.key?(param)

        supported_params = default_config.keys - INTERNAL_PARAMS

        yield param, supported_params
      end
    end

Focusing on the default_config.key?(param) part, it seems that if the parameter in question exists in the default config (config/default.yml of each gem), the warning display can be prevented.

Looking at how other gems handle this:

According to the comment in rubocop-grep at

# The original code is from https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb

 # The original code is from https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb

The lib/rubocop/grep/inject.rb is utilizing lib/rubocop/rspec/inject.rb from rubocop-rspec.

Rubocop-rspec defines additional parameters for each cop in config/default.yml.

For example, the RSpec/Dialect has an additional parameter named PreferredMethods:

https://github.com/rubocop/rubocop-rspec/blob/ecd945f5e49b6006c2a7f314d7570ed449afc6dc/config/default.yml#L301

RSpec/Dialect:
  Description: Enforces custom RSpec dialects.
  Enabled: false
  PreferredMethods: {}
  VersionAdded: '1.33'
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Dialect

Therefore, I considered resolving this by adding Rules as an additional parameter, similar to PreferredMethods: {}.

Avoid `Warning: Grep/Grep does not support Rules parameter.`
@hoshinotsuyoshi hoshinotsuyoshi self-assigned this Mar 26, 2024
@hoshinotsuyoshi hoshinotsuyoshi marked this pull request as ready for review March 26, 2024 00:45
@hoshinotsuyoshi hoshinotsuyoshi merged commit e750001 into dev Mar 26, 2024
3 checks passed
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.

1 participant