Skip to content

Add TS|TSX|JSX files count in javascripts count #42

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [BUGFIX: Fix JSON output missing Code and Tests total count](https://github.com/fastruby/rails_stats/pull/40)
* Update README examples
* [FEATURE: Output number of tables created from schema.rb or structure.sql, add polymorphic models count](https://github.com/fastruby/rails_stats/pull/37)
* [FEATURE: Add TS|TSX|JSX files count to Javascripts](https://github.com/fastruby/rails_stats/pull/42)

# v2.0.1 ([commits](https://github.com/fastruby/rails_stats/compare/v2.0.0...v2.0.1))

Expand Down
18 changes: 18 additions & 0 deletions lib/rails_stats/code_statistics_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ class CodeStatisticsCalculator #:nodoc:
end_block_comment: %r{\*/},
method: /function(\s+[_a-zA-Z][\da-zA-Z]*)?\s*\(/,
},
jsx: {
line_comment: %r{^\s*//},
begin_block_comment: %r{^\s*/\*},
end_block_comment: %r{\*/},
method: /^\s*function(\s+[_a-zA-Z][\da-zA-Z]*)?\s*\(/,
},
ts: {
line_comment: %r{^\s*//},
begin_block_comment: %r{^\s*/\*},
end_block_comment: %r{\*/},
method: /^\s*function(\s+[_a-zA-Z][\da-zA-Z]*)?\s*\(/,
},
tsx: {
line_comment: %r{^\s*//},
begin_block_comment: %r{^\s*/\*},
end_block_comment: %r{\*/},
method: /^\s*function(\s+[_a-zA-Z][\da-zA-Z]*)?\s*\(/,
},
coffee: {
line_comment: /^\s*#/,
begin_block_comment: /^\s*###/,
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_stats/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def calculate_statistics(directories, type = :code, &block)
out
end

def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|coffee|feature)$/)
def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|jsx|ts|tsx|coffee|feature)$/)
stats = CodeStatisticsCalculator.new

Dir.foreach(directory) do |file_name|
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/javascript/dummy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
Empty file.
8 changes: 4 additions & 4 deletions test/fixtures/console-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
| Configuration | 19 | 417 | 111 | 1 | 0 | 0 | 0 |
| Controllers | 1 | 7 | 6 | 1 | 1 | 1 | 4 |
| Helpers | 1 | 3 | 3 | 0 | 0 | 0 | 0 |
| Javascripts | 3 | 27 | 7 | 0 | 0 | 0 | 0 |
| Javascripts | 6 | 28 | 7 | 0 | 0 | 0 | 0 |
| Jobs | 1 | 7 | 2 | 1 | 0 | 0 | 0 |
| Libraries | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| Mailers | 1 | 4 | 4 | 1 | 0 | 0 | 0 |
Expand All @@ -33,11 +33,11 @@
| Spec Support | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| Test Support | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
+----------------------+---------+---------+---------+---------+---------+-----+-------+
| Code | 33 | 484 | 152 | 10 | 1 | 0 | 150 |
| Code | 36 | 485 | 152 | 10 | 1 | 0 | 150 |
| Tests | 4 | 7 | 6 | 2 | 0 | 0 | 0 |
| Total | 37 | 491 | 158 | 12 | 1 | 0 | 156 |
| Total | 40 | 492 | 158 | 12 | 1 | 0 | 156 |
+----------------------+---------+---------+---------+---------+---------+-----+-------+
Code LOC: 152 Test LOC: 6 Code to Test Ratio: 1:0.0 Files: 37
Code LOC: 152 Test LOC: 6 Code to Test Ratio: 1:0.0 Files: 40

Polymorphic models count: 1 polymorphic associations
Schema Stats: 2 `create_table` calls in schema.rb
12 changes: 6 additions & 6 deletions test/lib/rails_stats/json_formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
"loc_over_m": "0"
}, {
"name": "Javascripts",
"files": "3",
"lines": "27",
"files": "6",
"lines": "28",
"loc": "7",
"classes": "0",
"methods": "0",
Expand Down Expand Up @@ -220,8 +220,8 @@
"loc_over_m": "0"
}, {
"name": "Code",
"files": "33",
"lines": "484",
"files": "36",
"lines": "485",
"loc": "152",
"classes": "10",
"methods": "1",
Expand All @@ -242,8 +242,8 @@
"total": true
}, {
"name": "Total",
"files": "37",
"lines": "491",
"files": "40",
"lines": "492",
"loc": "158",
"classes": "12",
"methods": "1",
Expand Down