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

Apply inherit_mode to Include and Exclude of AllCops #16

Merged

Conversation

pixta-yuki-ito
Copy link
Contributor

@pixta-yuki-ito pixta-yuki-ito commented Dec 3, 2019

Currently, the rubocop is working in pixta's repository with using configs and examples of pixta-rubocop. But it doesn't report problems when a code has problems.

Because from rubocop v0.56.0 it changed the behavior of AllCops/Include and AllCops/Exclude to the overriding way.
https://github.com/rubocop-hq/rubocop/blob/master/relnotes/v0.56.0.md#new-features

You can see this issue and pull request.
rubocop/rubocop#4247
rubocop/rubocop#5882

Oh my God... I will check that with using configs and examples of pixta-rubocop in a new rails v4.2.x project. I used this .rubocop.yml(Refer to README of pixta-rubocop).

inherit_from:
  - https://raw.githubusercontent.com/pixta-dev/pixta-rubocop/master/rubocop.yml

AllCops:
  TargetRubyVersion: 2.4
  Include:
    - '**/Rakefile'
    - '**/config.ru'
  Exclude:
    - 'Gemfile'
    - 'bin/*'
    - 'config/**/*'
    - 'db/**/*'
    - 'deploy/**/*'
    - 'vendor/**/*'

This one is the result. The target file is Rakefile and config.ru only. It can't use default configs of rubocop.

vagrant@ubuntu-bionic ~/s/g/p/rails-with-docker-compose ❯❯❯ rubocop -v
0.77.0
vagrant@ubuntu-bionic ~/s/g/h/rails-with-docker-compose ❯❯❯ rubocop --list-target-files                                                                                                                                                                                    ✘ 1
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for SingleLineMethods.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for Documentation.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for MultilineBlockChain.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for Lambda.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for ClassAndModuleChildren.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for FormatString.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for MethodLength.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for StringLiterals.
Warning: unrecognized cop Rails found in .rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml
Warning: unrecognized cop Rails found in .rubocop.yml
Rakefile
config.ru

We should fix that problem. Normally pixta-rubocop uses default configs of rubocop. But we customized some configs to PIXTA. So we also want to apply that mind to AllCops/Include and AllCops/Exclude. If that we can use inherit_mode. inherit_mode has two options merge and override.
https://docs.rubocop.org/en/stable/configuration/#merging-arrays-using-inherit_mode

In our case, we can specify inherit_mode/merge to AllCops/Include and AllCops/Exclude.

I also check that with using inherit_mode/merge.

inherit_from:
  - https://raw.githubusercontent.com/pixta-dev/pixta-rubocop/master/rubocop.yml

inherit_mode:
  merge:
    - Include
    - Exclude

AllCops:
  TargetRubyVersion: 2.4
  Include:
    - '**/Rakefile'
    - '**/config.ru'
  Exclude:
    - 'Gemfile'
    - 'bin/*'
    - 'config/**/*'
    - 'db/**/*'
    - 'deploy/**/*'
    - 'vendor/**/*'

# Allow Japanese comments
AsciiComments:
  Enabled: false

This one is the result. it works well 💯

vagrant@ubuntu-bionic ~/s/g/p/rails-with-docker-compose ❯❯❯ rubocop -v
0.77.0
vagrant@ubuntu-bionic ~/s/g/h/rails-with-docker-compose ❯❯❯ rubocop --list-target-files
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for SingleLineMethods.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for Documentation.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for MultilineBlockChain.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for Lambda.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for ClassAndModuleChildren.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for FormatString.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for MethodLength.
/home/vagrant/src/github.com-for-hamuyuuki/hamuyuuki/rails-with-docker-compose/.rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml: Warning: no department given for StringLiterals.
Warning: unrecognized cop Rails found in .rubocop-https---raw-githubusercontent-com-pixta-dev-pixta-rubocop-master-rubocop-yml
Warning: unrecognized cop Rails found in .rubocop.yml
Rakefile
app/controllers/application_controller.rb
app/helpers/application_helper.rb
config.ru
test/test_helper.rb

This PR changes README and examples in the pixta-rubocop. After this PR is LGTM, we need to apply that configs to pixta's repository.

AllCops:
TargetRubyVersion: TODO
Include:
- '**/Rakefile'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[FYI]
Because **/Rakefile includes in the default configs.

- '**/config.ru'
Exclude:
- 'Gemfile'
- 'bin/*'
- 'config/**/*'
- 'db/**/*'
- 'deploy/**/*'
- 'vendor/**/*'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[FYI]
Because vendor/**/* includes in the default configs.

@pixta-yuki-ito pixta-yuki-ito force-pushed the apply-inherit_mode-to-include-and-exclude-of-allcops branch from 9ed7051 to 83f9786 Compare December 5, 2019 06:34
Copy link

@k-tokitoh k-tokitoh left a comment

Choose a reason for hiding this comment

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

LGTM!

README.md Outdated
AllCops:
TargetRubyVersion: TODO
Include:
- '**/Rakefile'
- '**/config.ru'
Copy link

@k-tokitoh k-tokitoh Dec 5, 2019

Choose a reason for hiding this comment

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

[nits]
'**/config.ru' also seems listed in the default config. so it can be deleted, i think.
ref. https://github.com/rubocop-hq/rubocop/blob/c50e7473f8627dd276cb7656bcd1953cb74bb243/config/default.yml#L31

@pixta-yuki-ito pixta-yuki-ito merged commit 17cac4c into master Dec 5, 2019
@yasaichi yasaichi deleted the apply-inherit_mode-to-include-and-exclude-of-allcops branch January 9, 2020 15:30
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.

2 participants