mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
C#: Autoformat QL queries
This commit is contained in:
@@ -7,17 +7,22 @@
|
||||
* @id cs/console-output
|
||||
* @tags maintainability
|
||||
*/
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.Util
|
||||
|
||||
predicate isConsoleOutRedefinedSomewhere() {
|
||||
exists(MethodCall mc | mc.getTarget().hasName("SetOut") and
|
||||
mc.getTarget().getDeclaringType().hasQualifiedName("System.Console"))
|
||||
exists(MethodCall mc |
|
||||
mc.getTarget().hasName("SetOut") and
|
||||
mc.getTarget().getDeclaringType().hasQualifiedName("System.Console")
|
||||
)
|
||||
}
|
||||
|
||||
predicate isConsoleErrorRedefinedSomewhere() {
|
||||
exists(MethodCall mc | mc.getTarget().hasName("SetError") and
|
||||
mc.getTarget().getDeclaringType().hasQualifiedName("System.Console"))
|
||||
exists(MethodCall mc |
|
||||
mc.getTarget().hasName("SetError") and
|
||||
mc.getTarget().getDeclaringType().hasQualifiedName("System.Console")
|
||||
)
|
||||
}
|
||||
|
||||
predicate isCallToConsoleWrite(MethodCall mc) {
|
||||
@@ -36,8 +41,13 @@ predicate isAccessToConsoleError(PropertyAccess pa) {
|
||||
}
|
||||
|
||||
from Expr e
|
||||
where (isCallToConsoleWrite(e) and not isConsoleOutRedefinedSomewhere()
|
||||
or isAccessToConsoleOut(e) and not isConsoleOutRedefinedSomewhere()
|
||||
or isAccessToConsoleError(e) and not isConsoleErrorRedefinedSomewhere())
|
||||
and not e.getEnclosingCallable() instanceof MainMethod
|
||||
where
|
||||
(
|
||||
isCallToConsoleWrite(e) and not isConsoleOutRedefinedSomewhere()
|
||||
or
|
||||
isAccessToConsoleOut(e) and not isConsoleOutRedefinedSomewhere()
|
||||
or
|
||||
isAccessToConsoleError(e) and not isConsoleErrorRedefinedSomewhere()
|
||||
) and
|
||||
not e.getEnclosingCallable() instanceof MainMethod
|
||||
select e, "Poor logging: use of system output stream."
|
||||
|
||||
Reference in New Issue
Block a user