sandi_meter 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,6 +17,7 @@ gem install sandi_meter
17
17
  sandi_meter --help
18
18
  -d, --details CLI mode. Show details (path, line number)
19
19
  -g, --graph HTML mode. Create folder, log data and output stats to HTML file.
20
+ --json Output as JSON
20
21
  -l, --log Show syntax error and indentation log output
21
22
  -p, --path PATH Path to folder or file to analyze (default is ".")
22
23
  -r, --rules Show rules
@@ -37,7 +38,7 @@ Classes with 100+ lines
37
38
  SandiMeter::HtmlGenerator | 135 | ./lib/sandi_meter/html_generator.rb:5
38
39
  Valera | 109 | ./spec/test_classes/12.rb:1
39
40
 
40
- Missindented classes
41
+ Misindented classes
41
42
  Class name | Path
42
43
  MyApp::TestClass | ./spec/test_classes/1.rb:2
43
44
  OneLinerClass | ./spec/test_classes/5.rb:1
@@ -47,7 +48,7 @@ Methods with 5+ lines
47
48
  SandiMeter::Analyzer | initialize | 10 | ./lib/sandi_meter/analyzer.rb:10
48
49
  SandiMeter::Analyzer | analyze | 13 | ./lib/sandi_meter/analyzer.rb:22
49
50
 
50
- Missindented methods
51
+ Misindented methods
51
52
  Class name | Method name | Path
52
53
  MyApp::TestClass | blah | ./spec/test_classes/1.rb:3
53
54
 
data/Rakefile CHANGED
@@ -10,3 +10,9 @@ Rake::TestTask.new do |test|
10
10
  end
11
11
 
12
12
  task default: :test
13
+
14
+ task :debug do
15
+ require "sandi_meter/cli"
16
+
17
+ SandiMeter::CLI.execute
18
+ end
@@ -27,31 +27,43 @@
27
27
  <div class="clearfix"></div>
28
28
  </section>
29
29
  <nav class="main-menu">
30
- <a href="#" class="main-menu-active js-menu-item" data-rel=".js-charts">Charts</a><a href="#" class="js-menu-item" data-rel=".js-details">Details</a>
30
+ <a href="#" class="main-menu-active js-menu-item" data-rel=".js-charts">Rules</a>
31
+ <a href="#" class="js-menu-item" data-rel=".js-charts-percentage">Rules %</a>
32
+ <a href="#" class="js-menu-item" data-rel=".js-progress">Progress %</a>
33
+ <a href="#" class="js-menu-item" data-rel=".js-details">Details</a>
31
34
  </nav>
32
35
  <section class="plot-charts js-charts js-tab-item">
33
36
  <div class="plot-charts-item">
34
37
  <div class="plot-charts-item-caption">Number of 100 line classes vs time</div>
35
- <div class="plot-charts-item-graph" id="plot1"></div>
38
+ <div class="plot-charts-item-graph plot1"></div>
36
39
  </div>
37
40
  <div class="plot-charts-item">
38
41
  <div class="plot-charts-item-caption">Number of 5 line methods vs time</div>
39
- <div class="plot-charts-item-graph" id="plot2"></div>
42
+ <div class="plot-charts-item-graph plot2"></div>
40
43
  </div>
41
44
  <div class="clearfix"></div>
42
45
  <div class="plot-charts-item">
43
46
  <div class="plot-charts-item-caption">Number of methods calls with 4 params vs time</div>
44
- <div class="plot-charts-item-graph" id="plot3"></div>
47
+ <div class="plot-charts-item-graph plot3"></div>
45
48
  </div>
46
49
  <div class="plot-charts-item">
47
50
  <div class="plot-charts-item-caption">Number of controllers with 1 instance variable vs time</div>
48
- <div class="plot-charts-item-graph" id="plot4"></div>
51
+ <div class="plot-charts-item-graph plot4"></div>
49
52
  </div>
50
53
  <div class="clearfix"></div>
51
54
  </section>
52
55
  <section class="details js-details js-tab-item">
53
56
  <% details %>
54
57
  </section>
58
+ <section class="charts-percentage js-charts-percentage js-tab-item">
59
+ </section>
60
+ <section class="progress js-progress js-tab-item">
61
+ <div class="plot-charts-item">
62
+ <div class="plot-charts-item-caption">Overall progress</div>
63
+ <div class="plot-charts-item-graph plot"></div>
64
+ <div class="clearfix"></div>
65
+ </div>
66
+ </section>
55
67
  <footer class="main-footer">
56
68
  Scanned with love by <a href="https://github.com/makaroni4/sandi_meter">sandi_meter</a> gem.
57
69
  Please, <a href="https://github.com/makaroni4/sandi_meter/issues/new">leave an issue</a> or
@@ -9,7 +9,6 @@ function plotDonut(value1, value2, label1, label2, id) {
9
9
  data.push({ value: value2, label: label2 });
10
10
  }
11
11
 
12
- console.log(data);
13
12
  Morris.Donut({
14
13
  element: id,
15
14
  data: data,
@@ -20,18 +19,22 @@ function plotDonut(value1, value2, label1, label2, id) {
20
19
  })
21
20
  }
22
21
 
23
- function plotLine(id, data, ykeys, labels) {
24
- Morris.Line({
25
- element: id,
22
+ function plotLine(selector, data, ykeys, labels, ymax_value) {
23
+ var ymax_value = typeof ymax_value !== 'undefined' ? ymax_value : 'auto';
24
+ var graph = Morris.Line({
25
+ element: $(selector),
26
26
  data: data,
27
27
  xkey: 'timestamp',
28
28
  ykeys: ykeys,
29
+ ymax: ymax_value,
29
30
  labels: labels,
30
31
  lineColors: [
31
32
  '#0C0',
32
33
  '#F00'
33
34
  ],
34
- dateFormat: function (x) { return new Date(x).toDateString(); }
35
+ dateFormat: function (x) {
36
+ return new Date(x).toDateString();
37
+ }
35
38
  });
36
39
  }
37
40
 
@@ -56,8 +59,28 @@ function setHeader(last_report) {
56
59
  $('.js-report-date').text("Latest report from " + dateHeader(last_report));
57
60
  }
58
61
 
62
+ function calculate_percentage(row) {
63
+ [1,2,3,4].forEach(function(rule) {
64
+ var green_index = "r" + rule + "0";
65
+ var red_index = "r" + rule + "1";
66
+ var total = row[green_index] + row[red_index];
67
+ row[green_index + "p"] = total == 0 ? 0 : Math.round(100 * row[green_index] / total, 0);
68
+ row[red_index + "p"] = total == 0 ? 0 : Math.round(100 * row[red_index] / total, 0);
69
+ })
70
+ }
71
+
72
+ function calculate_percentage_data(data) {
73
+ data.forEach(function(row){
74
+ calculate_percentage(row);
75
+ row["overall"] = Math.round((row["r10p"] + row["r20p"] + row["r30p"] + row["r40p"]) / 4, 0);
76
+ })
77
+ }
78
+
59
79
  $(document).ready(function(){
60
80
  last_report = lastReport(data);
81
+ calculate_percentage_data(data);
82
+
83
+ $(".charts-percentage").html($(".plot-charts").html());
61
84
 
62
85
  setHeader(last_report);
63
86
 
@@ -66,10 +89,20 @@ $(document).ready(function(){
66
89
  plotDonut(last_report.r30, last_report.r31, '3. Method calls with less than 4 params', '3. Method calls with more than 4 params', 'pie3');
67
90
  plotDonut(last_report.r40, last_report.r41, '4. Controllers with one instance variable', '4. Controllers with many instance variables', 'pie4');
68
91
 
69
- plotLine('plot1', data, ['r10', 'r11'], ['under 100 lines', 'more than 100 lines.']);
70
- plotLine('plot2', data, ['r20', 'r21'], ['under 5 lines', 'more than 5 lines']);
71
- plotLine('plot3', data, ['r30', 'r31'], ['less than 4 params', 'more than 4 params']);
72
- plotLine('plot4', data, ['r40', 'r41'], ['one instance variable', 'many instance variables']);
92
+ plotLine('.plot-charts .plot1', data, ['r10', 'r11'], ['under 100 lines', 'more than 100 lines.'], 'auto');
93
+ plotLine('.plot-charts .plot2', data, ['r20', 'r21'], ['under 5 lines', 'more than 5 lines'], 'auto');
94
+ plotLine('.plot-charts .plot3', data, ['r30', 'r31'], ['less than 4 params', 'more than 4 params'], 'auto');
95
+ plotLine('.plot-charts .plot4', data, ['r40', 'r41'], ['one instance variable', 'many instance variables'], 'auto');
96
+
97
+ plotLine('.charts-percentage .plot1', data, ['r10p'], ['under 100 lines'], 100);
98
+ plotLine('.charts-percentage .plot2', data, ['r20p'], ['under 5 lines'], 100);
99
+ plotLine('.charts-percentage .plot3', data, ['r30p'], ['less than 4 params'], 100);
100
+ plotLine('.charts-percentage .plot4', data, ['r40p'], ['one instance variable'], 100);
101
+
102
+ plotLine('.progress .plot', data, ['overall'], ['Overall progress'], 100);
103
+
104
+ $(".charts-percentage").hide();
105
+ $(".progress").hide();
73
106
 
74
107
  var $tabs = $(".js-tab-item");
75
108
  var $menuItems = $(".js-menu-item")
@@ -36,9 +36,9 @@ body {
36
36
  }
37
37
 
38
38
  .plot-charts-item {
39
- width: 480px;
40
- float: left;
39
+ width: 470px;
41
40
  height: 298px;
41
+ float: left;
42
42
  margin-bottom: 40px;
43
43
  }
44
44
 
@@ -49,9 +49,19 @@ body {
49
49
  }
50
50
 
51
51
  .plot-charts-item-graph {
52
+ width: 470px;
52
53
  height: 280px;
53
54
  }
54
55
 
56
+ .progress {
57
+ text-align: center;
58
+ }
59
+
60
+ .progress .plot-charts-item {
61
+ float: none;
62
+ margin: 0 auto;
63
+ }
64
+
55
65
  .toggle_report.current_tab {
56
66
  text-decoration: none;
57
67
  cursor: default;
@@ -91,6 +101,7 @@ body {
91
101
  .main-menu a {
92
102
  display: inline-block;
93
103
  padding: 4px 16px;
104
+ margin-left: -5px;
94
105
  font-size: 18px;
95
106
  text-decoration: none;
96
107
  color: black;
@@ -96,7 +96,7 @@ module SandiMeter
96
96
  total_classes_amount = @data[:classes].size
97
97
  small_classes_amount = @data[:classes].select(&:small?).size
98
98
 
99
- misindented_classes_amount = @data[:classes].select { |c| c.last_line.nil? }
99
+ misindented_classes_amount = @data[:classes].select { |c| c.last_line.nil? }.size
100
100
 
101
101
  @output[:first_rule] ||= {}
102
102
  @output[:first_rule][:small_classes_amount] = small_classes_amount
@@ -2,11 +2,13 @@
2
2
  require 'mixlib/cli'
3
3
  require 'sandi_meter/file_scanner'
4
4
  require 'sandi_meter/formatter'
5
+ require 'sandi_meter/json_formatter'
5
6
  require 'sandi_meter/rules_checker'
6
7
  require 'sandi_meter/logger'
7
8
  require 'sandi_meter/version'
8
9
  require 'sandi_meter/html_generator'
9
10
  require 'yaml'
11
+ require 'json'
10
12
 
11
13
  module SandiMeter
12
14
  class CommandParser
@@ -56,6 +58,11 @@ module SandiMeter
56
58
  long: "--rules",
57
59
  description: "Show rules",
58
60
  boolean: 0
61
+
62
+ option :json,
63
+ long: "--json",
64
+ description: "Output as JSON",
65
+ boolean: false
59
66
  end
60
67
 
61
68
  class CLI
@@ -85,7 +92,12 @@ module SandiMeter
85
92
  scanner = SandiMeter::FileScanner.new(cli.config[:log])
86
93
  data = scanner.scan(cli.config[:path], cli.config[:details] || cli.config[:graph])
87
94
 
88
- formatter = SandiMeter::Formatter.new
95
+ if cli.config[:json]
96
+ formatter = SandiMeter::JsonFormatter.new
97
+ else
98
+ formatter = SandiMeter::Formatter.new
99
+ end
100
+
89
101
  formatter.print_data(data)
90
102
 
91
103
  if cli.config[:graph]
@@ -37,7 +37,7 @@ module SandiMeter
37
37
  end
38
38
 
39
39
  if data[:first_rule][:log][:misindented_classes].any?
40
- puts "\nMissindented classes"
40
+ puts "\nMisindented classes"
41
41
  print_array_of_arrays [["Class name", "Path"]] + data[:first_rule][:log][:misindented_classes].map { |row| row.delete_at(1); row } # 1 – size, which nil for misindented_classes
42
42
  end
43
43
 
@@ -47,7 +47,7 @@ module SandiMeter
47
47
  end
48
48
 
49
49
  if data[:second_rule][:log][:misindented_methods].any?
50
- puts "\nMissindented methods"
50
+ puts "\nMisindented methods"
51
51
  print_array_of_arrays [["Class name", "Method name", "Path"]] + data[:second_rule][:log][:misindented_methods].map { |row| row.delete_at(2); row } # 2 – size, which nil for misindented_methods
52
52
  end
53
53
 
@@ -0,0 +1,11 @@
1
+ module SandiMeter
2
+ class JsonFormatter
3
+ def print_data(data)
4
+ puts JSON.dump(data)
5
+ end
6
+
7
+ def print_log(data)
8
+ puts JSON.dump(data)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module SandiMeter
2
- VERSION = "1.1.5"
2
+ VERSION = "1.1.6"
3
3
  end
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rake"
27
27
 
28
28
  spec.add_runtime_dependency "mixlib-cli"
29
+ spec.add_runtime_dependency "json"
29
30
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sandi_meter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Anatoli Makarevich
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-02-06 00:00:00.000000000 Z
12
+ date: 2014-05-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: mixlib-cli
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,23 @@ dependencies:
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: json
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
51
74
  requirements:
52
75
  - - ! '>='
53
76
  - !ruby/object:Gem::Version
@@ -79,6 +102,7 @@ files:
79
102
  - lib/sandi_meter/file_scanner.rb
80
103
  - lib/sandi_meter/formatter.rb
81
104
  - lib/sandi_meter/html_generator.rb
105
+ - lib/sandi_meter/json_formatter.rb
82
106
  - lib/sandi_meter/loc_checker.rb
83
107
  - lib/sandi_meter/logger.rb
84
108
  - lib/sandi_meter/method_arguments_counter.rb
@@ -120,25 +144,29 @@ files:
120
144
  homepage: https://github.com/makaroni4/sandi_meter
121
145
  licenses:
122
146
  - MIT
123
- metadata: {}
124
147
  post_install_message:
125
148
  rdoc_options: []
126
149
  require_paths:
127
150
  - lib
128
151
  required_ruby_version: !ruby/object:Gem::Requirement
152
+ none: false
129
153
  requirements:
130
154
  - - ! '>='
131
155
  - !ruby/object:Gem::Version
132
156
  version: 1.9.0
133
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
+ none: false
134
159
  requirements:
135
160
  - - ! '>='
136
161
  - !ruby/object:Gem::Version
137
162
  version: '0'
163
+ segments:
164
+ - 0
165
+ hash: 3255714450703413671
138
166
  requirements: []
139
167
  rubyforge_project:
140
- rubygems_version: 2.1.10
168
+ rubygems_version: 1.8.24
141
169
  signing_key:
142
- specification_version: 4
170
+ specification_version: 3
143
171
  summary: Sandi Metz rules checker
144
172
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTM2ZjcwMzM2NmQ5ZTliOGU5OGY0ZGY0Zjg1NjRhMzM1ZmJhNTVkNw==
5
- data.tar.gz: !binary |-
6
- ZTYzNDVjNmM1NDcxOGE2MmVlZjZlYjMzMTI2N2Y0YTRmNzdiYjBmNg==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- YTgwMTUwZmQ3ZjEwNTBlYmExM2ExMjU5NzU1YTkxZmZlNWU2MTc5YTRkODE4
10
- YjU5N2JkMGQyYzUyMGQwMTFhYWJiMTIyNjUzYTg1YjhhMDRjMjM5OTQwNzlk
11
- NmJiZWJlZDZiZDZlNGNhZTI5OGRhMzlkMTJiMzMxN2JkMzY1NGM=
12
- data.tar.gz: !binary |-
13
- ZjA4YTQzNWVhMDZhZThkZjg4NjdmZTFjYmQ1MDZiNzc0ZjQzOTY2ODQ4NTMw
14
- MWE2YTdjZWQyY2VhZDliMmFlZTlmMDI4ZmUzM2I1ZTQwMzVkY2EzOGViM2Zj
15
- ZDE1NmY2ZDM4ZGQyOWQyZmExM2VhMGFkZmU3MGEyOTE4MDg1ZmI=