-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjavascript.py
More file actions
63 lines (47 loc) · 2.28 KB
/
javascript.py
File metadata and controls
63 lines (47 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from gitevo import GitEvo, ParsedCommit
remote = 'https://github.com/expressjs/express'
# remote = 'https://github.com/facebook/react'
# remote = 'https://github.com/vercel/next.js'
# remote = 'https://github.com/sveltejs/svelte'
# remote = 'https://github.com/nodejs/node'
evo = GitEvo(repo=remote, extension='.js')
@evo.metric('Lines of code (LOC)', show_version_chart=False)
def loc(commit: ParsedCommit):
return commit.loc
@evo.metric('JavaScript files', show_version_chart=False)
def files(commit: ParsedCommit):
return len(commit.parsed_files)
@evo.metric('LOC / JavaScript files', show_version_chart=False)
def loc_per_file(commit: ParsedCommit):
parsed_files = len(commit.parsed_files)
if parsed_files == 0: return 0
return commit.loc / parsed_files
@evo.metric('Classes', categorical=True)
def classes(commit: ParsedCommit):
return commit.find_node_types(['class_declaration'])
@evo.metric('Variable declarations', categorical=True)
def variable_declarations(commit: ParsedCommit):
return commit.find_node_types(['const', 'let', 'var'])
@evo.metric('Functions', categorical=True)
def functions(commit: ParsedCommit):
method_nodes = ['function_declaration', 'method_definition', 'generator_function_declaration',
'arrow_function', 'generator_function', 'function_expression']
return commit.find_node_types(method_nodes)
@evo.metric('Conditionals', categorical=True)
def conditionals(commit: ParsedCommit):
return commit.find_node_types(['if_statement', 'switch_statement', 'ternary_expression'])
@evo.metric('Loops', categorical=True)
def loops(commit: ParsedCommit):
return commit.find_node_types(['for_statement', 'while_statement', 'for_in_statement', 'do_statement'])
@evo.metric('Exception statements', categorical=True)
def expections(commit: ParsedCommit):
return commit.find_node_types(['try_statement', 'throw_statement'])
@evo.metric('Await expression', categorical=True, show_version_chart=False)
def await_expression(commit: ParsedCommit):
return commit.find_node_types(['await_expression'])
@evo.metric('Comments', categorical=True, show_version_chart=False)
def comments(commit: ParsedCommit):
return commit.find_node_types(['comment'])
def as_str(text: bytes) -> str:
return text.decode('utf-8')
evo.run()