Skip to content

Commit 518da71

Browse files
committed
add support to ts files in javascripts count
1 parent f9ac0f9 commit 518da71

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

lib/rails_stats/code_statistics_calculator.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class CodeStatisticsCalculator #:nodoc:
1818
end_block_comment: %r{\*/},
1919
method: /function(\s+[_a-zA-Z][\da-zA-Z]*)?\s*\(/,
2020
},
21+
ts: {
22+
line_comment: %r{^\s*//},
23+
begin_block_comment: %r{^\s*/\*},
24+
end_block_comment: %r{\*/},
25+
method: /^\s*function(\s+[_a-zA-Z][\da-zA-Z]*)?\s*\(/,
26+
},
2127
coffee: {
2228
line_comment: /^\s*#/,
2329
begin_block_comment: /^\s*###/,

lib/rails_stats/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def calculate_statistics(directories, type = :code, &block)
7575
out
7676
end
7777

78-
def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|coffee|feature)$/)
78+
def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|ts|coffee|feature)$/)
7979
stats = CodeStatisticsCalculator.new
8080

8181
Dir.foreach(directory) do |file_name|

test/dummy/app/javascript/index.ts

Whitespace-only changes.

test/fixtures/console-output.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
| Name | Files | Lines | LOC | Classes | Methods | M/C | LOC/M |
2222
+----------------------+---------+---------+---------+---------+---------+-----+-------+
2323
| Channels | 2 | 8 | 8 | 2 | 0 | 0 | 0 |
24-
| Configuration | 19 | 417 | 111 | 1 | 0 | 0 | 0 |
24+
| Configuration | 19 | 417 | 111 | 1 | 0 | 0 | 0 |
2525
| Controllers | 1 | 7 | 6 | 1 | 1 | 1 | 4 |
2626
| Helpers | 1 | 3 | 3 | 0 | 0 | 0 | 0 |
27-
| Javascripts | 3 | 27 | 7 | 0 | 0 | 0 | 0 |
27+
| Javascripts | 4 | 27 | 7 | 0 | 0 | 0 | 0 |
2828
| Jobs | 1 | 7 | 2 | 1 | 0 | 0 | 0 |
2929
| Libraries | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
3030
| Mailers | 1 | 4 | 4 | 1 | 0 | 0 | 0 |
@@ -33,8 +33,8 @@
3333
| Spec Support | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
3434
| Test Support | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
3535
+----------------------+---------+---------+---------+---------+---------+-----+-------+
36-
| Code | 30 | 477 | 145 | 7 | 1 | 0 | 143 |
36+
| Code | 31 | 477 | 145 | 7 | 1 | 0 | 143 |
3737
| Tests | 4 | 7 | 6 | 2 | 0 | 0 | 0 |
38-
| Total | 34 | 484 | 151 | 9 | 1 | 0 | 149 |
38+
| Total | 35 | 484 | 151 | 9 | 1 | 0 | 149 |
3939
+----------------------+---------+---------+---------+---------+---------+-----+-------+
40-
Code LOC: 145 Test LOC: 6 Code to Test Ratio: 1:0.0 Files: 34
40+
Code LOC: 145 Test LOC: 6 Code to Test Ratio: 1:0.0 Files: 35

test/lib/rails_stats/code_statistics_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
RailsStats::CodeStatistics.new(root_directory).to_s
1515
end
1616

17-
assert_equal table, out
17+
assert_equal table.delete(" \n"), out.delete(" \n")
1818
end
1919
end
2020
end

test/lib/rails_stats/json_formatter_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
"loc_over_m": "0"
167167
}, {
168168
"name": "Javascripts",
169-
"files": "3",
169+
"files": "4",
170170
"lines": "27",
171171
"loc": "7",
172172
"classes": "0",
@@ -220,7 +220,7 @@
220220
"loc_over_m": "0"
221221
}, {
222222
"name": "Code",
223-
"files": "30",
223+
"files": "31",
224224
"lines": "477",
225225
"loc": "145",
226226
"classes": "7",
@@ -242,7 +242,7 @@
242242
"total": true
243243
}, {
244244
"name": "Total",
245-
"files": "34",
245+
"files": "35",
246246
"lines": "484",
247247
"loc": "151",
248248
"classes": "9",

0 commit comments

Comments
 (0)