-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(driver): Support suppression annotations (#203)
Closes #43
- Loading branch information
Showing
10 changed files
with
141 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,61 @@ | ||
/** | ||
* Represents annotations in the comments processed by Misti. | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
import { srcInfoToString } from "./tact"; | ||
import { SrcInfo } from "@tact-lang/compiler/dist/grammar/grammar"; | ||
|
||
/** | ||
* Represents a Misti annotation. | ||
*/ | ||
export type MistiAnnotation = { | ||
kind: "suppress"; | ||
detectors: string[]; | ||
}; | ||
|
||
/** | ||
* The marker used to identify Misti suppress annotations. | ||
* Syntax: // @misti:suppress Detector1,Detector2 | ||
*/ | ||
export const SUPPRESS_MARKER = "@misti:suppress"; | ||
|
||
/** | ||
* Retrieves the Misti annotation from the current source location if present. | ||
* | ||
* These can be single or multi-line comments on the current or previous line | ||
* annotated with SUPPRESS_MARKER. | ||
*/ | ||
export function getMistiAnnotation(loc: SrcInfo): MistiAnnotation | null { | ||
const lines = srcInfoToString(loc).split("\n"); | ||
const currentLineIndex = lines.findIndex((line) => | ||
line.trim().startsWith(">"), | ||
); | ||
if (currentLineIndex <= 0) return null; | ||
const previousLine = lines[currentLineIndex - 1]; | ||
const previousLineCode = getCodeFromLine(previousLine); | ||
const annotationPattern = new RegExp( | ||
`^\\s*(\\/\\/|\\/\\*)\\s*${SUPPRESS_MARKER}\\s+([\\w,]+)\\s*`, | ||
); | ||
|
||
const match = previousLineCode.match(annotationPattern); | ||
if (match) { | ||
const detectors = match[2].split(",").map((detector) => detector.trim()); | ||
return { | ||
kind: "suppress", | ||
detectors, | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function getCodeFromLine(line: string): string { | ||
const pipeIndex = line.indexOf("|"); | ||
if (pipeIndex !== -1) { | ||
return line.substring(pipeIndex + 1).trim(); | ||
} else { | ||
return line.trim(); | ||
} | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -1 +1,5 @@ | ||
asm(-> 1 0) extends mutates fun loadRefEx(self: Slice): Cell { LDREF } | ||
|
||
// OK: Suppressed | ||
// @misti:suppress AsmIsUsed | ||
asm(-> 1 0) extends mutates fun loadRefExSuppressed(self: Slice): Cell { LDREF } |
This file contains 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
[MEDIUM] FieldDoubleInit: Field a is initialized twice | ||
test/detectors/FieldDoubleInit.tact:4:9: | ||
3 | init(x: Int) { | ||
> 4 | self.a = x; // Should be highlighted | ||
[MEDIUM] FieldDoubleInit: Field a1 is initialized twice | ||
test/detectors/FieldDoubleInit.tact:5:9: | ||
4 | init(x: Int) { | ||
> 5 | self.a1 = x; // Should be highlighted | ||
^ | ||
5 | } | ||
6 | // @misti:suppress FieldDoubleInit | ||
Help: Consider initializing the field only in its declaration or in the `init` function | ||
See: https://nowarp.io/tools/misti/docs/detectors/FieldDoubleInit |
This file contains 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