Rust: cyclomatic and cognitive values that differ from McCabe and the Cognitive Complexity whitepaper
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Start by reading how rust-code-analysis-cli 0.0.25 computes cyclomatic and cognitive metrics for Rust control flow, then reproduce the four self-contained snippets from the issue. Compare each result with the cited McCabe and Cognitive Complexity rules to locate the relevant analysis and tests. Done means all reported metric values match the stated expectations.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version: rust-code-analysis-cli 0.0.25 (crates.io), and master at 37e5d83c056c. Same results on both.
Four small cases (five departures), each a self-contained file. The expected values come from McCabe (1976) for cyclomatic and from G. Ann Campbell's Cognitive Complexity whitepaper (SonarSource, v1.7) for cognitive.
1. match counts every arm, including the last (the whitepaper's getWords example, written with match):
fn get_words(number: u32) -> &'static str {
match number {
1 => "one",
2 => "a couple",
3 => "a few",
_ => "lots",
}
}
Cyclomatic: expected 4 (a four-way branch is three decisions; the whitepaper gives 4 for its switch version), actual 5. Cognitive 1 is as expected.
2. A bare loop counts as a decision, and is not counted for cognitive:
fn f(mut n: u32) -> u32 {
loop {
n += 1;
if n > 10 {
break;
}
}
n
}
Cyclomatic: expected 2 (loop has no predicate; the if is the only decision), actual 3. Cognitive: expected 3 (the whitepaper adds +1 for the loop and +2 for the if nested in it), actual 1.
3. let ... else is not a decision:
fn first(v: &[i32]) -> i32 {
let Some(x) = v.first() else { return 0; };
*x
}
Cyclomatic: expected 2 (the pattern either matches, or the diverging else runs), actual 1.
4. The whitepaper's mixed-operator example:
fn mixed(a: bool, b: bool, c: bool, d: bool, e: bool, g: bool) -> i32 {
if a && b && c || d || e && g {
return 1;
}
0
}
Cognitive: expected 4 (the whitepaper's own worked example: +1 for the if, +1 for each of the three operator sequences), actual 5. Cyclomatic 7 is as expected.
I'm happy to split this into separate issues if that's easier to track.
This report was drafted with AI assistance; I ran the repro and checked the numbers myself.
- Ngôn ngữ chính
- Rust
- Star
- 469
- Fork
- 74
- Merge trung bình
- 17 giờ 16 phút
- Pull request đã merge (30 ngày)
- 10
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của mozilla/rust-code-analysis
-
mozcpp: refresh the list of Mozilla annotation macrosCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
mozilla/rust-code-analysis#1267 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mozcpp: parse a string literal followed by a PRI*/SCN* format macroCó thể đã có người làm @marco-c đã nhận 2 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 15/100
mozilla/rust-code-analysis#1266 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Grammar check tasks compare unrelated files and skip most of the othersCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
mozilla/rust-code-analysis#1261 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
mozilla/rust-code-analysis#1250 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
mozilla/rust-code-analysis#1248 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của mozilla/rust-code-analysis
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
ubugeeei-prod/vize#13586 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
storytold/photocraft#16565 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
flaky needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
bherbruck/solvecraft#21315 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
undergroundrap/hatchling#624 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
node:url: url.parse and url.resolve report name parse/resolve instead of Node's urlParse/urlResolveĐang mởarea:stdlib effort:S impact:low parity type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày