From 09f7fee068b27f8a683ccf22d6c35f1f42092995 Mon Sep 17 00:00:00 2001 From: Henrique Medeiros Date: Thu, 29 May 2025 15:11:46 -0300 Subject: [PATCH 1/4] add support to ts files in javascripts count --- lib/rails_stats/code_statistics_calculator.rb | 6 ++++++ lib/rails_stats/util.rb | 2 +- test/dummy/app/javascript/index.ts | 0 test/fixtures/console-output.txt | 8 ++++---- 4 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 test/dummy/app/javascript/index.ts diff --git a/lib/rails_stats/code_statistics_calculator.rb b/lib/rails_stats/code_statistics_calculator.rb index f881d88..32c1a5d 100644 --- a/lib/rails_stats/code_statistics_calculator.rb +++ b/lib/rails_stats/code_statistics_calculator.rb @@ -18,6 +18,12 @@ class CodeStatisticsCalculator #:nodoc: end_block_comment: %r{\*/}, method: /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*\(/, + }, coffee: { line_comment: /^\s*#/, begin_block_comment: /^\s*###/, diff --git a/lib/rails_stats/util.rb b/lib/rails_stats/util.rb index bbe0d39..1420e7d 100644 --- a/lib/rails_stats/util.rb +++ b/lib/rails_stats/util.rb @@ -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|ts|coffee|feature)$/) stats = CodeStatisticsCalculator.new Dir.foreach(directory) do |file_name| diff --git a/test/dummy/app/javascript/index.ts b/test/dummy/app/javascript/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/console-output.txt b/test/fixtures/console-output.txt index cda0301..c9aa295 100644 --- a/test/fixtures/console-output.txt +++ b/test/fixtures/console-output.txt @@ -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 | 4 | 27 | 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 | @@ -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 | 34 | 484 | 152 | 10 | 1 | 0 | 150 | | Tests | 4 | 7 | 6 | 2 | 0 | 0 | 0 | -| Total | 37 | 491 | 158 | 12 | 1 | 0 | 156 | +| Total | 38 | 491 | 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: 38 Polymorphic models count: 1 polymorphic associations Schema Stats: 2 `create_table` calls in schema.rb From 0e872027b5f42443278975193a581cf6dfff06e9 Mon Sep 17 00:00:00 2001 From: Henrique Medeiros Date: Thu, 29 May 2025 15:28:18 -0300 Subject: [PATCH 2/4] add changelog entry --- CHANGELOG.md | 1 + test/lib/rails_stats/json_formatter_test.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e144329..11b412b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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)) diff --git a/test/lib/rails_stats/json_formatter_test.rb b/test/lib/rails_stats/json_formatter_test.rb index 0f5b0f6..df9cbce 100644 --- a/test/lib/rails_stats/json_formatter_test.rb +++ b/test/lib/rails_stats/json_formatter_test.rb @@ -166,7 +166,7 @@ "loc_over_m": "0" }, { "name": "Javascripts", - "files": "3", + "files": "4", "lines": "27", "loc": "7", "classes": "0", @@ -220,7 +220,7 @@ "loc_over_m": "0" }, { "name": "Code", - "files": "33", + "files": "34", "lines": "484", "loc": "152", "classes": "10", @@ -242,7 +242,7 @@ "total": true }, { "name": "Total", - "files": "37", + "files": "38", "lines": "491", "loc": "158", "classes": "12", From 0c087a82305e8bf645bcacc1a667595de7bd5879 Mon Sep 17 00:00:00 2001 From: Henrique Medeiros Date: Fri, 30 May 2025 09:25:55 -0300 Subject: [PATCH 3/4] add jsx and tsx files to count --- CHANGELOG.md | 2 +- lib/rails_stats/util.rb | 2 +- test/dummy/app/javascript/dummy.jsx | 1 + test/dummy/app/javascript/dummy.tsx | 0 test/fixtures/console-output.txt | 8 ++++---- test/lib/rails_stats/json_formatter_test.rb | 12 ++++++------ 6 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 test/dummy/app/javascript/dummy.jsx create mode 100644 test/dummy/app/javascript/dummy.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 11b412b..5b33b72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +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 files count to Javascripts](https://github.com/fastruby/rails_stats/pull/42) +* [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)) diff --git a/lib/rails_stats/util.rb b/lib/rails_stats/util.rb index 1420e7d..f9baf45 100644 --- a/lib/rails_stats/util.rb +++ b/lib/rails_stats/util.rb @@ -75,7 +75,7 @@ def calculate_statistics(directories, type = :code, &block) out end - def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|ts|coffee|feature)$/) + def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|jsx|ts|tsx|coffee|feature)$/) stats = CodeStatisticsCalculator.new Dir.foreach(directory) do |file_name| diff --git a/test/dummy/app/javascript/dummy.jsx b/test/dummy/app/javascript/dummy.jsx new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/dummy/app/javascript/dummy.jsx @@ -0,0 +1 @@ + diff --git a/test/dummy/app/javascript/dummy.tsx b/test/dummy/app/javascript/dummy.tsx new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/console-output.txt b/test/fixtures/console-output.txt index c9aa295..ffdca26 100644 --- a/test/fixtures/console-output.txt +++ b/test/fixtures/console-output.txt @@ -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 | 4 | 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 | @@ -33,11 +33,11 @@ | Spec Support | 1 | 1 | 1 | 0 | 0 | 0 | 0 | | Test Support | 1 | 1 | 1 | 0 | 0 | 0 | 0 | +----------------------+---------+---------+---------+---------+---------+-----+-------+ -| Code | 34 | 484 | 152 | 10 | 1 | 0 | 150 | +| Code | 36 | 485 | 152 | 10 | 1 | 0 | 150 | | Tests | 4 | 7 | 6 | 2 | 0 | 0 | 0 | -| Total | 38 | 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: 38 + 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 diff --git a/test/lib/rails_stats/json_formatter_test.rb b/test/lib/rails_stats/json_formatter_test.rb index df9cbce..8bce6ba 100644 --- a/test/lib/rails_stats/json_formatter_test.rb +++ b/test/lib/rails_stats/json_formatter_test.rb @@ -166,8 +166,8 @@ "loc_over_m": "0" }, { "name": "Javascripts", - "files": "4", - "lines": "27", + "files": "6", + "lines": "28", "loc": "7", "classes": "0", "methods": "0", @@ -220,8 +220,8 @@ "loc_over_m": "0" }, { "name": "Code", - "files": "34", - "lines": "484", + "files": "36", + "lines": "485", "loc": "152", "classes": "10", "methods": "1", @@ -242,8 +242,8 @@ "total": true }, { "name": "Total", - "files": "38", - "lines": "491", + "files": "40", + "lines": "492", "loc": "158", "classes": "12", "methods": "1", From 8cfe4a1746062b4520bff297bdcc78d0847966c3 Mon Sep 17 00:00:00 2001 From: Henrique Medeiros Date: Fri, 30 May 2025 09:38:17 -0300 Subject: [PATCH 4/4] adjust statistics calculator --- lib/rails_stats/code_statistics_calculator.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/rails_stats/code_statistics_calculator.rb b/lib/rails_stats/code_statistics_calculator.rb index 32c1a5d..db7d81e 100644 --- a/lib/rails_stats/code_statistics_calculator.rb +++ b/lib/rails_stats/code_statistics_calculator.rb @@ -18,12 +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*###/,