quality_report 0.1.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +6 -32
- data/exe/frequency-list +36 -0
- data/exe/line-authors +33 -0
- data/exe/ruby-author-warnings +32 -0
- data/exe/ruby-line-authors +21 -0
- data/exe/ruby-quality-report +79 -0
- data/lib/quality_report/version.rb +1 -1
- metadata +29 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a14f06872f83645bba1702173f3f9ee1942c54ae51ca3031db00158c63b51217
|
4
|
+
data.tar.gz: 614f5743e39d968b4a431206f5f886a40a258a849e2a89543687ce00b2a8015f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5af1a4cfcef6c1831c40a5a6a111d684091ad282109015a9438ec9ab692349a7284b73a9e0b06d3ce51c29536f6167e4b3429386841a2fe622f9846ddd99c5a3
|
7
|
+
data.tar.gz: a059cce459f23251d0d7c72cd0b29d4f3f3824fb2bf65a8e2d9fb0af78299a4dec89af4986071534ce690e0e7838aa00289c0171db94da8beddfbc1830197bbe
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -1,39 +1,13 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
TODO: Delete this and the text below, and describe your gem
|
4
|
-
|
5
|
-
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/quality_report`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
|
-
Install the gem and add to the application's Gemfile by executing:
|
12
|
-
|
13
|
-
```bash
|
14
|
-
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
15
|
-
```
|
16
|
-
|
17
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
|
-
|
19
|
-
```bash
|
20
|
-
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
21
|
-
```
|
1
|
+
# Ruby Quality Report
|
22
2
|
|
23
3
|
## Usage
|
24
4
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
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.
|
5
|
+
```sh
|
6
|
+
ruby-quality-report
|
7
|
+
```
|
30
8
|
|
31
|
-
|
9
|
+
This outputs a CSV report to stdout.
|
32
10
|
|
33
11
|
## Contributing
|
34
12
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
36
|
-
|
37
|
-
## License
|
38
|
-
|
39
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
13
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dogweather/ruby-quality-report.
|
data/exe/frequency-list
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# frequency-list
|
6
|
+
#
|
7
|
+
# Input: A list of lines.
|
8
|
+
# Output: The unique lines in the input, sorted by frequency of occurrence.
|
9
|
+
#
|
10
|
+
# EXAMPLE
|
11
|
+
#
|
12
|
+
# Input:
|
13
|
+
#
|
14
|
+
# apple
|
15
|
+
# banana
|
16
|
+
# apple
|
17
|
+
# cherry
|
18
|
+
#
|
19
|
+
# Output:
|
20
|
+
#
|
21
|
+
# 2 apple
|
22
|
+
# 1 banana
|
23
|
+
# 1 cherry
|
24
|
+
#
|
25
|
+
|
26
|
+
lines = ARGF.readlines
|
27
|
+
|
28
|
+
frequency = lines.each_with_object(Hash.new(0)) do |line, counts|
|
29
|
+
counts[line.chomp] += 1
|
30
|
+
end
|
31
|
+
|
32
|
+
sorted_frequency = frequency.sort_by { |_, count| -count }
|
33
|
+
|
34
|
+
sorted_frequency.each do |line, count|
|
35
|
+
puts "#{count} #{line}"
|
36
|
+
end
|
data/exe/line-authors
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# line-authors
|
6
|
+
#
|
7
|
+
# List the authors of a single file, optionally limited
|
8
|
+
# to the specified lines. Outputs one author name for each
|
9
|
+
# line.
|
10
|
+
#
|
11
|
+
# USAGE
|
12
|
+
#
|
13
|
+
# line-authors <filename> <start line> <end line>
|
14
|
+
# line-authors <filename>
|
15
|
+
#
|
16
|
+
|
17
|
+
GIT_COMMAND = case ARGV.length
|
18
|
+
when 3
|
19
|
+
filename, start_line, end_line = ARGV
|
20
|
+
"git blame --line-porcelain -L #{start_line},#{end_line} #{filename}"
|
21
|
+
when 1
|
22
|
+
filename = ARGV[0]
|
23
|
+
"git blame --line-porcelain #{filename}"
|
24
|
+
else
|
25
|
+
puts 'Usage: line-authors <filename> <start line> <end line>'
|
26
|
+
puts ' line-authors <filename>'
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
puts(`#{GIT_COMMAND}`
|
31
|
+
.lines
|
32
|
+
.select { |line| line.start_with?('author ') }
|
33
|
+
.map { |line| line.split(' ')[1] })
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
#
|
5
|
+
# ruby-author-warnings
|
6
|
+
#
|
7
|
+
# This script outputs the authors of the lines of code that
|
8
|
+
# have been flagged by Rubocop as having too high of a complexity.
|
9
|
+
#
|
10
|
+
# Three metrics are used to determine complexity:
|
11
|
+
#
|
12
|
+
# - ABC Size
|
13
|
+
# - Cyclomatic Complexity
|
14
|
+
# - Perceived Complexity
|
15
|
+
#
|
16
|
+
# Each line of code can trigger one or more of these metrics.
|
17
|
+
# Each triggered line is listed as a separate warning.
|
18
|
+
#
|
19
|
+
|
20
|
+
RUBOCOP_WARNINGS = `rubocop --format json --force-default-config --only Metrics/AbcSize,Metrics/BlockLength,Metrics/BlockNesting,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity`
|
21
|
+
|
22
|
+
LOCATIONS =
|
23
|
+
JSON
|
24
|
+
.parse(RUBOCOP_WARNINGS)['files']
|
25
|
+
.reject{ |f| f['offenses'].empty? }
|
26
|
+
.map{ |f| f['offenses']
|
27
|
+
.map{|o| { path: f['path'], begin: o['location']['start_line'], end: o['location']['last_line'] }}}
|
28
|
+
.flatten
|
29
|
+
|
30
|
+
LOCATIONS.each do |location|
|
31
|
+
puts `line-authors #{location[:path]} #{location[:begin]} #{location[:end]}`
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# ruby-line-authors
|
5
|
+
#
|
6
|
+
# Output the authors of every line of Ruby code in this
|
7
|
+
# directory and all subdirectories. Names are output
|
8
|
+
# for every line.
|
9
|
+
#
|
10
|
+
# Example output when Alice wrote three lines and Bob
|
11
|
+
# wrote one, irrespective of the number of files:
|
12
|
+
#
|
13
|
+
# Alice
|
14
|
+
# Alice
|
15
|
+
# Bob
|
16
|
+
# Alice
|
17
|
+
|
18
|
+
RUBY_FILES = `find . -name '*.rb'`
|
19
|
+
|
20
|
+
RUBY_FILES
|
21
|
+
.each_line{ |filename| puts `line-authors #{filename}` }
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'tty-table'
|
5
|
+
|
6
|
+
#
|
7
|
+
# ruby-quality-report
|
8
|
+
#
|
9
|
+
# This script outputs a CSV spreadsheet file showing the percentage
|
10
|
+
# of lines of code written by each author that have been flagged as
|
11
|
+
# having too high of a complexity.
|
12
|
+
#
|
13
|
+
|
14
|
+
def create_combined_stats(part_stats, whole_stats)
|
15
|
+
part_data = make_data_set(part_stats)
|
16
|
+
whole_data = make_data_set(whole_stats)
|
17
|
+
|
18
|
+
whole_data.map do |label, whole_count|
|
19
|
+
part_count = part_data[label] || 0
|
20
|
+
|
21
|
+
{
|
22
|
+
label:,
|
23
|
+
part_count:,
|
24
|
+
whole_count:,
|
25
|
+
percent: float_to_percent(part_count.to_f / whole_count)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def make_data_set(two_column_data)
|
31
|
+
hash = {}
|
32
|
+
two_column_data.each_line do |line|
|
33
|
+
count, label = line.split(' ')
|
34
|
+
hash[label] = count.to_i
|
35
|
+
end
|
36
|
+
hash
|
37
|
+
end
|
38
|
+
|
39
|
+
def generate_csv(combined_stats)
|
40
|
+
generate_data(combined_stats)
|
41
|
+
.map { |stats| [stats[:label], stats[:percent], stats[:part_count], stats[:whole_count]].join(',') }
|
42
|
+
.tap { |x| x.prepend(['Author,Percent Flagged,Flagged Lines,All Lines']) }
|
43
|
+
.join("\n")
|
44
|
+
end
|
45
|
+
|
46
|
+
def generate_table(combined_stats)
|
47
|
+
table = TTY::Table.new(header: ['Author', 'Percent Flagged', 'Flagged Lines', 'All Lines'])
|
48
|
+
|
49
|
+
generate_data(combined_stats).each do |stats|
|
50
|
+
next if should_skip?(stats)
|
51
|
+
|
52
|
+
table << [stats[:label], "#{stats[:percent]}%", stats[:part_count], stats[:whole_count]]
|
53
|
+
end
|
54
|
+
|
55
|
+
table.render(:unicode)
|
56
|
+
end
|
57
|
+
|
58
|
+
def generate_data(combined_stats)
|
59
|
+
combined_stats
|
60
|
+
.sort_by { |s| s[:percent] }
|
61
|
+
.reverse
|
62
|
+
end
|
63
|
+
|
64
|
+
def should_skip?(stats)
|
65
|
+
stats[:whole_count] < 200
|
66
|
+
end
|
67
|
+
|
68
|
+
def float_to_percent(a_float)
|
69
|
+
(Float(a_float) * 100).round(1)
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Execution begins here
|
74
|
+
#
|
75
|
+
PART_STATS = `ruby-author-warnings | frequency-list`
|
76
|
+
WHOLE_STATS = `ruby-line-authors | frequency-list`
|
77
|
+
COMBINED_STATS = create_combined_stats(PART_STATS, WHOLE_STATS)
|
78
|
+
|
79
|
+
puts generate_table(COMBINED_STATS)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quality_report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robb Shecter
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.68'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tty-table
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.12.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.12.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -41,19 +55,30 @@ dependencies:
|
|
41
55
|
description: 'Ruby code quality report for teams: generates comparative metrics.'
|
42
56
|
email:
|
43
57
|
- robb@public.law
|
44
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- frequency-list
|
60
|
+
- line-authors
|
61
|
+
- ruby-author-warnings
|
62
|
+
- ruby-line-authors
|
63
|
+
- ruby-quality-report
|
45
64
|
extensions: []
|
46
65
|
extra_rdoc_files: []
|
47
66
|
files:
|
67
|
+
- ".rubocop.yml"
|
48
68
|
- LICENSE
|
49
69
|
- README.md
|
50
70
|
- Rakefile
|
71
|
+
- exe/frequency-list
|
72
|
+
- exe/line-authors
|
73
|
+
- exe/ruby-author-warnings
|
74
|
+
- exe/ruby-line-authors
|
75
|
+
- exe/ruby-quality-report
|
51
76
|
- lib/quality_report.rb
|
52
77
|
- lib/quality_report/version.rb
|
53
78
|
- sig/quality_report.rbs
|
54
79
|
homepage: https://github.com/dogweather/ruby-quality-report
|
55
80
|
licenses:
|
56
|
-
-
|
81
|
+
- MPL-2.0
|
57
82
|
metadata:
|
58
83
|
homepage_uri: https://github.com/dogweather/ruby-quality-report
|
59
84
|
source_code_uri: https://github.com/dogweather/ruby-quality-report
|
@@ -66,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
91
|
requirements:
|
67
92
|
- - ">="
|
68
93
|
- !ruby/object:Gem::Version
|
69
|
-
version: 3.
|
94
|
+
version: 3.1.0
|
70
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
96
|
requirements:
|
72
97
|
- - ">="
|