Skip to content

Commit

Permalink
Add bin/new-cop script
Browse files Browse the repository at this point in the history
Replace rake task with simple bin script and avoid the hassle of passing rake arguments in ZSH.
  • Loading branch information
javierjulio committed Nov 21, 2024
1 parent bb4a89d commit c5126a4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ Add `rubocop-jackpocket` to your Gemfile.

## Development

All custom cops are located under [`lib/rubocop/cop/jackpocket`](lib/rubocop/cop/jackpocket).
Run `bundle install` and then `bundle exec rspec` for setup.

Generate a new cop with `bin/new-cop Jackpocket/MyCustomCop`.

```
bundle install
bundle exec rspec
```
All custom cops are located under [`lib/rubocop/cop/jackpocket`](lib/rubocop/cop/jackpocket).
19 changes: 0 additions & 19 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,3 @@ require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end

desc 'Generate a new cop with a template'
task :new_cop, [:cop] do |_task, args|
require 'rubocop'

cop_name = args.fetch(:cop) do
warn 'usage: bundle exec rake new_cop[Department/Name]'
exit!
end

generator = RuboCop::Cop::Generator.new(cop_name)

generator.write_source
generator.write_spec
generator.inject_require(root_file_path: 'lib/rubocop/cop/jackpocket_cops.rb')
generator.inject_config(config_file_path: 'config/default.yml')

puts generator.todo
end
26 changes: 26 additions & 0 deletions bin/new-cop
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Provide cop_name
#
# > bin/new-cop Jackpocket/MyCustomCop

require "bundler/setup"
require "rubocop"

cop_name = ARGV[0]

if cop_name.nil? || !cop_name.match?(/Jackpocket\/[A-Za-z]*/)
puts "Error: Missing or invalid cop name."
puts "Usage: bin/new-cop Jackpocket/MyCustomCop"
exit
end

generator = RuboCop::Cop::Generator.new(cop_name)

generator.write_source
generator.write_spec
generator.inject_require(root_file_path: 'lib/rubocop/cop/jackpocket_cops.rb')
generator.inject_config(config_file_path: 'config/default.yml')

puts generator.todo

0 comments on commit c5126a4

Please sign in to comment.