Repository navigation
Expand file tree
/
Copy pathhelp.rs
More file actions
156 lines (135 loc) · 5.42 KB
/
Copy pathhelp.rs
File metadata and controls
156 lines (135 loc) · 5.42 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const HELP_TEXT_BODY: &str = "\
USAGE:
codem8 help
codem8 -h
codem8 --version
codem8 --report-complexity [OPTIONS]
codem8 --report-duplicate [OPTIONS]
COMMANDS:
help
-h
Display this detailed documentation.
--version
Display the current CodeM8 version.
REQUIRED REPORT SWITCHES:
--report-complexity
Analyze supported source files and print a function complexity report.
Cannot be combined with --report-duplicate.
--report-duplicate
Analyze source files and print a duplicate code report.
Cannot be combined with --report-complexity.
OPTIONS:
-file-extension=<extensions>
Comma-separated source file extensions to analyze.
Defaults to all extensions registered in LANGUAGE_PATTERNS.
Examples: -file-extension=ts,tsx,js,jsx
-files=<paths>
Comma-separated explicit files to analyze instead of recursively
discovering files from the current directory.
Example: -files=\"src/a.ts,src/b.js\"
-git-branch
Limit the report to lines changed on the current local Git
branch. Cannot be combined with -files.
-max-cognitive-complexity=<value>
Maximum allowed cognitive complexity for --report-complexity.
Defaults to 15.
-max-cyclomatic-complexity=<value>
Maximum allowed cyclomatic complexity for --report-complexity.
Defaults to 10.
-verbose
Include analyzed files and timings in report output, plus duplicate block details.
In -git-branch mode, analyzed files include changed line ranges.
COMPLEXITY REPORT PURPOSE:
The complexity report helps you find functions whose cognitive or cyclomatic
complexity exceeds the configured limits. It lists each function with its
location and both computed complexity values.
DUPLICATE REPORT PURPOSE:
The duplicate report helps you find repeated code that may be worth
refactoring, reviewing, or consolidating. It lists each duplicated block with
the files and line ranges where it appears, making it easier to compare the
repeated code and decide whether it should stay duplicated.
EXAMPLES:
codem8 --report-complexity
codem8 --report-complexity -file-extension=rs -max-cognitive-complexity=12
codem8 --report-complexity -git-branch
codem8 --report-duplicate
codem8 --report-duplicate -file-extension=ts,tsx,js,jsx
codem8 --report-duplicate -file-extension=ts,js -files=\"src/a.ts,src/b.js\"
codem8 --report-duplicate -git-branch
";
#[must_use]
pub fn help_text() -> String {
let mut output = String::new();
output.push_str("CodeM8 - deterministic source code analysis reports.\n");
output.push('\n');
output.push_str(HELP_TEXT_BODY);
output
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn exposes_detailed_help_text() {
let help = help_text();
assert_help_includes_expected_sections(&help);
assert_help_includes_single_dash_options(&help);
assert_help_excludes_double_dash_options(&help);
assert_help_mentions_complexity_before_duplicate(&help);
}
fn assert_help_includes_expected_sections(help: &str) {
assert!(help.contains("USAGE:"));
assert!(help.contains("codem8 -h"));
assert!(help.contains("codem8 --version"));
assert!(help.contains(" -h"));
assert!(help.contains(" --version"));
assert!(help.contains("--report-duplicate"));
assert!(help.contains("--report-complexity"));
assert!(help.contains("helps you find repeated code"));
assert!(help.contains("helps you find functions"));
assert!(!help.contains("Duplicate weight"));
}
fn assert_help_includes_single_dash_options(help: &str) {
assert!(help.contains("-verbose"));
assert!(help.contains("-file-extension=<extensions>"));
assert!(help.contains("-files=<paths>"));
assert!(help.contains("-git-branch"));
assert!(help.contains("-max-cognitive-complexity=<value>"));
assert!(help.contains("-max-cyclomatic-complexity=<value>"));
}
fn assert_help_excludes_double_dash_options(help: &str) {
assert!(!help.contains("--verbose"));
assert!(!help.contains("--file-extension=<extensions>"));
assert!(!help.contains("--files=<paths>"));
assert!(!help.contains("--git-branch"));
assert!(!help.contains("--max-cognitive-complexity=<value>"));
assert!(!help.contains("--max-cyclomatic-complexity=<value>"));
}
fn assert_help_mentions_complexity_before_duplicate(help: &str) {
assert!(
help.find("codem8 --report-complexity [OPTIONS]")
.expect("complexity usage exists")
< help
.find("codem8 --report-duplicate [OPTIONS]")
.expect("duplicate usage exists")
);
assert!(
help.find("COMPLEXITY REPORT PURPOSE:")
.expect("complexity purpose exists")
< help
.find("DUPLICATE REPORT PURPOSE:")
.expect("duplicate purpose exists")
);
assert!(
help.find("codem8 --report-complexity\n")
.expect("complexity example exists")
< help
.find("codem8 --report-duplicate\n")
.expect("duplicate example exists")
);
}
#[test]
fn help_text_header_excludes_version() {
assert!(help_text().starts_with("CodeM8 - "));
assert!(!help_text().starts_with("CodeM8 0."));
}
}