Rust: cyclomatic and cognitive values that differ from McCabe and the Cognitive Complexity whitepaper
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Rust
- スター
- 469
- フォーク
- 74
- 平均マージ
- 17時間 16分
- マージ済み PR(30日)
- 10
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
mozilla/rust-code-analysis のほかの issue
-
mozcpp: refresh the list of Mozilla annotation macros対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
mozilla/rust-code-analysis#1267 ·
メンテナーはふだん 1 日以内に返信
-
mozcpp: parse a string literal followed by a PRI*/SCN* format macro対応中かも @marco-c が 2 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 15/100
mozilla/rust-code-analysis#1266 ·
メンテナーはふだん 1 日以内に返信
-
Grammar check tasks compare unrelated files and skip most of the others再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
mozilla/rust-code-analysis#1261 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
mozilla/rust-code-analysis#1250 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
mozilla/rust-code-analysis#1248 ·
メンテナーはふだん 1 日以内に返信
mozilla/rust-code-analysis の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
ubugeeei-prod/vize#13586 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
storytold/photocraft#16565 ·
メンテナーはふだん 1 日以内に返信
-
flaky needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
bherbruck/solvecraft#21315 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
undergroundrap/hatchling#624 ·
メンテナーはふだん 1 日以内に返信
-
node:url: url.parse and url.resolve report name parse/resolve instead of Node's urlParse/urlResolveオープンarea:stdlib effort:S impact:low parity type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信