Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JSON output #20

Merged
merged 5 commits into from
Oct 20, 2021
Merged

Support JSON output #20

merged 5 commits into from
Oct 20, 2021

Conversation

etagwerker
Copy link
Member

Hey,

This is a PR which adds support for a JSON formatter (see #12). I'm not sure what is the preferred/best way to tell rake stats to output JSON instead of a table in the console.

This set of changes includes a small-ish refactor:

  • It splits up code_statistics.rb into two (calculator calculates, formatter formats output)
  • It adds a superclass for the formatters

Please check it out when you get a minute.

Thanks!

@codecov
Copy link

codecov bot commented Oct 11, 2021

Codecov Report

Merging #20 (dea39e0) into main (6d7427a) will increase coverage by 3.00%.
The diff coverage is 94.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #20      +/-   ##
==========================================
+ Coverage   69.73%   72.74%   +3.00%     
==========================================
  Files          14       19       +5     
  Lines         598      675      +77     
==========================================
+ Hits          417      491      +74     
- Misses        181      184       +3     
Impacted Files Coverage Δ
lib/rails_stats/tasks.rb 0.00% <0.00%> (ø)
lib/rails_stats/code_statistics.rb 91.66% <87.50%> (-3.79%) ⬇️
lib/rails_stats/stats_calculator.rb 94.66% <94.66%> (ø)
lib/rails_stats/json_formatter.rb 95.65% <95.65%> (ø)
lib/rails_stats/all.rb 100.00% <100.00%> (ø)
lib/rails_stats/console_formatter.rb 100.00% <100.00%> (ø)
lib/rails_stats/stats_formatter.rb 100.00% <100.00%> (ø)
test/lib/rails_stats/json_formatter_test.rb 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d7427a...dea39e0. Read the comment docs.

Copy link
Contributor

@bronzdoc bronzdoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I would suggest making refactors and feature implementation in two different PR's. As a maintainer is harder to review the actual feature implementation

@bronzdoc
Copy link
Contributor

@etagwerker What is the best way to test the changes in this PR?

In order to call the rake task and get JSON output will be like so:

```
rake stats\[test/dummy,json\]
```
@etagwerker
Copy link
Member Author

@bronzdoc Good question, you can test it by doing this:

rake stats\[test/dummy,json\]

If you don't pass the second parameter, or you pass some garbage format, it will show the output as before...

@bronzdoc
Copy link
Contributor

@etagwerker I tried the command you suggested but I still get the output as before

What shell are you using?

Directory: /Users/bronzdoc/projects/rails_stats/test/dummy

+----------------------+---------+---------+---------+---------+-----+-------+
| Name                 | Lines   |     LOC | Classes | Methods | M/C | LOC/M |
+----------------------+---------+---------+---------+---------+-----+-------+
| Channels             |       8 |       8 |       2 |       0 |   0 |     0 |
| Configuration        |     417 |     111 |       1 |       0 |   0 |     0 |
| Controllers          |       7 |       6 |       1 |       1 |   1 |     4 |
| Helpers              |       3 |       3 |       0 |       0 |   0 |     0 |
| Javascripts          |      27 |       7 |       0 |       0 |   0 |     0 |
| Jobs                 |       7 |       2 |       1 |       0 |   0 |     0 |
| Mailers              |       4 |       4 |       1 |       0 |   0 |     0 |
| Models               |       3 |       3 |       1 |       0 |   0 |     0 |
+----------------------+---------+---------+---------+---------+-----+-------+
| Code                 |     476 |     144 |       7 |       1 |   0 |   142 |
| Tests                |       0 |       0 |       0 |       0 |   0 |     0 |
| Total                |     476 |     144 |       7 |       1 |   0 |   142 |
+----------------------+---------+---------+---------+---------+-----+-------+
  Code LOC: 144     Test LOC: 0     Code to Test Ratio: 1:0.0

@etagwerker
Copy link
Member Author

@bronzdoc Weird! Are you using the latest version of this branch?

@bronzdoc
Copy link
Contributor

@etagwerker ahh sorry! that was it! I had an outdated version :)

➜  rails_stats git:(feature/output-json-string) rake stats\[test/dummy,json\]

Directory: /Users/bronzdoc/projects/rails_stats/test/dummy

[{"name":"Mailers","lines":"4","loc":"4","classes":"1","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Models","lines":"3","loc":"3","classes":"1","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Javascripts","lines":"27","loc":"7","classes":"0","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Jobs","lines":"7","loc":"2","classes":"1","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Controllers","lines":"7","loc":"6","classes":"1","methods":"1","m_over_c":"1","loc_over_m":"4"},{"name":"Helpers","lines":"3","loc":"3","classes":"0","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Channels","lines":"8","loc":"8","classes":"2","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Configuration","lines":"417","loc":"111","classes":"1","methods":"0","m_over_c":"0","loc_over_m":"0"},{"name":"Total","lines":"476","loc":"144","classes":"7","methods":"1","m_over_c":"0","loc_over_m":"142","code_to_test_ratio":"0.0","total":true}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants