diff --git a/CHANGELOG.md b/CHANGELOG.md index e144329..5b33b72 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|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/code_statistics_calculator.rb b/lib/rails_stats/code_statistics_calculator.rb index f881d88..db7d81e 100644 --- a/lib/rails_stats/code_statistics_calculator.rb +++ b/lib/rails_stats/code_statistics_calculator.rb @@ -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*###/, diff --git a/lib/rails_stats/util.rb b/lib/rails_stats/util.rb index bbe0d39..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|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/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..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 | 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 | @@ -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 diff --git a/test/lib/rails_stats/json_formatter_test.rb b/test/lib/rails_stats/json_formatter_test.rb index 0f5b0f6..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": "3", - "lines": "27", + "files": "6", + "lines": "28", "loc": "7", "classes": "0", "methods": "0", @@ -220,8 +220,8 @@ "loc_over_m": "0" }, { "name": "Code", - "files": "33", - "lines": "484", + "files": "36", + "lines": "485", "loc": "152", "classes": "10", "methods": "1", @@ -242,8 +242,8 @@ "total": true }, { "name": "Total", - "files": "37", - "lines": "491", + "files": "40", + "lines": "492", "loc": "158", "classes": "12", "methods": "1",