Skip to content

Commit

Permalink
feat(SuspiciousMessageMode): Dynamic suggestions for integer literals (
Browse files Browse the repository at this point in the history
…#200)

Closes #196

* Fix: Added dynamic suggestions for integer literals in SuspiciousMessageMode

* Update src/detectors/builtin/suspiciousMessageMode.ts

* Update test/detectors/SuspiciousMessageMode.expected.out

* Update test/detectors/SuspiciousMessageMode.expected.out

---------

Co-authored-by: Georgiy Komarov <[email protected]>
  • Loading branch information
Esorat and jubnzv authored Oct 26, 2024
1 parent b30afcb commit 46420ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/detectors/builtin/suspiciousMessageMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ export class SuspiciousMessageMode extends ASTDetector {
flagsUsed.add(flagName);
break;
case "number":
let suggestion: string = `Replace integer literal \`${e.value}\` with symbolic flag constants`;
if (e.value === 64n) {
suggestion = "Replace `64` with `SendRemainingValue`";
} else if (e.value === 128n) {
suggestion = "Replace `128` with `SendRemainingBalance`";
}
warnings.push(
this.makeWarning(
"Integer literals should not be used in mode expression; use symbolic constants instead",
"Integer literals should not be used in mode expression",
e.loc,
{
suggestion:
"Replace integer literals with symbolic flag constants",
suggestion,
},
),
);
Expand Down
8 changes: 4 additions & 4 deletions test/detectors/SuspiciousMessageMode.expected.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ test/detectors/SuspiciousMessageMode.tact:25:19:
Help: Use the '|' operator (bitwise OR) to combine flags
See: https://nowarp.io/tools/misti/docs/detectors/SuspiciousMessageMode

[MEDIUM] SuspiciousMessageMode: Integer literals should not be used in mode expression; use symbolic constants instead
[MEDIUM] SuspiciousMessageMode: Integer literals should not be used in mode expression
test/detectors/SuspiciousMessageMode.tact:34:19:
33 | value: 0,
> 34 | mode: 64 // Bad: Integer literal instead of symbolic constant
^
35 | });
Help: Replace integer literals with symbolic flag constants
Help: Replace `64` with `SendRemainingValue`
See: https://nowarp.io/tools/misti/docs/detectors/SuspiciousMessageMode

[MEDIUM] SuspiciousMessageMode: Mode expression should only contain the '|' operator
Expand All @@ -43,13 +43,13 @@ test/detectors/SuspiciousMessageMode.tact:52:40:
Help: Use each flag at most once in the mode expression
See: https://nowarp.io/tools/misti/docs/detectors/SuspiciousMessageMode

[MEDIUM] SuspiciousMessageMode: Integer literals should not be used in mode expression; use symbolic constants instead
[MEDIUM] SuspiciousMessageMode: Integer literals should not be used in mode expression
test/detectors/SuspiciousMessageMode.tact:52:61:
51 | value: 0,
> 52 | mode: SendRemainingValue + SendRemainingValue + 64 // Bad: Duplicate flags, '+' operator, integer literal
^
53 | });
Help: Replace integer literals with symbolic flag constants
Help: Replace `64` with `SendRemainingValue`
See: https://nowarp.io/tools/misti/docs/detectors/SuspiciousMessageMode

[MEDIUM] SuspiciousMessageMode: Mode expression should only contain the '|' operator
Expand Down

0 comments on commit 46420ac

Please sign in to comment.