Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)
還沒有人認領這個 Issue。
評估
研究方向
從 python/ql/src/AlertSuppression.ql 中提議的模式開始,然後閱讀 shared/util/codeql/util/suppression/AlertSuppression.qll 以及 Rust Comment.qll 和 AstNode.qll 檔案。新增 rust/ql/src/AlertSuppression.ql,並確認 // codeql[...] 和 // lgtm[...] 註解能夠產生 Rust 警示抑制,而不變更 rust/ql/src/qlpack.yml。
由索引模型根據 Issue 內容生成。
描述
Description of the issue
Rust is missing an AlertSuppression.ql query, which means // codeql[...] and // lgtm[...] inline suppression comments have no effect on Rust code scanning alerts. Every other supported language (C++, C#, Go, Java, JavaScript, Python, Ruby, Swift) has this query.
All the building blocks already exist in the Rust CodeQL library:
- Shared suppression module:
shared/util/codeql/util/suppression/AlertSuppression.qll— requiresAstNode(withhasLocationInfo) andSingleLineComment(withhasLocationInfo,getText,toString) - Rust
Commentclass:rust/ql/lib/codeql/rust/elements/Comment.qll— already hasgetText()(raw text including//),getCommentText()(stripped),hasLocationInfo(inherited fromAstNode/Token), andtoString - Rust
AstNode:rust/ql/lib/codeql/rust/elements/AstNode.qll
Proposed implementation
A new file at rust/ql/src/AlertSuppression.ql, following the same pattern as python/ql/src/AlertSuppression.ql:
/**
* @name Alert suppression
* @description Generates information about alert suppressions.
* @kind alert-suppression
* @id rust/alert-suppression
*/
private import codeql.util.suppression.AlertSuppression as AS
private import codeql.rust.elements.Comment as C
private import codeql.rust.elements.AstNode as A
class AstNode instanceof A::AstNode {
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
super.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
string toString() { result = super.toString() }
}
class SingleLineComment instanceof C::Comment {
SingleLineComment() {
// Only match single-line comments (// ...), not block comments (/* ... */)
super.getText().matches("//%")
}
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
super.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
string getText() { result = super.getText() }
string toString() { result = super.toString() }
}
import AS::Make<AstNode, SingleLineComment>
The qlpack.yml at rust/ql/src/qlpack.yml already depends on codeql/util, so no dependency changes are needed.
Motivation
Without this, there is no way to suppress false positives inline for Rust. The only workaround is dismissing alerts via the GitHub API or UI, which doesn't persist reliably across code changes.
- 主要語言
- CodeQL
- 星號
- 10.1k
- 分支
- 2.1k
- 平均合併
- 2 天 11 小時
- 30 天內合併 PR
- 129
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/codeql 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 84/100
-
難度 2/5 1-3 小時 新手友好度 82/100
-
false-positive
難度 2/5 1-3 小時 新手友好度 70/100
-
false-positive
難度 3/5 1-2 天 新手友好度 68/100
-
難度 4/5 3-5 天 新手友好度 55/100
相似的 Issue
-
documentation help wanted
難度 2/5 1-3 小時 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 76/100
AXERA-TECH/ax-llm#75 ·
-
bug
難度 2/5 1-3 小時 新手友好度 68/100
gitbutlerapp/gitbutler#15998 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 78/100
sympozium-ai/sympozium#627 ·
-
clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:security impact:ux-friction issue-rating: 🦞 diamond lobster P2
難度 2/5 1-3 小時 新手友好度 84/100