-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor module #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
85749d4
[refactor] move duplicate report logic under report module
b4prog 90a681f
[refactor] split language registry and classification modules
b4prog 9727d05
[chore] bump CodeM8 minor version to 0.7.0
b4prog a32dd55
[refactor] split CLI parsing and help modules
b4prog ddba2c6
[refactor] move git branch filtering into discovery module
b4prog 5b17e8e
[docs] add tests to agent verification commands
b4prog 5246b3f
[fix] add Rust ampersand duplicate mitigation pattern
b4prog c93cc81
[fix] ignore Rust assert macro openers in duplicate mitigation
b4prog edd89ea
[docs] document short help entrypoint
b4prog be5325b
[fix] canonicalize explicit file display root
b4prog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| use std::fmt::Write as _; | ||
|
|
||
| use super::version::codem8_version_from_cargo_lock; | ||
|
|
||
| const HELP_TEXT_BODY: &str = "\ | ||
| USAGE: | ||
| codem8 help | ||
| codem8 -h | ||
| codem8 --report-duplicate [OPTIONS] | ||
|
|
||
| COMMANDS: | ||
| help | ||
| -h | ||
| Display this detailed documentation. | ||
|
|
||
| REQUIRED REPORT SWITCHES: | ||
| --report-duplicate | ||
| Analyze source files and print a duplicate code report. | ||
|
|
||
| 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 | ||
| Analyze files changed on the current local Git branch compared to the | ||
| origin base branch, including committed, staged, unstaged, and untracked | ||
| files. Cannot be combined with -files. | ||
|
|
||
| -verbose | ||
| Include duplicate block metrics in report output. | ||
|
|
||
| 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-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 version = codem8_version_from_cargo_lock().unwrap_or("unknown"); | ||
| let mut output = String::new(); | ||
| let _ = writeln!( | ||
| output, | ||
| "CodeM8 {version} - deterministic source code analysis reports." | ||
| ); | ||
| output.push('\n'); | ||
| output.push_str(HELP_TEXT_BODY); | ||
| output | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::cli::version::codem8_version_from_cargo_lock; | ||
|
|
||
| #[test] | ||
| fn exposes_detailed_help_text() { | ||
| let help = help_text(); | ||
| assert!(help.contains("USAGE:")); | ||
| assert!(help.contains("codem8 -h")); | ||
| assert!(help.contains(" -h")); | ||
| assert!(help.contains("--report-duplicate")); | ||
| assert!(help.contains("-verbose")); | ||
| assert!(help.contains("-file-extension=<extensions>")); | ||
| assert!(help.contains("-files=<paths>")); | ||
| assert!(help.contains("-git-branch")); | ||
| assert!(!help.contains("--verbose")); | ||
| assert!(!help.contains("--file-extension=<extensions>")); | ||
| assert!(!help.contains("--files=<paths>")); | ||
| assert!(!help.contains("--git-branch")); | ||
| assert!(help.contains("helps you find repeated code")); | ||
| assert!(!help.contains("Duplicate weight")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn help_text_includes_version_from_cargo_lock() { | ||
| let version = codem8_version_from_cargo_lock().expect("codem8 version exists"); | ||
| assert!(help_text().starts_with(&format!("CodeM8 {version} - "))); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.