gry 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +4 -0
- data/Appraisals +7 -0
- data/Gemfile +0 -3
- data/README.md +10 -13
- data/exe/gry +1 -1
- data/gemfiles/rubocop_0.47.0.gemfile +7 -0
- data/gemfiles/rubocop_head.gemfile +7 -0
- data/gry.gemspec +4 -4
- data/lib/gry.rb +3 -2
- data/lib/gry/cli.rb +17 -5
- data/lib/gry/congress.rb +29 -0
- data/lib/gry/formatter.rb +5 -7
- data/lib/gry/law.rb +3 -0
- data/lib/gry/option.rb +12 -14
- data/lib/gry/{analyzer.rb → pilot_study.rb} +2 -3
- data/lib/gry/version.rb +1 -1
- metadata +28 -10
- data/lib/gry/strategy.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33d1bfe1ac908ccdb01f9277c21baac9f73fbffe
|
4
|
+
data.tar.gz: f318d2d9613aff6348b5a4381e74fa1996fc30bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abe9020e5308c428f7e3091a8029f8aa884f14ac268492effb2bbbe3ee36fd46cf45edcc093ab33237e3c4b2b2d9fd5218902ede86fc89132991c51a74029be3
|
7
|
+
data.tar.gz: 9f61103cb653094a324e5fca6e97b8f04b031bcca3c910f7760fa5eceff95ddf639722d816c9af2d233a67d59c89e6d3a5c8ec436e4aa979f6f378d7ab813ac8
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Appraisals
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
# Gry
|
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
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
## Development
|
21
|
+
# Generate a .rubocop.yml for all configuratble cops.
|
22
|
+
$ gry >> .rubocop.yml
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
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
data/gry.gemspec
CHANGED
@@ -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.
|
35
|
-
spec.add_development_dependency "meowcop", ">= 1.
|
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
|
-
|
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/
|
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
|
data/lib/gry/cli.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
19
|
-
|
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
|
data/lib/gry/congress.rb
ADDED
@@ -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
|
data/lib/gry/formatter.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
module Gry
|
2
2
|
module Formatter
|
3
|
-
# @param gry_result [
|
4
|
-
# {'Style/DotPosition' => { {conf} => count}}
|
3
|
+
# @param gry_result [Array<Law>]
|
5
4
|
# @return [String] a yaml string
|
6
|
-
def self.format(
|
7
|
-
confs =
|
8
|
-
|
9
|
-
|
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) +
|
data/lib/gry/law.rb
ADDED
data/lib/gry/option.rb
CHANGED
@@ -1,27 +1,25 @@
|
|
1
1
|
module Gry
|
2
2
|
class Option
|
3
|
-
|
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 =
|
9
|
+
@fast = true
|
10
|
+
@max_count = 10
|
11
|
+
@min_difference = 10
|
13
12
|
|
14
|
-
opt.
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
27
|
-
Formatter.format(gry_result)
|
26
|
+
execute_rubocop(rubocop_args)
|
28
27
|
end
|
29
28
|
|
30
29
|
|
data/lib/gry/version.rb
CHANGED
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
|
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-
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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:
|
data/lib/gry/strategy.rb
DELETED
@@ -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
|