code_metric_fu 4.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (296) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.metrics +3 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +15 -0
  6. data/.rubocop_todo.yml +69 -0
  7. data/.simplecov +74 -0
  8. data/.travis.yml +22 -0
  9. data/.yardopts +4 -0
  10. data/AUTHORS +12 -0
  11. data/CONTRIBUTING.md +47 -0
  12. data/CONTRIBUTORS +76 -0
  13. data/DEV.md +76 -0
  14. data/Gemfile +74 -0
  15. data/Guardfile +30 -0
  16. data/HISTORY.md +705 -0
  17. data/MIT-LICENSE +22 -0
  18. data/README.md +299 -0
  19. data/Rakefile +27 -0
  20. data/TODO.md +118 -0
  21. data/appveyor.yml +31 -0
  22. data/bin/metric_fu +9 -0
  23. data/bin/mf-cane +10 -0
  24. data/bin/mf-churn +10 -0
  25. data/bin/mf-flay +10 -0
  26. data/bin/mf-reek +10 -0
  27. data/bin/mf-roodi +10 -0
  28. data/bin/mf-saikuro +10 -0
  29. data/certs/bf4.pem +22 -0
  30. data/checksum/.gitkeep +0 -0
  31. data/checksum/metric_fu-4.10.0.gem.sha512 +1 -0
  32. data/checksum/metric_fu-4.11.0.gem.sha512 +1 -0
  33. data/checksum/metric_fu-4.11.1.gem.sha512 +1 -0
  34. data/checksum/metric_fu-4.11.2.gem.sha512 +1 -0
  35. data/checksum/metric_fu-4.11.3.gem.sha512 +1 -0
  36. data/checksum/metric_fu-4.11.4.gem.sha512 +1 -0
  37. data/checksum/metric_fu-4.12.0.gem.sha512 +1 -0
  38. data/checksum/metric_fu-4.2.0.gem.sha512 +1 -0
  39. data/checksum/metric_fu-4.2.1.gem.sha512 +1 -0
  40. data/checksum/metric_fu-4.3.0.gem.sha512 +1 -0
  41. data/checksum/metric_fu-4.3.1.gem.sha512 +1 -0
  42. data/checksum/metric_fu-4.4.0.gem.sha512 +1 -0
  43. data/checksum/metric_fu-4.4.1.gem.sha512 +1 -0
  44. data/checksum/metric_fu-4.4.2.gem.sha512 +1 -0
  45. data/checksum/metric_fu-4.4.3.gem.sha512 +1 -0
  46. data/checksum/metric_fu-4.4.4.gem.sha512 +1 -0
  47. data/checksum/metric_fu-4.5.0.gem.sha512 +1 -0
  48. data/checksum/metric_fu-4.5.1.gem.sha512 +1 -0
  49. data/checksum/metric_fu-4.5.2.gem.sha512 +1 -0
  50. data/checksum/metric_fu-4.6.0.gem.sha512 +1 -0
  51. data/checksum/metric_fu-4.7.0.gem.sha512 +1 -0
  52. data/checksum/metric_fu-4.7.1.gem.sha512 +1 -0
  53. data/checksum/metric_fu-4.7.2.gem.sha512 +1 -0
  54. data/checksum/metric_fu-4.7.3.gem.sha512 +1 -0
  55. data/checksum/metric_fu-4.7.4.gem.sha512 +1 -0
  56. data/checksum/metric_fu-4.8.0.gem.sha512 +1 -0
  57. data/checksum/metric_fu-4.9.0.gem.sha512 +1 -0
  58. data/config/roodi_config.yml +22 -0
  59. data/config/rubocop.yml +269 -0
  60. data/gem_tasks/build.rake +197 -0
  61. data/gem_tasks/rubocop.rake +10 -0
  62. data/gem_tasks/usage_test.rake +19 -0
  63. data/gem_tasks/yard.rake +24 -0
  64. data/lib/metric_fu/calculate.rb +10 -0
  65. data/lib/metric_fu/cli/client.rb +26 -0
  66. data/lib/metric_fu/cli/helper.rb +80 -0
  67. data/lib/metric_fu/cli/parser.rb +138 -0
  68. data/lib/metric_fu/configuration.rb +150 -0
  69. data/lib/metric_fu/constantize.rb +57 -0
  70. data/lib/metric_fu/data_structures/line_numbers.rb +112 -0
  71. data/lib/metric_fu/data_structures/location.rb +110 -0
  72. data/lib/metric_fu/data_structures/sexp_node.rb +107 -0
  73. data/lib/metric_fu/environment.rb +129 -0
  74. data/lib/metric_fu/errors/analysis_error.rb +4 -0
  75. data/lib/metric_fu/formatter/html.rb +96 -0
  76. data/lib/metric_fu/formatter/syntax.rb +45 -0
  77. data/lib/metric_fu/formatter/yaml.rb +18 -0
  78. data/lib/metric_fu/formatter.rb +40 -0
  79. data/lib/metric_fu/gem_run.rb +70 -0
  80. data/lib/metric_fu/gem_version.rb +92 -0
  81. data/lib/metric_fu/generator.rb +135 -0
  82. data/lib/metric_fu/io.rb +132 -0
  83. data/lib/metric_fu/loader.rb +105 -0
  84. data/lib/metric_fu/logger.rb +62 -0
  85. data/lib/metric_fu/logging/mf_debugger.rb +23 -0
  86. data/lib/metric_fu/metric.rb +143 -0
  87. data/lib/metric_fu/metrics/cane/generator.rb +95 -0
  88. data/lib/metric_fu/metrics/cane/grapher.rb +37 -0
  89. data/lib/metric_fu/metrics/cane/metric.rb +34 -0
  90. data/lib/metric_fu/metrics/cane/report.html.erb +87 -0
  91. data/lib/metric_fu/metrics/cane/violations.rb +46 -0
  92. data/lib/metric_fu/metrics/churn/generator.rb +37 -0
  93. data/lib/metric_fu/metrics/churn/hotspot.rb +43 -0
  94. data/lib/metric_fu/metrics/churn/metric.rb +29 -0
  95. data/lib/metric_fu/metrics/churn/report.html.erb +58 -0
  96. data/lib/metric_fu/metrics/flay/generator.rb +51 -0
  97. data/lib/metric_fu/metrics/flay/grapher.rb +37 -0
  98. data/lib/metric_fu/metrics/flay/hotspot.rb +52 -0
  99. data/lib/metric_fu/metrics/flay/metric.rb +28 -0
  100. data/lib/metric_fu/metrics/flay/report.html.erb +29 -0
  101. data/lib/metric_fu/metrics/flog/generator.rb +113 -0
  102. data/lib/metric_fu/metrics/flog/grapher.rb +77 -0
  103. data/lib/metric_fu/metrics/flog/hotspot.rb +46 -0
  104. data/lib/metric_fu/metrics/flog/metric.rb +29 -0
  105. data/lib/metric_fu/metrics/flog/report.html.erb +50 -0
  106. data/lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb +34 -0
  107. data/lib/metric_fu/metrics/hotspots/analysis/analyzer_tables.rb +114 -0
  108. data/lib/metric_fu/metrics/hotspots/analysis/grouping.rb +23 -0
  109. data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +12 -0
  110. data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +20 -0
  111. data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +70 -0
  112. data/lib/metric_fu/metrics/hotspots/analysis/ranking.rb +29 -0
  113. data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +91 -0
  114. data/lib/metric_fu/metrics/hotspots/analysis/record.rb +32 -0
  115. data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +24 -0
  116. data/lib/metric_fu/metrics/hotspots/analysis/table.rb +67 -0
  117. data/lib/metric_fu/metrics/hotspots/generator.rb +40 -0
  118. data/lib/metric_fu/metrics/hotspots/hotspot.rb +87 -0
  119. data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +61 -0
  120. data/lib/metric_fu/metrics/hotspots/metric.rb +20 -0
  121. data/lib/metric_fu/metrics/hotspots/report.html.erb +60 -0
  122. data/lib/metric_fu/metrics/rails_best_practices/generator.rb +47 -0
  123. data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +38 -0
  124. data/lib/metric_fu/metrics/rails_best_practices/metric.rb +31 -0
  125. data/lib/metric_fu/metrics/rails_best_practices/report.html.erb +22 -0
  126. data/lib/metric_fu/metrics/rcov/external_client.rb +22 -0
  127. data/lib/metric_fu/metrics/rcov/generator.rb +75 -0
  128. data/lib/metric_fu/metrics/rcov/grapher.rb +37 -0
  129. data/lib/metric_fu/metrics/rcov/hotspot.rb +46 -0
  130. data/lib/metric_fu/metrics/rcov/metric.rb +61 -0
  131. data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +149 -0
  132. data/lib/metric_fu/metrics/rcov/rcov_line.rb +48 -0
  133. data/lib/metric_fu/metrics/rcov/report.html.erb +40 -0
  134. data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +74 -0
  135. data/lib/metric_fu/metrics/reek/generator.rb +97 -0
  136. data/lib/metric_fu/metrics/reek/grapher.rb +55 -0
  137. data/lib/metric_fu/metrics/reek/hotspot.rb +95 -0
  138. data/lib/metric_fu/metrics/reek/metric.rb +26 -0
  139. data/lib/metric_fu/metrics/reek/report.html.erb +35 -0
  140. data/lib/metric_fu/metrics/roodi/generator.rb +41 -0
  141. data/lib/metric_fu/metrics/roodi/grapher.rb +37 -0
  142. data/lib/metric_fu/metrics/roodi/hotspot.rb +39 -0
  143. data/lib/metric_fu/metrics/roodi/metric.rb +24 -0
  144. data/lib/metric_fu/metrics/roodi/report.html.erb +22 -0
  145. data/lib/metric_fu/metrics/saikuro/generator.rb +145 -0
  146. data/lib/metric_fu/metrics/saikuro/hotspot.rb +51 -0
  147. data/lib/metric_fu/metrics/saikuro/metric.rb +31 -0
  148. data/lib/metric_fu/metrics/saikuro/parsing_element.rb +37 -0
  149. data/lib/metric_fu/metrics/saikuro/report.html.erb +71 -0
  150. data/lib/metric_fu/metrics/saikuro/scratch_file.rb +108 -0
  151. data/lib/metric_fu/metrics/stats/generator.rb +82 -0
  152. data/lib/metric_fu/metrics/stats/grapher.rb +40 -0
  153. data/lib/metric_fu/metrics/stats/hotspot.rb +35 -0
  154. data/lib/metric_fu/metrics/stats/metric.rb +28 -0
  155. data/lib/metric_fu/metrics/stats/report.html.erb +44 -0
  156. data/lib/metric_fu/reporter.rb +37 -0
  157. data/lib/metric_fu/reporting/graphs/graph.rb +69 -0
  158. data/lib/metric_fu/reporting/graphs/grapher.rb +66 -0
  159. data/lib/metric_fu/reporting/result.rb +59 -0
  160. data/lib/metric_fu/run.rb +82 -0
  161. data/lib/metric_fu/tasks/metric_fu.rake +54 -0
  162. data/lib/metric_fu/templates/_gem_info.html.erb +8 -0
  163. data/lib/metric_fu/templates/_graph.html.erb +2 -0
  164. data/lib/metric_fu/templates/_report_footer.html.erb +1 -0
  165. data/lib/metric_fu/templates/configuration.rb +25 -0
  166. data/lib/metric_fu/templates/css/bluff.css +15 -0
  167. data/lib/metric_fu/templates/css/buttons.css +82 -0
  168. data/lib/metric_fu/templates/css/default.css +43 -0
  169. data/lib/metric_fu/templates/css/integrity.css +337 -0
  170. data/lib/metric_fu/templates/css/rcov.css +32 -0
  171. data/lib/metric_fu/templates/css/reset.css +7 -0
  172. data/lib/metric_fu/templates/css/syntax.css +19 -0
  173. data/lib/metric_fu/templates/index.html.erb +13 -0
  174. data/lib/metric_fu/templates/javascripts/bluff-min.js +1 -0
  175. data/lib/metric_fu/templates/javascripts/bluff_graph.js +15 -0
  176. data/lib/metric_fu/templates/javascripts/excanvas.js +35 -0
  177. data/lib/metric_fu/templates/javascripts/highcharts.js +294 -0
  178. data/lib/metric_fu/templates/javascripts/highcharts_graph.js +38 -0
  179. data/lib/metric_fu/templates/javascripts/js-class.js +1 -0
  180. data/lib/metric_fu/templates/javascripts/standalone-framework.js +17 -0
  181. data/lib/metric_fu/templates/javascripts/utils.js +9 -0
  182. data/lib/metric_fu/templates/layout.html.erb +41 -0
  183. data/lib/metric_fu/templates/metrics_template.rb +86 -0
  184. data/lib/metric_fu/templates/report.html.erb +31 -0
  185. data/lib/metric_fu/templates/report.rb +41 -0
  186. data/lib/metric_fu/templates/template.rb +247 -0
  187. data/lib/metric_fu/utility.rb +79 -0
  188. data/lib/metric_fu/version.rb +9 -0
  189. data/lib/metric_fu.rb +143 -0
  190. data/metric_fu.gemspec +72 -0
  191. data/spec/capture_warnings.rb +55 -0
  192. data/spec/cli/helper_spec.rb +165 -0
  193. data/spec/dummy/.gitignore +1 -0
  194. data/spec/dummy/.gitkeep +0 -0
  195. data/spec/dummy/.metrics +4 -0
  196. data/spec/dummy/lib/.gitkeep +0 -0
  197. data/spec/dummy/lib/bad_encoding.rb +6 -0
  198. data/spec/dummy/spec/.gitkeep +0 -0
  199. data/spec/fixtures/20090630.yml +7922 -0
  200. data/spec/fixtures/coverage-153.rb +11 -0
  201. data/spec/fixtures/coverage.rb +13 -0
  202. data/spec/fixtures/exit0.sh +3 -0
  203. data/spec/fixtures/exit1.sh +3 -0
  204. data/spec/fixtures/hotspots/flog.yml +86 -0
  205. data/spec/fixtures/hotspots/generator.yml +47 -0
  206. data/spec/fixtures/hotspots/generator_analysis.yml +53 -0
  207. data/spec/fixtures/hotspots/reek.yml +14 -0
  208. data/spec/fixtures/hotspots/roodi.yml +13 -0
  209. data/spec/fixtures/hotspots/saikuro.yml +27 -0
  210. data/spec/fixtures/hotspots/several_metrics.yml +47 -0
  211. data/spec/fixtures/hotspots/stats.yml +4 -0
  212. data/spec/fixtures/hotspots/three_metrics_on_same_file.yml +36 -0
  213. data/spec/fixtures/line_numbers/foo.rb +33 -0
  214. data/spec/fixtures/line_numbers/module.rb +11 -0
  215. data/spec/fixtures/line_numbers/module_surrounds_class.rb +15 -0
  216. data/spec/fixtures/line_numbers/two_classes.rb +11 -0
  217. data/spec/fixtures/metric_missing.yml +1 -0
  218. data/spec/fixtures/rcov_output.txt +135 -0
  219. data/spec/fixtures/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  220. data/spec/fixtures/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  221. data/spec/fixtures/saikuro/index_cyclo.html +155 -0
  222. data/spec/fixtures/saikuro_sfiles/thing.rb_cyclo.html +11 -0
  223. data/spec/metric_fu/calculate_spec.rb +21 -0
  224. data/spec/metric_fu/configuration_spec.rb +90 -0
  225. data/spec/metric_fu/data_structures/line_numbers_spec.rb +63 -0
  226. data/spec/metric_fu/data_structures/location_spec.rb +110 -0
  227. data/spec/metric_fu/formatter/configuration_spec.rb +44 -0
  228. data/spec/metric_fu/formatter/html_spec.rb +138 -0
  229. data/spec/metric_fu/formatter/yaml_spec.rb +61 -0
  230. data/spec/metric_fu/formatter_spec.rb +49 -0
  231. data/spec/metric_fu/gem_version_spec.rb +12 -0
  232. data/spec/metric_fu/generator_spec.rb +130 -0
  233. data/spec/metric_fu/loader_spec.rb +10 -0
  234. data/spec/metric_fu/metric_spec.rb +46 -0
  235. data/spec/metric_fu/metrics/cane/configuration_spec.rb +22 -0
  236. data/spec/metric_fu/metrics/cane/generator_spec.rb +184 -0
  237. data/spec/metric_fu/metrics/churn/configuration_spec.rb +13 -0
  238. data/spec/metric_fu/metrics/churn/generator_spec.rb +64 -0
  239. data/spec/metric_fu/metrics/flay/configuration_spec.rb +13 -0
  240. data/spec/metric_fu/metrics/flay/generator_spec.rb +105 -0
  241. data/spec/metric_fu/metrics/flay/grapher_spec.rb +57 -0
  242. data/spec/metric_fu/metrics/flog/configuration_spec.rb +18 -0
  243. data/spec/metric_fu/metrics/flog/generator_spec.rb +77 -0
  244. data/spec/metric_fu/metrics/flog/grapher_spec.rb +107 -0
  245. data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +104 -0
  246. data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +71 -0
  247. data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +30 -0
  248. data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +97 -0
  249. data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +6 -0
  250. data/spec/metric_fu/metrics/hotspots/generator_spec.rb +46 -0
  251. data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +10 -0
  252. data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +16 -0
  253. data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +55 -0
  254. data/spec/metric_fu/metrics/rails_best_practices/generator_spec.rb +33 -0
  255. data/spec/metric_fu/metrics/rails_best_practices/grapher_spec.rb +62 -0
  256. data/spec/metric_fu/metrics/rcov/configuration_spec.rb +28 -0
  257. data/spec/metric_fu/metrics/rcov/generator_spec.rb +22 -0
  258. data/spec/metric_fu/metrics/rcov/grapher_spec.rb +57 -0
  259. data/spec/metric_fu/metrics/rcov/hotspot_spec.rb +20 -0
  260. data/spec/metric_fu/metrics/rcov/rcov_line_spec.rb +89 -0
  261. data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +67 -0
  262. data/spec/metric_fu/metrics/reek/configuration_spec.rb +13 -0
  263. data/spec/metric_fu/metrics/reek/generator_spec.rb +169 -0
  264. data/spec/metric_fu/metrics/reek/grapher_spec.rb +66 -0
  265. data/spec/metric_fu/metrics/roodi/configuration_spec.rb +14 -0
  266. data/spec/metric_fu/metrics/roodi/generator_spec.rb +82 -0
  267. data/spec/metric_fu/metrics/roodi/grapher_spec.rb +57 -0
  268. data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +25 -0
  269. data/spec/metric_fu/metrics/saikuro/generator_spec.rb +71 -0
  270. data/spec/metric_fu/metrics/stats/generator_spec.rb +96 -0
  271. data/spec/metric_fu/metrics/stats/grapher_spec.rb +69 -0
  272. data/spec/metric_fu/reporter_spec.rb +41 -0
  273. data/spec/metric_fu/reporting/graphs/graph_spec.rb +44 -0
  274. data/spec/metric_fu/reporting/graphs/grapher_spec.rb +24 -0
  275. data/spec/metric_fu/reporting/result_spec.rb +50 -0
  276. data/spec/metric_fu/run_spec.rb +197 -0
  277. data/spec/metric_fu/templates/configuration_spec.rb +51 -0
  278. data/spec/metric_fu/templates/metrics_template_spec.rb +11 -0
  279. data/spec/metric_fu/templates/report_spec.rb +15 -0
  280. data/spec/metric_fu/templates/template_spec.rb +233 -0
  281. data/spec/metric_fu/utility_spec.rb +12 -0
  282. data/spec/metric_fu_spec.rb +33 -0
  283. data/spec/quality_spec.rb +114 -0
  284. data/spec/shared/configured.rb +45 -0
  285. data/spec/shared/test_coverage.rb +95 -0
  286. data/spec/spec_helper.rb +54 -0
  287. data/spec/support/deferred_garbaged_collection.rb +33 -0
  288. data/spec/support/helper_methods.rb +32 -0
  289. data/spec/support/matcher_create_file.rb +37 -0
  290. data/spec/support/matcher_create_files.rb +43 -0
  291. data/spec/support/suite.rb +26 -0
  292. data/spec/support/test_fixtures.rb +37 -0
  293. data/spec/support/timeout.rb +7 -0
  294. data/spec/support/usage_test.rb +150 -0
  295. data/spec/usage_test_spec.rb +93 -0
  296. metadata +757 -0
data/lib/metric_fu.rb ADDED
@@ -0,0 +1,143 @@
1
+ # coding: utf-8
2
+ require "metric_fu/version"
3
+ require "forwardable"
4
+ require "pathname"
5
+ require 'pry-byebug'
6
+ module MetricFu
7
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
8
+ LIB_ROOT = File.join(APP_ROOT, "lib/metric_fu")
9
+
10
+ module_function
11
+
12
+ def root
13
+ @app_root ||= Pathname(APP_ROOT)
14
+ end
15
+
16
+ def metric_url
17
+ "https://github.com/metricfu/metric_fu"
18
+ end
19
+
20
+ def metric_name
21
+ "MetricFu"
22
+ end
23
+
24
+ def run_dir
25
+ @run_dir ||= Dir.pwd
26
+ end
27
+
28
+ def run_path
29
+ Pathname(run_dir)
30
+ end
31
+
32
+ def run_dir=(run_dir)
33
+ @run_dir = run_dir
34
+ end
35
+
36
+ def report_name
37
+ @report_name || self.report_name = run_path.basename.to_s
38
+ end
39
+
40
+ def report_name=(report_name)
41
+ @report_name = report_name
42
+ end
43
+
44
+ # The time at analyzed code state
45
+ def report_time
46
+ Time.now
47
+ end
48
+
49
+ def report_date_string
50
+ report_time.strftime("%Y%m%d")
51
+ end
52
+
53
+ # @return [String]
54
+ # @example '20140323'
55
+ # Used to uniquely identify reports
56
+ # as a sortable reference to when the report
57
+ # was generated
58
+ def report_id
59
+ report_date_string
60
+ end
61
+
62
+ # Non-date-specific; Used to uniquely identify a report run
63
+ def report_fingerprint
64
+ report_time.to_i.to_s
65
+ end
66
+
67
+ # The time the metrics are generated
68
+ def current_time
69
+ Time.now.localtime
70
+ end
71
+
72
+ def root_dir
73
+ APP_ROOT
74
+ end
75
+
76
+ def lib_dir
77
+ LIB_ROOT
78
+ end
79
+
80
+ require "metric_fu/loader"
81
+ LOADER = MetricFu::Loader.new(LIB_ROOT)
82
+ def loader
83
+ LOADER
84
+ end
85
+ extend SingleForwardable
86
+
87
+ def_delegators :loader, :lib_require, :load_tasks
88
+
89
+ def library_dirs
90
+ %w(metrics formatter reporting logging errors data_structures tasks)
91
+ end
92
+
93
+ loader.create_dirs(self) do
94
+ library_dirs
95
+ end
96
+
97
+ # @note artifact_dir is relative to where the task is being run,
98
+ # not to the metric_fu library
99
+ require "metric_fu/io"
100
+ def artifact_dir
101
+ MetricFu::Io::FileSystem.artifact_dir
102
+ end
103
+
104
+ def artifact_subdirs
105
+ %w(scratch output _data)
106
+ end
107
+
108
+ loader.create_artifact_subdirs(self) do
109
+ artifact_subdirs
110
+ end
111
+
112
+ loader.setup
113
+
114
+ def reset
115
+ # TODO Don't like how this method needs to know
116
+ # all of these class variables that are defined
117
+ # in separate classes.
118
+ @configuration = nil
119
+ @graph = nil
120
+ @result = nil
121
+ end
122
+
123
+ def run(options)
124
+ MetricFu::Run.new.run(options)
125
+ end
126
+
127
+ def run_only(metrics_to_run_names, options)
128
+ metrics_to_run_names = Array(metrics_to_run_names).map(&:to_s)
129
+ MetricFu::Configuration.run do |config|
130
+ config.configure_metrics.each do |metric|
131
+ metric_name = metric.name.to_s
132
+ if metrics_to_run_names.include?(metric_name)
133
+ p "Enabling #{metric_name}"
134
+ metric.enabled = true
135
+ else
136
+ p "Disabling #{metric_name}"
137
+ metric.enabled = false
138
+ end
139
+ end
140
+ end
141
+ run(options)
142
+ end
143
+ end
data/metric_fu.gemspec ADDED
@@ -0,0 +1,72 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "metric_fu/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "code_metric_fu"
7
+ s.homepage = "https://github.com/rainchen/code_metric_fu"
8
+ s.summary = "A fistful of code metrics, with awesome templates and graphs(forked metric_fu)"
9
+ s.description = "Code metrics from Flog, Flay, Saikuro, Churn, Reek, Roodi, Code Statistics, and Rails Best Practices. (and optionally RCov)"
10
+ s.email = "github@benjaminfleischer.com"
11
+ author_file = File.expand_path("AUTHORS", File.dirname(__FILE__))
12
+ s.authors = File.readlines(author_file, encoding: Encoding::UTF_8).map(&:strip)
13
+
14
+ # used with gem i metric_fu -P HighSecurity
15
+ s.cert_chain = ["certs/bf4.pem"]
16
+ # Sign gem when evaluating spec with `gem` command
17
+ # unless ENV has set a SKIP_GEM_SIGNING
18
+ if ($0 =~ /gem\z/) and not ENV.include?("SKIP_GEM_SIGNING")
19
+ s.signing_key = File.join(Gem.user_home, ".ssh", "gem-private_key.pem")
20
+ end
21
+
22
+ s.rubyforge_project = "metric_fu"
23
+ s.license = "MIT"
24
+ s.platform = Gem::Platform::RUBY
25
+ s.version = MetricFu::VERSION
26
+ s.required_ruby_version = ">= 1.9.0"
27
+ s.required_rubygems_version = ">= 1.3.6"
28
+
29
+ tracked_files = `git ls-files`.split($\)
30
+ excluded_dirs = %r{\Aetc}
31
+ files = tracked_files.reject { |file| file[excluded_dirs] }
32
+ test_files = files.grep(%r{^(test|spec|features)/})
33
+ executables = files.grep(%r{^bin/}).map { |f| File.basename(f) }
34
+ s.files = files
35
+ s.test_files = test_files
36
+ s.executables = executables
37
+ s.default_executable = "metric_fu"
38
+ s.require_paths = ["lib"]
39
+
40
+ s.has_rdoc = true
41
+ s.extra_rdoc_files = ["HISTORY.md", "CONTRIBUTING.md", "TODO.md", "MIT-LICENSE"]
42
+ s.rdoc_options = ["--main", "README.md"]
43
+
44
+ # metric dependencies
45
+ s.add_runtime_dependency "flay", [">= 2.0.1", "~> 2.1"]
46
+ s.add_runtime_dependency "churn", ["~> 0.0.35"]
47
+ s.add_runtime_dependency "flog", [">= 4.1.1", "~> 4.1"]
48
+ s.add_runtime_dependency "reek", [">= 1.3.4", "< 5.0"]
49
+ s.add_runtime_dependency "cane", [">= 2.5.2", "~> 2.5"]
50
+ s.add_runtime_dependency "rails_best_practices", [">= 1.14.3", "~> 1.14"]
51
+ s.add_runtime_dependency "metric_fu-Saikuro", [">= 1.1.3", "~> 1.1"]
52
+ s.add_runtime_dependency "roodi", ["~> 5.0.0"]
53
+ s.add_runtime_dependency "code_metrics", ["~> 0.1"]
54
+
55
+ # other dependencies
56
+ # ruby version identification
57
+ s.add_runtime_dependency "redcard"
58
+ # syntax highlighting
59
+ s.add_runtime_dependency "coderay"
60
+ # to_json support
61
+ s.add_runtime_dependency "multi_json"
62
+ # open browser support
63
+ s.add_runtime_dependency "launchy", "~> 2.0"
64
+
65
+ s.add_development_dependency "pry-byebug", '~> 3.4'
66
+ s.add_development_dependency "rspec", "~> 3.1"
67
+ # temporary filesystem to act on
68
+ s.add_development_dependency "test_construct"
69
+ # ensure we have a JSON parser
70
+ s.add_development_dependency "json"
71
+ s.add_development_dependency "simplecov", "~> 0.9"
72
+ end
@@ -0,0 +1,55 @@
1
+ # https://raw.githubusercontent.com/metric_fu/metric_fu/master/spec/capture_warnings.rb
2
+ require "rubygems" if RUBY_VERSION =~ /^1\.8/
3
+ require "bundler/setup"
4
+ require "rspec/core"
5
+ require "rspec/expectations"
6
+ require "tempfile"
7
+ require "fileutils"
8
+
9
+ stderr_file = Tempfile.new("app.stderr")
10
+ app_root ||= Dir.pwd
11
+ output_dir = File.join(app_root, "tmp")
12
+ FileUtils.mkdir_p(output_dir)
13
+ bundle_dir = File.join(app_root, "bundle")
14
+
15
+ RSpec.configure do |config|
16
+ config.before(:suite) do
17
+ $stderr.reopen(stderr_file.path)
18
+ $VERBOSE = true
19
+ end
20
+
21
+ config.after(:suite) do
22
+ stderr_file.rewind
23
+ lines = stderr_file.read.split("\n").uniq
24
+ stderr_file.close!
25
+
26
+ $stderr.reopen(STDERR)
27
+
28
+ app_warnings, other_warnings = lines.partition { |line|
29
+ line.include?(app_root) && !line.include?(bundle_dir)
30
+ }
31
+
32
+ if app_warnings.any?
33
+ puts <<-WARNINGS
34
+ #{'-' * 30} app warnings: #{'-' * 30}
35
+
36
+ #{app_warnings.join("\n")}
37
+
38
+ #{'-' * 75}
39
+ WARNINGS
40
+ end
41
+
42
+ if other_warnings.any?
43
+ output_file = File.join(output_dir, "warnings.txt")
44
+ File.write(output_file, other_warnings.join("\n") << "\n")
45
+ puts
46
+ puts "Non-app warnings written to tmp/warnings.txt"
47
+ puts
48
+ end
49
+
50
+ # fail the build...
51
+ if app_warnings.any?
52
+ abort "Failing build due to app warnings: #{app_warnings.inspect}"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,165 @@
1
+ require "spec_helper"
2
+ require "metric_fu/cli/helper"
3
+ MetricFu.configuration.configure_metric(:rcov) do |rcov|
4
+ rcov.enabled = true
5
+ end
6
+ MetricFu.configure
7
+
8
+ describe MetricFu::Cli::Helper do
9
+ describe "defaults" do
10
+ let(:helper) { MetricFu::Cli::Helper.new }
11
+ let(:defaults) { helper.process_options }
12
+
13
+ context "on every Ruby version" do
14
+ it "opens the report in a browser" do
15
+ expect(defaults[:open]).to be_truthy
16
+ end
17
+
18
+ it "enables Flay" do
19
+ expect(defaults[:flay]).to be_truthy
20
+ end
21
+
22
+ it "enables Reek" do
23
+ expect(defaults[:reek]).to be_truthy
24
+ end
25
+
26
+ it "enables Hotspots" do
27
+ expect(defaults[:hotspots]).to be_truthy
28
+ end
29
+
30
+ it "enables Churn" do
31
+ expect(defaults[:churn]).to be_truthy
32
+ end
33
+
34
+ it "enables Saikuro" do
35
+ expect(defaults[:saikuro]).to be_truthy
36
+ end
37
+
38
+ if MetricFu.configuration.mri?
39
+ it "enables Flog" do
40
+ !expect(defaults[:flog]).to be_truthy
41
+ end
42
+
43
+ it "enables Cane" do
44
+ expect(defaults[:cane]).to be_truthy
45
+ end
46
+ end
47
+
48
+ it "enables RCov" do
49
+ expect(defaults[:rcov]).to be_truthy
50
+ end
51
+
52
+ it "runs by default" do
53
+ expect(defaults[:run]).to be_truthy
54
+ end
55
+ end
56
+
57
+ if MetricFu.configuration.mri?
58
+
59
+ it "enables Rails Best Practices" do
60
+ expect(defaults[:rails_best_practices]).to be_truthy
61
+ end
62
+
63
+ end
64
+ end
65
+
66
+ describe ".parse" do
67
+ let(:helper) { MetricFu::Cli::Helper.new }
68
+
69
+ it "turns open in browser off" do
70
+ expect(helper.process_options(["--no-open"])[:open]).to be_falsey
71
+ end
72
+
73
+ it "turns open in browser on" do
74
+ expect(helper.process_options(["--open"])[:open]).to be_truthy
75
+ end
76
+
77
+ it "turns saikuro off" do
78
+ expect(helper.process_options(["--no-saikuro"])[:saikuro]).to be_falsey
79
+ end
80
+
81
+ it "turns saikuro on" do
82
+ expect(helper.process_options(["--saikuro"])[:saikuro]).to be_truthy
83
+ end
84
+
85
+ it "turns churn off" do
86
+ expect(helper.process_options(["--no-churn"])[:churn]).to be_falsey
87
+ end
88
+
89
+ it "turns churn on" do
90
+ expect(helper.process_options(["--churn"])[:churn]).to be_truthy
91
+ end
92
+
93
+ it "turns flay off" do
94
+ expect(helper.process_options(["--no-flay"])[:flay]).to be_falsey
95
+ end
96
+
97
+ it "turns flay on" do
98
+ expect(helper.process_options(["--flay"])[:flay]).to be_truthy
99
+ end
100
+
101
+ if MetricFu.configuration.mri?
102
+
103
+ it "turns flog off" do
104
+ expect(helper.process_options(["--no-flog"])[:flog]).to be_falsey
105
+ end
106
+
107
+ it "turns flog on" do
108
+ expect(helper.process_options(["--flog"])[:flog]).to be_truthy
109
+ end
110
+
111
+ it "turns cane off" do
112
+ expect(helper.process_options(["--no-cane"])[:cane]).to be_falsey
113
+ end
114
+
115
+ it "turns cane on" do
116
+ expect(helper.process_options(["--cane"])[:cane]).to be_truthy
117
+ end
118
+
119
+ end
120
+
121
+ it "turns hotspots off" do
122
+ expect(helper.process_options(["--no-hotspots"])[:hotspots]).to be_falsey
123
+ end
124
+
125
+ it "turns hotspots on" do
126
+ expect(helper.process_options(["--hotspots"])[:hotspots]).to be_truthy
127
+ end
128
+
129
+ it "turns rcov off" do
130
+ expect(helper.process_options(["--no-rcov"])[:rcov]).to be_falsey
131
+ end
132
+
133
+ it "turns rcov on" do
134
+ expect(helper.process_options(["--rcov"])[:rcov]).to be_truthy
135
+ end
136
+
137
+ it "turns reek off" do
138
+ expect(helper.process_options(["--no-reek"])[:reek]).to be_falsey
139
+ end
140
+
141
+ it "turns reek on" do
142
+ expect(helper.process_options(["--reek"])[:reek]).to be_truthy
143
+ end
144
+
145
+ it "turns roodi off" do
146
+ expect(helper.process_options(["--no-roodi"])[:roodi]).to be_falsey
147
+ end
148
+
149
+ it "turns roodi on" do
150
+ expect(helper.process_options(["--roodi"])[:roodi]).to be_truthy
151
+ end
152
+
153
+ context "given a single format" do
154
+ it "sets the format" do
155
+ expect(helper.process_options(["--format", "json"])[:format]).to eq([["json"]])
156
+ end
157
+ end
158
+
159
+ context "given multiple formats" do
160
+ it "sets multiple formats" do
161
+ expect(helper.process_options(["--format", "json", "--format", "yaml"])[:format]).to eq([["json"], ["yaml"]])
162
+ end
163
+ end
164
+ end
165
+ end
@@ -0,0 +1 @@
1
+ tmp
File without changes
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # For testing that this file gets loaded
4
+ $metric_file_loaded = true
File without changes
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
2
+ class SomeClass
3
+ def initialize(_a, _b, _c)
4
+ "hey, invalid ASCII\xED"
5
+ end
6
+ end
File without changes