C#: Autoformat QL queries

This commit is contained in:
Tom Hvitved
2019-01-02 12:59:07 +01:00
parent 4348de3120
commit daa45322b1
277 changed files with 2462 additions and 2301 deletions

View File

@@ -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."