rubocop_auto_corrector 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a49a13088441b5013dc3201f355bdbe72dbed856f382e1e980ff6a1226708fb0
4
+ data.tar.gz: 0c7c9f3c2a254bd55d5c5011137dabef38c49e520ae45934e36466efb67c3d74
5
+ SHA512:
6
+ metadata.gz: 4c0f3e1c67c1a6d07f2a7e134c2ce99c0d45e042ede33c08f8c881f78cd87ae59a8b44fc274b33a9c6fc5681565a970ffa7ad427189841ab70f4ddcc2c977840
7
+ data.tar.gz: e3064d3ab780f08597235065f6502aec40e6df1497ef13783f0beea8382771d9298cda56a1fcef33cde002c235e2bc29abbd3445ed511ee8fff6411b32ca4f3f
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,18 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.2
5
+
6
+ Exclude:
7
+ - 'spec/dummy/**/*.rb'
8
+
9
+ # via. https://github.com/rubocop-hq/rubocop/blob/v0.60.0/config/default.yml#L60
10
+ - 'node_modules/**/*'
11
+ - 'vendor/**/*'
12
+ - '.git/**/*'
13
+
14
+ Layout/IndentHeredoc:
15
+ Enabled: false
16
+
17
+ RSpec/DescribedClass:
18
+ Enabled: false
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.1
@@ -0,0 +1,5 @@
1
+ ## master
2
+ [full changelog](http://github.com/sue445/rubocop_auto_corrector/compare/v0.1.0...master)
3
+
4
+ ## v0.1.0
5
+ * first release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rubocop_auto_corrector.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 sue445
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # RubocopAutoCorrector
2
+
3
+ Run `rubocop --auto-correct && git commit` with each cop.
4
+
5
+ # Example
6
+ See https://github.com/sue445/rubocop_auto_corrector/pull/3/commits
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'rubocop_auto_corrector'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install rubocop_auto_corrector
23
+
24
+ ## Usage
25
+ ```bash
26
+ $ bundle exec rubocop_auto_corrector
27
+ ```
28
+
29
+ ## Help
30
+ ```bash
31
+ $ bundle exec rubocop_auto_corrector --help
32
+ Usage: rubocop_auto_corrector [options]
33
+ --auto-correct-count COUNT Run `rubocop --auto-correct` and `git commit` for this number of times. (default. 2)
34
+ ```
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ 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).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/rubocop_auto_corrector.
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rubocop_auto_corrector'
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,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubocop_auto_corrector/cli'
4
+ require 'rubocop_auto_corrector/version'
5
+ require 'optparse'
6
+
7
+ opt = OptionParser.new
8
+ params = {
9
+ auto_correct_count: 2
10
+ }
11
+
12
+ Version = RubocopAutoCorrector::VERSION
13
+ opt.on('--auto-correct-count COUNT', 'Run `rubocop --auto-correct` and `git commit` for this number of times. (default. 2)') { |v| params[:auto_correct_count] = v.to_i }
14
+
15
+ opt.parse!(ARGV)
16
+
17
+ cli = RubocopAutoCorrector::CLI.new
18
+
19
+ params[:auto_correct_count].times do
20
+ cli.perform
21
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubocop_auto_corrector/version'
2
+
3
+ module RubocopAutoCorrector
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,77 @@
1
+ module RubocopAutoCorrector
2
+ require 'json'
3
+ require 'yaml'
4
+ require 'rubocop'
5
+
6
+ class CLI
7
+ DEFAULT_ORDER = 100
8
+
9
+ def initialize
10
+ data = YAML.load_file("#{__dir__}/data.yml")
11
+ @cop_orders = data['cop_orders']
12
+ @exclude_cops = data['exclude_cops']
13
+ end
14
+
15
+ def perform
16
+ cop_names =
17
+ collect_offense_cop_names
18
+ .select { |cop_name| auto_correctable?(cop_name) }
19
+ .sort_by { |cop_name| [cop_order(cop_name), cop_name] }
20
+
21
+ cop_names.each do |cop_name|
22
+ if (reason = exclude_reason(cop_name))
23
+ puts reason
24
+ next
25
+ end
26
+
27
+ run_and_commit "rubocop --auto-correct --only #{cop_name}"
28
+ end
29
+ end
30
+
31
+ def collect_offense_cop_names
32
+ rubocop_result = JSON.parse(run_rubocop_for_collect)
33
+
34
+ cop_names = []
35
+ rubocop_result['files'].each do |file|
36
+ cop_names += file['offenses'].map { |offense| offense['cop_name'] }
37
+ end
38
+ cop_names.uniq
39
+ end
40
+
41
+ def auto_correctable?(cop_name)
42
+ cop_class_name = "::RuboCop::Cop::#{cop_name.gsub('/', '::')}"
43
+ plugin_name = "rubocop-#{cop_name.split('/').first.downcase}"
44
+
45
+ begin
46
+ Object.new.instance_eval <<-RUBY
47
+ begin
48
+ require '#{plugin_name}'
49
+ rescue LoadError
50
+ end
51
+ #{cop_class_name}.new.respond_to?(:autocorrect)
52
+ RUBY
53
+ rescue NameError
54
+ false
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def run_and_commit(command)
61
+ ret = system command
62
+ system "git commit -am ':cop: #{command}'" if ret
63
+ end
64
+
65
+ def run_rubocop_for_collect
66
+ `rubocop --parallel --format=json`
67
+ end
68
+
69
+ def cop_order(cop_name)
70
+ @cop_orders[cop_name] || DEFAULT_ORDER
71
+ end
72
+
73
+ def exclude_reason(cop_name)
74
+ @exclude_cops[cop_name]
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,6 @@
1
+ cop_orders:
2
+ # Run `Style/UnneededPercentQ` before `Style/StringLiterals`.
3
+ Style/UnneededPercentQ: 50
4
+
5
+ exclude_cops:
6
+ Lint/UnneededDisable: "Lint/UnneededDisable can not be used with --only."
@@ -0,0 +1,3 @@
1
+ module RubocopAutoCorrector
2
+ VERSION = '0.1.0.beta1'.freeze
3
+ end
@@ -0,0 +1,44 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rubocop_auto_corrector/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rubocop_auto_corrector'
7
+ spec.version = RubocopAutoCorrector::VERSION
8
+ spec.authors = ['sue445']
9
+ spec.email = ['sue445@sue445.net']
10
+
11
+ spec.summary = 'Run `rubocop --auto-correct && git commit` with each cop.'
12
+ spec.description = 'Run `rubocop --auto-correct && git commit` with each cop.'
13
+ spec.homepage = 'https://github.com/sue445/rubocop_auto_corrector'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
22
+ else
23
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ 'public gem pushes.'
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_dependency 'rubocop', '>= 0.49.0'
37
+
38
+ spec.add_development_dependency 'bundler', '~> 1.17'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ spec.add_development_dependency 'rspec-parameterized'
42
+ spec.add_development_dependency 'rspec-temp_dir', '>= 1.1.0'
43
+ spec.add_development_dependency 'rubocop-rspec'
44
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop_auto_corrector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - sue445
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.49.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.49.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-parameterized
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-temp_dir
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Run `rubocop --auto-correct && git commit` with each cop.
112
+ email:
113
+ - sue445@sue445.net
114
+ executables:
115
+ - rubocop_auto_corrector
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - ".travis.yml"
123
+ - CHANGELOG.md
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/setup
130
+ - exe/rubocop_auto_corrector
131
+ - lib/rubocop_auto_corrector.rb
132
+ - lib/rubocop_auto_corrector/cli.rb
133
+ - lib/rubocop_auto_corrector/data.yml
134
+ - lib/rubocop_auto_corrector/version.rb
135
+ - rubocop_auto_corrector.gemspec
136
+ homepage: https://github.com/sue445/rubocop_auto_corrector
137
+ licenses:
138
+ - MIT
139
+ metadata:
140
+ homepage_uri: https://github.com/sue445/rubocop_auto_corrector
141
+ source_code_uri: https://github.com/sue445/rubocop_auto_corrector
142
+ changelog_uri: https://github.com/sue445/rubocop_auto_corrector/blob/master/CHANGELOG.md
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">"
155
+ - !ruby/object:Gem::Version
156
+ version: 1.3.1
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.7.6
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Run `rubocop --auto-correct && git commit` with each cop.
163
+ test_files: []