quality_report 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 887fda6d1ac12508da2c4b19b6142b061dddc0a5814a704da31091a674383811
4
- data.tar.gz: 41d6473f6b5a673c1f4f3d0ff0dc37bb4ee8f81260874392f1d7cd530a9ce5ee
3
+ metadata.gz: 864f3f5fa2d1b9a35478532a96341ef0b23df5911aa8eb8ac0293beb7e42397a
4
+ data.tar.gz: 926133e5ba6df85661a397f10e6c035e987b0d3a68920595633a8d3b6d4d9330
5
5
  SHA512:
6
- metadata.gz: 583024b0f69b6d41b6f4e9e0451ebeb0f67fc18649df41938cd3bbd4a969b27ea5c95f5c3ae38c107b51af3f51a27fb69e8e0ba2cce43d1fa774ea77f0873fe7
7
- data.tar.gz: 14e8f05560c3bd0a0d598ad0c62fa669eaf358914bef07a27007551873f6a45caf7054613e40e58ad3dd3ddc9c4ce885f6fd5d90432112056c16ff66dcbdcbe0
6
+ metadata.gz: 047430fe2e35df46138827d368f7eae6dc24881a41f952e128f59fae156fe0338bfff5a721d148372983513f7d8f45bc71ecc6bd77377918bb8e8d5c755f0e4f
7
+ data.tar.gz: 154ffb7d0e21db6d0ac67b20a5d73247980ae074bf21323369a4ed2d9add28e4e7af101f11e90d8319240ce5a804715202fea345a2d8fd47d618683863f545c3
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
data/README.md CHANGED
@@ -1,39 +1,11 @@
1
- # QualityReport
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
- TODO: Write usage instructions here
26
-
27
- ## Development
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.
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
5
+ ```sh
6
+ ruby-quality-report
7
+ ```
32
8
 
33
9
  ## Contributing
34
10
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/quality_report.
36
-
37
- ## License
38
-
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
11
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dogweather/ruby-quality-report.
@@ -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,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # ruby-quality-report
5
+ #
6
+ # This script outputs a CSV spreadsheet file showing the percentage
7
+ # of lines of code written by each author that have been flagged as
8
+ # having too high of a complexity.
9
+ #
10
+
11
+ def create_combined_stats(part_stats, whole_stats)
12
+ part_data = make_data_set(part_stats)
13
+ whole_data = make_data_set(whole_stats)
14
+
15
+ whole_data.map do |label, whole_count|
16
+ part_count = part_data[label] || 0
17
+ {
18
+ label:,
19
+ part_count:,
20
+ whole_count:,
21
+ percent: part_count.to_f / whole_count.to_f
22
+ }
23
+ end
24
+ end
25
+
26
+ def make_data_set(two_column_data)
27
+ hash = {}
28
+ two_column_data.each_line do |line|
29
+ count, label = line.split(' ')
30
+ hash[label] = count.to_i
31
+ end
32
+ hash
33
+ end
34
+
35
+ def generate_csv(combined_stats)
36
+ combined_stats
37
+ .sort_by{|s| s[:percent]}
38
+ .reverse
39
+ .map{ |stats| [stats[:label], stats[:percent], stats[:part_count], stats[:whole_count]].join(',') }
40
+ .tap{|x| x.prepend(["Author,Percent Flagged,Flagged Lines,All Lines"])}
41
+ .join("\n")
42
+ end
43
+
44
+
45
+ #
46
+ # Execution begins here
47
+ #
48
+ PART_STATS = `ruby-author-warnings | frequency-list`
49
+ WHOLE_STATS = `ruby-line-authors | frequency-list`
50
+
51
+ COMBINED_STATS = create_combined_stats(PART_STATS, WHOLE_STATS)
52
+
53
+ puts generate_csv(COMBINED_STATS)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QualityReport
4
- VERSION = "0.1.0"
4
+ VERSION = '1.0.0'
5
5
  end
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: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
@@ -41,19 +41,30 @@ dependencies:
41
41
  description: 'Ruby code quality report for teams: generates comparative metrics.'
42
42
  email:
43
43
  - robb@public.law
44
- executables: []
44
+ executables:
45
+ - frequency-list
46
+ - line-authors
47
+ - ruby-author-warnings
48
+ - ruby-line-authors
49
+ - ruby-quality-report
45
50
  extensions: []
46
51
  extra_rdoc_files: []
47
52
  files:
53
+ - ".rubocop.yml"
48
54
  - LICENSE
49
55
  - README.md
50
56
  - Rakefile
57
+ - exe/frequency-list
58
+ - exe/line-authors
59
+ - exe/ruby-author-warnings
60
+ - exe/ruby-line-authors
61
+ - exe/ruby-quality-report
51
62
  - lib/quality_report.rb
52
63
  - lib/quality_report/version.rb
53
64
  - sig/quality_report.rbs
54
65
  homepage: https://github.com/dogweather/ruby-quality-report
55
66
  licenses:
56
- - Mozilla Public License 2.0
67
+ - MPL-2.0
57
68
  metadata:
58
69
  homepage_uri: https://github.com/dogweather/ruby-quality-report
59
70
  source_code_uri: https://github.com/dogweather/ruby-quality-report
@@ -66,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
77
  requirements:
67
78
  - - ">="
68
79
  - !ruby/object:Gem::Version
69
- version: 3.0.0
80
+ version: 3.1.0
70
81
  required_rubygems_version: !ruby/object:Gem::Requirement
71
82
  requirements:
72
83
  - - ">="