From c5126a4c2eb57476fe4b45794a57f8cc280ef327 Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Thu, 21 Nov 2024 18:13:21 -0500 Subject: [PATCH] Add bin/new-cop script Replace rake task with simple bin script and avoid the hassle of passing rake arguments in ZSH. --- README.md | 9 ++++----- Rakefile | 19 ------------------- bin/new-cop | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 24 deletions(-) create mode 100755 bin/new-cop diff --git a/README.md b/README.md index 64c9f96..a450f48 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/Rakefile b/Rakefile index 3d23877..71e113d 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/bin/new-cop b/bin/new-cop new file mode 100755 index 0000000..d4a709c --- /dev/null +++ b/bin/new-cop @@ -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