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

Change command for the rake task with arguments to a style that can also be used in zsh #10695

Merged
merged 1 commit into from
Jun 6, 2022

Conversation

ydah
Copy link
Member

@ydah ydah commented Jun 5, 2022

If you try to add a new cop and use the wrong command in the rake task, you will get the following warning.

bundle exec rake new_cop                                     
usage: bundle exec rake new_cop[Department/Name]

If you try to execute it as is, you will face the following error.

bundle exec rake new_cop[Department/Name]
zsh: no matches found: new_cop[Department/Name]

#10695 (comment)

As noted in the documentation, it should be in a format that can be executed by zsh by enclosing it in single quotation marks.


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.

@ydah ydah marked this pull request as ready for review June 5, 2022 22:48
@koic
Copy link
Member

koic commented Jun 6, 2022

Hm, I wonder whether this makes sense because it depends on the user's shell and its settings. The effects other than zsh are unknown, and it is an unnecessary escape if zsh also uses noglob.

@ydah
Copy link
Member Author

ydah commented Jun 6, 2022

It certainly depends on the user's shell and its settings, but there are cases where it doesn't work, so it seems like there should be a good expression that works reasonably well in any environment. (would a better expression than this escape look good?)

Another way to make it readable in zsh is to put it in quotation marks:

bundle exec rake new_cop
usage: bundle exec rake 'new_cop[Department/Name]'

@koic
Copy link
Member

koic commented Jun 6, 2022

I'm not sure what happens to the developers of bash, fish, and others.

@ydah
Copy link
Member Author

ydah commented Jun 6, 2022

Certainly, I should have checked if it works in other shells. Sorry.
I have performed the following checks and at least the 'new_cop[Foo/Bar]' format appears to work.

> fish -v
fish, version 3.4.1
> bundle exec rake 'new_cop[Department/Name]'
[create] lib/rubocop/cop/department/name.rb
[create] spec/rubocop/cop/department/name_spec.rb
[modify] lib/rubocop.rb - `require_relative 'rubocop/cop/department/name'` was injected.
[modify] A configuration for the cop is added into config/default.yml.
Do 4 steps:
  1. Modify the description of Department/Name in config/default.yml
  2. Implement your new cop in the generated file!
  3. Commit your new cop with a message such as
     e.g. "Add new `Department/Name` cop"
  4. Run `bundle exec rake changelog:new` to generate a changelog entry
     for your new cop.
> git add -N .
> git diff --name-only
config/default.yml
lib/rubocop.rb
lib/rubocop/cop/department/name.rb
spec/rubocop/cop/department/name_spec.rb
$ bash --version
bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin21)
Copyright (C) 2007 Free Software Foundation, Inc.
$ bundle exec rake 'new_cop[Department/Name]'
bundle exec rake 'new_cop[Department/Name]'
rake new_cop: lib/rubocop/cop/department/name.rb already exists!
bash-3.2$ bundle exec rake 'new_cop[Department/Name]'
bundle exec rake 'new_cop[Department/Name]'
[create] lib/rubocop/cop/department/name.rb
[create] spec/rubocop/cop/department/name_spec.rb
[modify] lib/rubocop.rb - `require_relative 'rubocop/cop/department/name'` was injected.
[modify] A configuration for the cop is added into config/default.yml.
Do 4 steps:
  1. Modify the description of Department/Name in config/default.yml
  2. Implement your new cop in the generated file!
  3. Commit your new cop with a message such as
     e.g. "Add new `Department/Name` cop"
  4. Run `bundle exec rake changelog:new` to generate a changelog entry
     for your new cop.
$ git add -N .
$ git diff --name-only
config/default.yml
lib/rubocop.rb
lib/rubocop/cop/department/name.rb
spec/rubocop/cop/department/name_spec.rb

@koic
Copy link
Member

koic commented Jun 6, 2022

I've just found the documentation. Let's use it in single quotes.
https://docs.rubocop.org/rubocop/1.30/development.html#create-a-new-cop

@ydah ydah force-pushed the change_suggest_rake_task_warning branch from 0e84d64 to def56cb Compare June 6, 2022 04:19
@koic koic merged commit e61ee78 into rubocop:master Jun 6, 2022
@koic
Copy link
Member

koic commented Jun 6, 2022

Thanks!

@ydah
Copy link
Member Author

ydah commented Jun 6, 2022

@koic Thank you for your review and checked the documents!

@ydah ydah deleted the change_suggest_rake_task_warning branch June 6, 2022 05:07
ydah added a commit to ydah/rubocop-rails that referenced this pull request Jun 17, 2022
ydah added a commit to ydah/rubocop-performance that referenced this pull request Jun 17, 2022
ydah added a commit to ydah/rubocop-rspec that referenced this pull request Jun 17, 2022
ydah added a commit to ydah/sevencop that referenced this pull request Jun 18, 2022
ydah added a commit to ydah/rubocop-minitest that referenced this pull request Jun 20, 2022
renawatson68 added a commit to renawatson68/performance-develop-rubyonrails that referenced this pull request Sep 23, 2022
richardstewart0213 added a commit to richardstewart0213/performance-build-Performance-optimization-analysis- that referenced this pull request Nov 4, 2022
pirj pushed a commit to rubocop/rubocop-capybara that referenced this pull request Dec 29, 2022
ydah added a commit to rubocop/rubocop-factory_bot that referenced this pull request Apr 13, 2023
MarttiCheng added a commit to MarttiCheng/Rubocop-Performance that referenced this pull request Sep 28, 2023
SerhiiMisiura added a commit to SerhiiMisiura/Rubocop-Performance that referenced this pull request Oct 5, 2023
ydah added a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
ydah added a commit to rubocop/rubocop-rspec_rails that referenced this pull request Mar 27, 2024
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