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
//! `Cyclomatic` implementation for Perl.
#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
#![allow(
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
clippy::cast_sign_loss
)]
use super::*;
use crate::lang_helpers::perl::perl_and_is_operator;
impl Cyclomatic for PerlCode {
fn compute<'a>(
node: &Node<'a>,
_code: &'a [u8],
ancestors: Ancestors<'a, '_>,
stats: &mut Stats,
) {
use Perl as P;
match node.kind_id().into() {
P::IfStatement
| P::UnlessStatement
| P::ElsifClause
| P::WhileStatement
| P::UntilStatement
| P::ForStatement1
| P::ForStatement2
| P::WhenSimpleStatement
| P::IfSimpleStatement
| P::UnlessSimpleStatement
| P::WhileSimpleStatement
| P::UntilSimpleStatement
| P::ForSimpleStatement
| P::AMPAMP
| P::PIPEPIPE
| P::SLASHSLASH
// Compound short-circuit assignments `&&=`, `||=`, `//=`
// are semantically `x = x op y` and each carries one short-
// circuit decision edge, parallel to the JS-family fix in
// #248 (issue #249).
| P::AMPAMPEQ
| P::PIPEPIPEEQ
| P::SLASHSLASHEQ
| P::Or
| P::TernaryExpression => {
stats.cyclomatic += 1.;
stats.cyclomatic_modified += 1.;
}
// FIXME(#1539 upstream): an auto-quoted `and` key lexes as
// the operator token; only one with a left operand is a
// decision.
P::And
if ancestors
.parent(node)
.is_some_and(|parent| perl_and_is_operator(node, &parent)) =>
{
stats.cyclomatic += 1.;
stats.cyclomatic_modified += 1.;
}
_ => {}
}
}
}