Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "codem8"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
license = "MIT"
description = "A deterministic source code analysis CLI for duplicate code reports."
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ Duplicate block weight is calculated as:
Reports are sorted deterministically by descending weight, then by line count,
character count, first location, and normalized block text.

By default, each duplicate block prints the duplicated code before its
locations. Use `-verbose` to also show weight, line count, occurrence count, and
timings for discovery, file processing, and duplicate detection. Character
counts are used internally for scoring and sorting, but are not printed.
By default, each duplicate block prints only the duplicate locations. Use
`-verbose` to also show the duplicated code, weight, line count, occurrence
count, and timings for discovery, file processing, and duplicate detection.
Character counts are used internally for scoring and sorting, but are not
printed.

## Development

Expand Down
7 changes: 0 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,6 @@ mod tests {
"Duplicate blocks found: 1\n",
"\n",
"#1\n",
"Code:\n",
" const value = computeValue(input);\n",
" if (value === undefined) {\n",
" return defaultValue;\n",
" }\n",
"\n",
"Locations:\n",
"- src/a.ts:1-4\n",
"- src/b.ts:1-4\n",
]
Expand Down
26 changes: 14 additions & 12 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ pub fn render_duplicate_report(report: &DuplicateReport, verbose: bool) -> Strin
let _ = writeln!(output, "Lines: {}", block.line_count());
let _ = writeln!(output, "Occurrences: {}", block.occurrences.len());
output.push('\n');
output.push_str("Code:\n");
for line in &block.normalized_lines {
output.push_str(" ");
output.push_str(line);
output.push('\n');
}
output.push_str("\nLocations:\n");
}
output.push_str("Code:\n");
for line in &block.normalized_lines {
output.push_str(" ");
output.push_str(line);
output.push('\n');
}
output.push_str("\nLocations:\n");
for occurrence in &block.occurrences {
let _ = writeln!(
output,
Expand Down Expand Up @@ -169,12 +169,11 @@ mod tests {
assert!(!output.contains("Lines: 1"));
assert!(!output.contains("Occurrences: 2"));
assert!(!output.contains("Characters:"));
assert!(!output.contains("Code:"));
assert!(!output.contains("Locations:"));
assert!(output.contains("- src/a.ts:1-1"));
assert!(output.contains(" return value;"));
assert!(
output.find("Code:").expect("code section exists")
< output.find("Locations:").expect("locations section exists")
);
assert!(!output.contains(" return value;"));
assert!(output.contains("#1\n- src/a.ts:1-1\n- src/b.js:5-5\n"));
}

#[test]
Expand Down Expand Up @@ -219,6 +218,9 @@ mod tests {
assert!(output.contains("Lines: 1"));
assert!(output.contains("Occurrences: 2"));
assert!(!output.contains("Characters:"));
assert!(output.contains("Code:"));
assert!(output.contains("Locations:"));
assert!(output.contains(" return value;"));
}

#[test]
Expand Down
Loading