Skip to content

Commit fe84a70

Browse files
committed
Add complexity recipe for analyzing source files
1 parent 5cf6af3 commit fe84a70

6 files changed

Lines changed: 187 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ CONFIG_DIR ?= $(ROOT_DIR)/etc
4343
# Define the directory for writing reports, including code coverage:
4444
REPORTS_DIR ?= $(ROOT_DIR)/reports
4545
COVERAGE_DIR ?= $(REPORTS_DIR)/coverage
46+
COMPLEXITY_DIR ?= $(REPORTS_DIR)/complexity
4647

4748
# Define the directory for documentation:
4849
DOCS_DIR ?= $(ROOT_DIR)/docs

tools/make/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ include $(TOOLS_MAKE_LIB_DIR)/test-ci/Makefile
3939
include $(TOOLS_MAKE_LIB_DIR)/coverage-service/Makefile
4040
include $(TOOLS_MAKE_LIB_DIR)/benchmark/Makefile
4141
include $(TOOLS_MAKE_LIB_DIR)/examples/Makefile
42+
include $(TOOLS_MAKE_LIB_DIR)/complexity/Makefile
4243
include $(TOOLS_MAKE_LIB_DIR)/docs/Makefile
4344
include $(TOOLS_MAKE_LIB_DIR)/debug/Makefile
4445

tools/make/lib/complexity/Makefile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
# DEPENDENCIES #
3+
4+
include $(TOOLS_MAKE_LIB_DIR)/complexity/javascript.mk
5+
6+
7+
# TARGETS #
8+
9+
# Generate a complexity report.
10+
#
11+
# This target analyzes source code and generates a complexity report.
12+
13+
complexity: complexity-javascript
14+
15+
.PHONY: complexity
16+
17+
18+
# Analyze source code complexity.
19+
#
20+
# This target analyzes only source files.
21+
22+
complexity-src: complexity-javascript-src
23+
24+
.PHONY: complexity-src
25+
26+
27+
# Analyze test code complexity.
28+
#
29+
# This target analyzes only test files.
30+
31+
complexity-tests: complexity-javascript-tests
32+
33+
.PHONY: complexity-tests
34+
35+
36+
# Analyze example code complexity.
37+
#
38+
# This target analyzes only example files.
39+
40+
complexity-examples: complexity-javascript-examples
41+
42+
.PHONY: complexity-examples
43+
44+
45+
# View a complexity report.
46+
#
47+
# This target opens an HTML complexity report in a local web browser.
48+
49+
view-complexity: view-javascript-complexity
50+
51+
.PHONY: view-complexity
52+
53+
54+
# Remove complexity artifacts.
55+
#
56+
# This target deletes complexity artifacts, such as complexity reports and associated HTML pages.
57+
58+
clean-complexity: clean-javascript-complexity
59+
60+
.PHONY: clean-complexity
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
# VARIABLES #
3+
4+
# Define the analysis tool to use when analyzing JavaScript files:
5+
JAVASCRIPT_COMPLEXITY_TOOL ?= plato
6+
7+
# Define the output directory:
8+
JAVASCRIPT_COMPLEXITY_DIR ?= $(COMPLEXITY_DIR)/javascript
9+
10+
11+
# DEPENDENCIES #
12+
13+
ifeq ($(JAVASCRIPT_COMPLEXITY_TOOL), plato)
14+
include $(TOOLS_MAKE_LIB_DIR)/complexity/plato.mk
15+
endif
16+
17+
18+
# TARGETS #
19+
20+
# Analyze code complexity.
21+
#
22+
# This target analyzes all JavaScript source code.
23+
24+
complexity-javascript: $(NODE_MODULES)
25+
$(JAVASCRIPT_COMPLEXITY) $(JAVASCRIPT_COMPLEXITY_FLAGS) $(SOURCES) $(TESTS) $(EXAMPLES)
26+
27+
.PHONY: complexity-javascript
28+
29+
30+
# Analyze source code complexity.
31+
#
32+
# This target analyzes only JavaScript source files.
33+
34+
complexity-javascript-src: $(NODE_MODULES)
35+
$(JAVASCRIPT_COMPLEXITY) $(JAVASCRIPT_COMPLEXITY_FLAGS) $(SOURCES)
36+
37+
.PHONY: complexity-javascript-src
38+
39+
40+
# Analyze test code complexity.
41+
#
42+
# This target analyzes only JavaScript test files.
43+
44+
complexity-javascript-tests: $(NODE_MODULES)
45+
$(JAVASCRIPT_COMPLEXITY) $(JAVASCRIPT_COMPLEXITY_FLAGS) $(TESTS)
46+
47+
.PHONY: complexity-javascript-tests
48+
49+
50+
# Analyze example code complexity.
51+
#
52+
# This target analyzes only JavaScript example files.
53+
54+
complexity-javascript-examples: $(NODE_MODULES)
55+
$(JAVASCRIPT_COMPLEXITY) $(JAVASCRIPT_COMPLEXITY_FLAGS) $(EXAMPLES)
56+
57+
.PHONY: complexity-javascript-examples
58+
59+
60+
# View a complexity report.
61+
#
62+
# This target opens an HTML JavaScript complexity report in a local web browser.
63+
64+
view-javascript-complexity:
65+
ifeq ($(JAVASCRIPT_COMPLEXITY_TOOL), plato)
66+
@$(MAKE) -f $(this_file) view-plato-report
67+
endif
68+
69+
.PHONY: view-javascript-complexity
70+
71+
72+
# Remove a complexity directory.
73+
#
74+
# This target cleans up a JavaScript complexity directory by removing it entirely.
75+
76+
clean-javascript-complexity:
77+
$(DELETE) $(DELETE_FLAGS) $(JAVASCRIPT_COMPLEXITY_DIR)
78+
79+
.PHONY: clean-javascript-complexity

tools/make/lib/complexity/plato.mk

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
# VARIABLES #
3+
4+
# Determine the host kernel:
5+
KERNEL ?= $(shell uname -s)
6+
7+
# Based on the kernel, determine the `open` command:
8+
ifeq ($(KERNEL), Darwin)
9+
OPEN ?= open
10+
else
11+
OPEN ?= xdg-open
12+
endif
13+
# TODO: add Windows command
14+
15+
# Define the path to the [plato][1] executable.
16+
#
17+
# To install plato:
18+
# $ npm install plato
19+
#
20+
# [1]: https://github.com/es-analysis/plato
21+
22+
JAVASCRIPT_COMPLEXITY ?= $(BIN_DIR)/plato
23+
24+
# Define the title of the report:
25+
PLATO_REPORT_TITLE ?= 'JavaScript Complexity'
26+
27+
# Define the output file path for the HTML report generated by plato:
28+
PLATO_HTML_REPORT ?= $(JAVASCRIPT_COMPLEXITY_DIR)/index.html
29+
30+
# Define the command-line options to use when invoking the plato executable:
31+
JAVASCRIPT_COMPLEXITY_FLAGS ?= \
32+
--dir $(JAVASCRIPT_COMPLEXITY_DIR) \
33+
--title $(PLATO_REPORT_TITLE)
34+
35+
36+
# TARGETS #
37+
38+
# View a complexity report.
39+
#
40+
# This target opens an HTML complexity report in a local web browser.
41+
42+
view-plato-report:
43+
$(OPEN) $(PLATO_HTML_REPORT)
44+
45+
.PHONY: view-plato-report

tools/make/lib/test-cov/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ view-cov: view-javascript-cov
2424
.PHONY: view-cov
2525

2626

27-
# Remove a coverage artifacts.
27+
# Remove coverage artifacts.
2828
#
2929
# This target deletes coverage artifacts, such as coverage reports and associated HTML pages.
3030

0 commit comments

Comments
 (0)