custom_cops_generator 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1b3a26c7275ff33acb6bdfb41c4eb9dd3264c6d06ae058e7551b9b6c10021e3b
4
+ data.tar.gz: 1b1606a45da88d889934d9e701353e79e68a2f7b7dadd9c304b22b16ba362746
5
+ SHA512:
6
+ metadata.gz: 3d74b53a1a7e7c47764ae5fcb652ea11e02961793149b74655bf451c07dd9249fc29cee2d78bfec6abd4cd44dbae6a809cefe94942748fe56f8057d5f6bdf031
7
+ data.tar.gz: 7e6513aab2049ee7c5bc54f14ce6f656f02c67f7d0c948d717bb6a43b50d8c6ee71519e4e82eed40f40ca5e0fc999149a07deda8957ac9628ec625766278649d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in custom_cops_generator.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,36 @@
1
+ # CustomCopsGenerator
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/custom_cops_generator`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'custom_cops_generator'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install custom_cops_generator
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/custom_cops_generator.
36
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "custom_cops_generator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/custom_cops_generator/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "custom_cops_generator"
5
+ spec.version = CustomCopsGenerator::VERSION
6
+ spec.authors = ["Masataka Pocke Kuwabara"]
7
+ spec.email = ["kuwabara@pocke.me"]
8
+
9
+ spec.summary = %q{A generator of RuboCop's custom cops gem}
10
+ spec.description = %q{A generator of RuboCop's custom cops gem}
11
+ spec.homepage = "https://github.com/pocke/custom_cops_generator"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency 'bundler'
30
+ spec.add_runtime_dependency 'activesupport'
31
+ end
@@ -0,0 +1,5 @@
1
+ #!ruby
2
+
3
+ require 'custom_cops_generator'
4
+
5
+ CustomCopsGenerator::CLI.run(ARGV)
@@ -0,0 +1,15 @@
1
+ require "custom_cops_generator/version"
2
+ require "custom_cops_generator/cli"
3
+ require "custom_cops_generator/generator"
4
+
5
+ require 'active_support'
6
+ require 'active_support/core_ext/string/inflections'
7
+
8
+ require 'optparse'
9
+ require 'pathname'
10
+ require 'fileutils'
11
+
12
+ module CustomCopsGenerator
13
+ class Error < StandardError; end
14
+ # Your code goes here...
15
+ end
@@ -0,0 +1,34 @@
1
+ module CustomCopsGenerator
2
+ class CLI
3
+ BANNER = <<~TEXT
4
+ Usage: custom_cops_generator NAME
5
+ TEXT
6
+
7
+ def self.run(argv)
8
+ new(argv).run
9
+ end
10
+
11
+ def initialize(argv)
12
+ @argv = argv
13
+ end
14
+
15
+ def run
16
+ # For --help
17
+ opt = OptionParser.new(BANNER)
18
+ args = opt.parse(@argv)
19
+
20
+ name = args.first
21
+ raise "It must be named `rubocop-*`. For example: rubocop-rspec" unless name.match?(/\Arubocop-\w+\z/)
22
+
23
+ Generator.new(name).generate
24
+ end
25
+
26
+ private def to_dirname(name)
27
+ name.sub('-', '/')
28
+ end
29
+
30
+ private def to_classname
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,161 @@
1
+ module CustomCopsGenerator
2
+ class Generator
3
+ def initialize(name)
4
+ @name = name
5
+ end
6
+
7
+ def generate
8
+ system('bundle', 'gem', name, exception: true)
9
+
10
+ put "lib/#{name}.rb", <<~RUBY
11
+ # frozen_string_literal: true
12
+
13
+ require 'rubocop'
14
+
15
+ require_relative '#{dirname}'
16
+ require_relative '#{dirname}/version'
17
+ require_relative '#{dirname}/inject'
18
+
19
+ RuboCop::#{classname}::Inject.defaults!
20
+
21
+ require_relative '#{cops_file_name}'
22
+ RUBY
23
+
24
+ put "lib/#{dirname}/inject.rb", <<~RUBY
25
+ # frozen_string_literal: true
26
+
27
+ # The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
28
+ # See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
29
+ module RuboCop
30
+ module #{classname}
31
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
32
+ # bit of our configuration.
33
+ module Inject
34
+ def self.defaults!
35
+ path = CONFIG_DEFAULT.to_s
36
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
37
+ config = Config.new(hash, path)
38
+ puts "configuration from \#{path}" if ConfigLoader.debug?
39
+ config = ConfigLoader.merge_with_default(config, path)
40
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ RUBY
46
+
47
+ put cops_file_name, <<~RUBY
48
+ # frozen_string_literal: true
49
+ RUBY
50
+
51
+ put "config/default.yml", <<~YAML
52
+ # Write it!
53
+ YAML
54
+
55
+ put 'spec/spec_helper.rb', <<~RUBY
56
+ # frozen_string_literal: true
57
+
58
+ require '#{dirname}'
59
+ require 'rubocop/rspec/support'
60
+
61
+ RSpec.configure do |config|
62
+ config.include RuboCop::RSpec::ExpectOffense
63
+
64
+ config.disable_monkey_patching!
65
+ config.raise_errors_for_deprecations!
66
+ config.raise_on_warning = true
67
+ config.fail_if_no_examples = true
68
+
69
+ config.order = :random
70
+ Kernel.srand config.seed
71
+ end
72
+ RUBY
73
+
74
+ put '.rspec', <<~TEXT
75
+ --format documentation
76
+ --color
77
+ --require spec_helper
78
+ TEXT
79
+
80
+ patch "#{name}.gemspec", /^end/, <<~RUBY
81
+
82
+ spec.add_runtime_dependency 'rubocop'
83
+ end
84
+ RUBY
85
+
86
+ patch "Rakefile", /\z/, <<~RUBY
87
+
88
+ require 'rspec/core/rake_task'
89
+
90
+ RSpec::Core::RakeTask.new(:spec) do |spec|
91
+ spec.pattern = FileList['spec/**/*_spec.rb']
92
+ end
93
+
94
+ task :new_cop, [:cop] do |_task, args|
95
+ require 'rubocop'
96
+
97
+ cop_name = args.fetch(:cop) do
98
+ warn 'usage: bundle exec rake new_cop[Department/Name]'
99
+ exit!
100
+ end
101
+
102
+ github_user = `git config github.user`.chop
103
+ github_user = 'your_id' if github_user.empty?
104
+
105
+ generator = RuboCop::Cop::Generator.new(cop_name, github_user)
106
+
107
+ generator.write_source
108
+ generator.write_spec
109
+ generator.inject_require(root_file_path: '#{cops_file_name}')
110
+ generator.inject_config(config_file_path: 'config/default.yml')
111
+
112
+ puts generator.todo
113
+ end
114
+ RUBY
115
+
116
+ patch 'Gemfile', /\z/, <<~RUBY
117
+ gem 'rspec'
118
+ RUBY
119
+
120
+ puts
121
+ puts <<~MESSAGE
122
+ It's done! You can start developing a new extension of RuboCop in #{root_path}.
123
+ For the next step, you can use the cop generator.
124
+
125
+ $ bundle exec rake 'new_cop[#{classname}/SuperCoolCopName]'
126
+ MESSAGE
127
+ end
128
+
129
+ private def put(path, content)
130
+ path = root_path / path
131
+ puts "create #{path}"
132
+ FileUtils.mkdir_p(path.dirname) unless path.dirname.directory?
133
+ path.write(content)
134
+ end
135
+
136
+ private def patch(path, pattern, content)
137
+ puts "update #{path}"
138
+ path = root_path / path
139
+ path.write path.read.sub(pattern, content)
140
+ end
141
+
142
+ private def root_path
143
+ @root_path ||= Pathname(name)
144
+ end
145
+
146
+ private def dirname
147
+ @dirname ||= name.sub('-', '/')
148
+ end
149
+
150
+ private def classname
151
+ @classname ||= name.split('-').last.camelcase
152
+ end
153
+
154
+ private def cops_file_name
155
+ @cops_file_name ||= "lib/rubocop/cop/#{name.split('-').last}_cops.rb"
156
+ end
157
+
158
+ attr_reader :name
159
+ private :name
160
+ end
161
+ end
@@ -0,0 +1,3 @@
1
+ module CustomCopsGenerator
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: custom_cops_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masataka Pocke Kuwabara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A generator of RuboCop's custom cops gem
42
+ email:
43
+ - kuwabara@pocke.me
44
+ executables:
45
+ - custom_cops_generator
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - custom_cops_generator.gemspec
56
+ - exe/custom_cops_generator
57
+ - lib/custom_cops_generator.rb
58
+ - lib/custom_cops_generator/cli.rb
59
+ - lib/custom_cops_generator/generator.rb
60
+ - lib/custom_cops_generator/version.rb
61
+ homepage: https://github.com/pocke/custom_cops_generator
62
+ licenses: []
63
+ metadata:
64
+ allowed_push_host: https://rubygems.org
65
+ homepage_uri: https://github.com/pocke/custom_cops_generator
66
+ source_code_uri: https://github.com/pocke/custom_cops_generator
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.6.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.0.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: A generator of RuboCop's custom cops gem
86
+ test_files: []