gry 0.0.2 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c54e917086fa41a5b62398662b2c32f7e0188173
4
- data.tar.gz: 06f3a5e3b7a4462e3f45bb9ae87a24d5b9ccf50c
3
+ metadata.gz: 33d1bfe1ac908ccdb01f9277c21baac9f73fbffe
4
+ data.tar.gz: f318d2d9613aff6348b5a4381e74fa1996fc30bb
5
5
  SHA512:
6
- metadata.gz: c0fe5457c19c379f412e23736f93cae17eb92e9cbb75f5bf69057ef5403ea99e4c8fa176e4c2fa50dbe46ca18118610856da52a67c7a4fdbb8e7c8a3f3ce507f
7
- data.tar.gz: 148ce9a7abfe1e8d5f0c4f88fdadbe19e5715bcded3d7b7b04861781bb563f9cf1a6a575e1b56338912f131d3cb98f86bee14fd4eaf41989ae73240f59abaf13
6
+ metadata.gz: abe9020e5308c428f7e3091a8029f8aa884f14ac268492effb2bbbe3ee36fd46cf45edcc093ab33237e3c4b2b2d9fd5218902ede86fc89132991c51a74029be3
7
+ data.tar.gz: 9f61103cb653094a324e5fca6e97b8f04b031bcca3c910f7760fa5eceff95ddf639722d816c9af2d233a67d59c89e6d3a5c8ec436e4aa979f6f378d7ab813ac8
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- /.bundle/
1
+ .bundle/
2
2
  /.yardoc
3
3
  /Gemfile.lock
4
4
  /_yardoc/
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /gemfiles/*.lock
@@ -2,4 +2,8 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - 2.3.3
5
+ - 2.4.0
5
6
  - ruby-head
7
+ gemfile:
8
+ - gemfiles/rubocop_0.47.0.gemfile
9
+ - gemfiles/rubocop_head.gemfile
@@ -0,0 +1,7 @@
1
+ appraise "rubocop-head" do
2
+ gem "rubocop", github: 'bbatsov/rubocop'
3
+ end
4
+
5
+ appraise "rubocop-0.47.0" do
6
+ gem "rubocop", "0.47.0"
7
+ end
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in gry.gemspec
4
4
  gemspec
5
-
6
- gem 'rubocop', github: 'bbatsov/rubocop'
7
- gem 'meowcop', github: 'pocke/meowcop', branch: 'rubocop-master'
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
- # Gry (Work In Progress!)
1
+ # Gry
2
+
3
+ Gry Generates a .Rubocop.Yml automatically.
2
4
 
3
5
  [![Build Status](https://travis-ci.org/pocke/gry.svg?branch=master)](https://travis-ci.org/pocke/gry)
4
6
  [![Coverage Status](https://coveralls.io/repos/github/pocke/gry/badge.svg?branch=master)](https://coveralls.io/github/pocke/gry?branch=master)
5
7
  [![Gem Version](https://badge.fury.io/rb/gry.svg)](https://badge.fury.io/rb/gry)
6
8
 
7
- Gry generates `.rubocop.yml` automatically from your source code.
9
+ Gry extracts coding style guide as a `.rubocop.yml` from your code that already exists.
10
+
8
11
 
9
12
  ## Installation
10
13
 
@@ -15,18 +18,12 @@ $ gem install gry
15
18
  ## Usage
16
19
 
17
20
  ```sh
18
- $ gry Style/EmptyElse Style/AlignParameters
19
- ```
20
-
21
- ## Development
21
+ # Generate a .rubocop.yml for all configuratble cops.
22
+ $ gry >> .rubocop.yml
22
23
 
23
- 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.
24
-
25
- 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).
26
-
27
- ## Contributing
28
-
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/gry.
24
+ # Generate a .rubocop.yml for specified cops only.
25
+ $ gry Style/AndOr Style/VariableName >> .rubocop.yml
26
+ ```
30
27
 
31
28
 
32
29
  License
data/exe/gry CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'gry'
4
4
 
5
- Gry::CLI.new(ARGV).run
5
+ Gry::CLI.new(ARGV).run(STDOUT)
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "0.47.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", :github => "bbatsov/rubocop"
6
+
7
+ gemspec :path => "../"
@@ -31,10 +31,10 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "guard-rspec", "~> 4.7.3"
32
32
  spec.add_development_dependency "guard-bundler", "~> 2.1.0"
33
33
  spec.add_development_dependency "guard-rubocop", "~> 1.2.0"
34
- spec.add_development_dependency "rubocop", ">= 0.46.0"
35
- spec.add_development_dependency "meowcop", ">= 1.4.0"
34
+ spec.add_development_dependency "rubocop", ">= 0.47.0"
35
+ spec.add_development_dependency "meowcop", ">= 1.7.0"
36
+ spec.add_development_dependency "appraisal"
36
37
 
37
- # TODO: specify 0.47.0
38
- spec.add_runtime_dependency "rubocop", ">= 0.46.0"
38
+ spec.add_runtime_dependency "rubocop", ">= 0.47.0"
39
39
  spec.add_runtime_dependency "parallel", "~> 1.10.0"
40
40
  end
data/lib/gry.rb CHANGED
@@ -10,11 +10,12 @@ require 'parallel'
10
10
 
11
11
  require "gry/version"
12
12
  require 'gry/rubocop_runner'
13
- require 'gry/analyzer'
13
+ require 'gry/congress'
14
+ require 'gry/law'
15
+ require 'gry/pilot_study'
14
16
  require "gry/option"
15
17
  require 'gry/cli'
16
18
  require 'gry/rubocop_adapter'
17
- require 'gry/strategy'
18
19
  require 'gry/formatter'
19
20
 
20
21
  module Gry
@@ -4,19 +4,31 @@ module Gry
4
4
  @argv = argv
5
5
  end
6
6
 
7
- def run
7
+ def run(writer)
8
8
  opt = Option.new(@argv)
9
9
  if opt.version
10
10
  rubocop_version, = *Open3.capture3('rubocop', '--verbose-version')
11
- puts "gry #{VERSION} (RuboCop #{rubocop_version.chomp})"
11
+ writer.puts "gry #{VERSION} (RuboCop #{rubocop_version.chomp})"
12
12
  return
13
13
  end
14
- cops = opt.all ? RubocopAdapter.configurable_cops : opt.args
14
+
15
+ cops = opt.args.empty? ? RubocopAdapter.configurable_cops : opt.args
15
16
  if opt.fast
16
17
  cops.reject!{|cop| cop == 'Style/AlignHash'}
17
18
  end
18
- analyzer = Gry::Analyzer.new(cops, process: opt.process)
19
- puts analyzer.analyze
19
+ pilot_study = Gry::PilotStudy.new(cops, process: opt.process)
20
+
21
+ bills = pilot_study.analyze
22
+ # TODO: Specify the value from option
23
+ congress = Congress.new(
24
+ max_count: opt.max_count,
25
+ min_difference: opt.min_difference,
26
+ )
27
+ laws = bills.map do |cop_name, bill|
28
+ congress.discuss(cop_name, bill)
29
+ end.compact
30
+
31
+ writer.puts Formatter.format(laws)
20
32
  end
21
33
  end
22
34
  end
@@ -0,0 +1,29 @@
1
+ module Gry
2
+ class Congress
3
+ def initialize(max_count:, min_difference:)
4
+ @max_count = max_count
5
+ @min_difference = min_difference
6
+ end
7
+
8
+ # @param name [String] cop name
9
+ # @param bill [Hash{Hash => Integer}] rubocop results
10
+ # {
11
+ # {config1} => 20,
12
+ # {config2} => 0,
13
+ # {config3} => 10,
14
+ # }
15
+ # @return [Law]
16
+ def discuss(name, bill)
17
+ # [[conf, count], ...]
18
+ sorted = bill.sort_by{|_conf, count| count}
19
+ min_count = sorted.first.last
20
+ return nil if min_count > @max_count
21
+
22
+ second_count = sorted[1].last
23
+ return nil if second_count - min_count < @min_difference
24
+
25
+ letter = sorted.first.first
26
+ Law.new(name, bill, letter)
27
+ end
28
+ end
29
+ end
@@ -1,13 +1,11 @@
1
1
  module Gry
2
2
  module Formatter
3
- # @param gry_result [Hash]
4
- # {'Style/DotPosition' => { {conf} => count}}
3
+ # @param gry_result [Array<Law>]
5
4
  # @return [String] a yaml string
6
- def self.format(gry_result)
7
- confs = gry_result.map do |cop_name, set_count|
8
- setting = Strategy.results_to_config(set_count)
9
- next unless setting
10
- to_comment(set_count) + to_yaml({cop_name => setting})
5
+ def self.format(laws)
6
+ confs = laws.map do |law|
7
+ to_comment(law.bill) +
8
+ to_yaml({law.name => law.letter})
11
9
  end.compact
12
10
 
13
11
  to_yaml(RubocopAdapter.config_base) +
@@ -0,0 +1,3 @@
1
+ module Gry
2
+ Law = Struct.new(:name, :bill, :letter)
3
+ end
@@ -1,27 +1,25 @@
1
1
  module Gry
2
2
  class Option
3
- class ParseError < StandardError; end
4
-
5
- attr_reader :args, :all, :process, :version, :fast
3
+ attr_reader :args, :process, :version, :fast, :max_count, :min_difference
6
4
 
7
5
  def initialize(argv)
8
6
  opt = OptionParser.new
9
- @all = false
10
7
  @version = false
11
8
  @process = Parallel.processor_count
12
- @fast = false
9
+ @fast = true
10
+ @max_count = 10
11
+ @min_difference = 10
13
12
 
14
- opt.on('-d', '--debug') {Gry.debug_mode!}
15
- opt.on('-a', '--all') {@all = true}
16
- opt.on('-p', '--process=VAL') {|v| @process = v.to_i}
17
- opt.on('-v', '--version') {@version = true}
18
- opt.on('-f', '--fast') {@fast = true}
13
+ opt.banner = 'Usage: gry [options] [Cop1, Cop2, ...]'
19
14
 
20
- @args = opt.parse(argv)
15
+ opt.on('-d', '--debug', 'Output debug log.') {Gry.debug_mode!}
16
+ opt.on('-p', '--process=VAL', 'Number of parallel processes.') {|v| @process = v.to_i}
17
+ opt.on('-v', '--version', 'Display version.') {@version = true}
18
+ opt.on('--[no-]fast', 'Run only fast cops. Default: true') {|v| @fast = v}
19
+ opt.on('--max-count=10', 'Upper limit of issues.') {|v| @max_count = v.to_i}
20
+ opt.on('--min-difference=10', 'Lower limit of issues number difference') {|v| @min_difference = v.to_i}
21
21
 
22
- if @all && !@args.empty?
23
- raise ParseError, 'Do not specify cop name with --all option'
24
- end
22
+ @args = opt.parse(argv)
25
23
  end
26
24
  end
27
25
  end
@@ -1,5 +1,5 @@
1
1
  module Gry
2
- class Analyzer
2
+ class PilotStudy
3
3
  # @param cops [Array<String>] cop names. e.g.) ['Style/EmptyElse']
4
4
  def initialize(cops, process:)
5
5
  @cops = cops
@@ -23,8 +23,7 @@ module Gry
23
23
  [cops, setting]
24
24
  end
25
25
 
26
- gry_result = execute_rubocop(rubocop_args)
27
- Formatter.format(gry_result)
26
+ execute_rubocop(rubocop_args)
28
27
  end
29
28
 
30
29
 
@@ -1,3 +1,3 @@
1
1
  module Gry
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masataka Kuwabara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-14 00:00:00.000000000 Z
11
+ date: 2017-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -156,42 +156,56 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 0.46.0
159
+ version: 0.47.0
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: 0.46.0
166
+ version: 0.47.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: meowcop
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: 1.4.0
173
+ version: 1.7.0
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
- version: 1.4.0
180
+ version: 1.7.0
181
+ - !ruby/object:Gem::Dependency
182
+ name: appraisal
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: rubocop
183
197
  requirement: !ruby/object:Gem::Requirement
184
198
  requirements:
185
199
  - - ">="
186
200
  - !ruby/object:Gem::Version
187
- version: 0.46.0
201
+ version: 0.47.0
188
202
  type: :runtime
189
203
  prerelease: false
190
204
  version_requirements: !ruby/object:Gem::Requirement
191
205
  requirements:
192
206
  - - ">="
193
207
  - !ruby/object:Gem::Version
194
- version: 0.46.0
208
+ version: 0.47.0
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: parallel
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -218,6 +232,7 @@ files:
218
232
  - ".rspec"
219
233
  - ".rubocop.yml"
220
234
  - ".travis.yml"
235
+ - Appraisals
221
236
  - Gemfile
222
237
  - Guardfile
223
238
  - LICENSE
@@ -226,15 +241,18 @@ files:
226
241
  - bin/console
227
242
  - bin/setup
228
243
  - exe/gry
244
+ - gemfiles/rubocop_0.47.0.gemfile
245
+ - gemfiles/rubocop_head.gemfile
229
246
  - gry.gemspec
230
247
  - lib/gry.rb
231
- - lib/gry/analyzer.rb
232
248
  - lib/gry/cli.rb
249
+ - lib/gry/congress.rb
233
250
  - lib/gry/formatter.rb
251
+ - lib/gry/law.rb
234
252
  - lib/gry/option.rb
253
+ - lib/gry/pilot_study.rb
235
254
  - lib/gry/rubocop_adapter.rb
236
255
  - lib/gry/rubocop_runner.rb
237
- - lib/gry/strategy.rb
238
256
  - lib/gry/version.rb
239
257
  homepage: https://github.com/pocke/gry
240
258
  licenses:
@@ -1,24 +0,0 @@
1
- module Gry
2
- # Strategy decides a rule config from rubocop results.
3
- module Strategy
4
- # The method returns
5
- # @param results [Hash{Hash => Integer}] rubocop results
6
- # {
7
- # {config1} => 20,
8
- # {config2} => 0,
9
- # {config3} => 10,
10
- # }
11
- # @return [Hash{}] returns a config decided from received configs
12
- # {
13
- # EnforcedStyle: 'foobar',
14
- # }
15
- # @return [NilClass] if config is not available, retunrs nil
16
- def self.results_to_config(results, count_limit: 10)
17
- results
18
- .select{|_conf, count| count <= count_limit }
19
- .sort_by{|_conf, count| count}
20
- .first # to get minimum conf and count
21
- &.first # to get conf
22
- end
23
- end
24
- end