Skip to content

Commit d1a1ead

Browse files
committed
Ql: Fix some Ql4Ql violations.
1 parent b4d6cb6 commit d1a1ead

File tree

8 files changed

+26
-17
lines changed

8 files changed

+26
-17
lines changed

ql/ql/src/codeql_ql/style/RedundantCastQuery.qll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import ql
22

33
class RedundantInlineCast extends AstNode instanceof InlineCast {
4-
Type t;
5-
4+
// Type t;
65
RedundantInlineCast() {
7-
t = unique( | | super.getType()) and
8-
(
6+
exists(Type t |
7+
t = unique( | | super.getType()) and
8+
// noopt can require explicit casts
9+
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
10+
|
911
// The cast is to the type the base expression already has
1012
t = unique( | | super.getBase().getType())
1113
or
@@ -23,9 +25,7 @@ class RedundantInlineCast extends AstNode instanceof InlineCast {
2325
target = unique( | | call.getTarget()) and
2426
t = unique( | | target.getParameterType(i))
2527
)
26-
) and
27-
// noopt can require explicit casts
28-
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
28+
)
2929
}
3030

3131
TypeExpr getTypeExpr() { result = super.getTypeExpr() }
@@ -49,15 +49,16 @@ private class AnyCast extends AstNode instanceof FullAggregate {
4949
// `foo = any(Bar b)` is effectively a cast to `Bar`.
5050
class RedundantAnyCast extends AstNode instanceof ComparisonFormula {
5151
AnyCast cast;
52-
Expr operand;
5352

5453
RedundantAnyCast() {
5554
super.getOperator() = "=" and
5655
super.getAnOperand() = cast and
57-
super.getAnOperand() = operand and
58-
cast != operand and
59-
unique( | | operand.getType()).getASuperType*() =
60-
unique( | | cast.getTypeExpr().getResolvedType()) and
56+
exists(Expr operand |
57+
super.getAnOperand() = operand and
58+
cast != operand and
59+
unique( | | operand.getType()).getASuperType*() =
60+
unique( | | cast.getTypeExpr().getResolvedType())
61+
) and
6162
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
6263
}
6364

ql/ql/test/queries/performance/VarUnusedInDisjunct/Test.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,6 @@ class HasField extends Big {
165165
or
166166
this.toString().matches("%foo") // <- field only defined here.
167167
}
168+
169+
Big getField() { result = field }
168170
}

ql/ql/test/queries/style/Misspelling/Misspelling.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
| Test.qll:4:7:4:26 | Class PublicallyAccessible | This class name contains the common misspelling 'publically', which should instead be 'publicly'. |
33
| Test.qll:5:3:5:20 | FieldDecl | This field name contains the common misspelling 'occurences', which should instead be 'occurrences'. |
44
| Test.qll:10:13:10:23 | ClassPredicate hasAgrument | This predicate name contains the common misspelling 'agrument', which should instead be 'argument'. |
5-
| Test.qll:13:1:16:3 | QLDoc | This comment contains the non-US spelling 'colour', which should instead be 'color'. |
6-
| Test.qll:17:7:17:17 | Class AnalysedInt | This class name contains the non-US spelling 'analysed', which should instead be 'analyzed'. |
5+
| Test.qll:15:1:18:3 | QLDoc | This comment contains the non-US spelling 'colour', which should instead be 'color'. |
6+
| Test.qll:19:7:19:17 | Class AnalysedInt | This class name contains the non-US spelling 'analysed', which should instead be 'analyzed'. |

ql/ql/test/queries/style/Misspelling/Test.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class PublicallyAccessible extends string {
88

99
// should be argument
1010
predicate hasAgrument() { none() }
11+
12+
int getNum() { result = numOccurences }
1113
}
1214

1315
/**

ql/ql/test/queries/style/UseInstanceofExtension/Foo.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Inst3 extends string {
2222
Range range;
2323

2424
Inst3() { this = range }
25+
26+
Range getRange() { result = range }
2527
}
2628

2729
class Inst4 extends string {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
| Foo.qll:7:7:7:10 | Class Inst | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
22
| Foo.qll:15:7:15:11 | Class Inst2 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
33
| Foo.qll:21:7:21:11 | Class Inst3 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
4-
| Foo.qll:27:7:27:11 | Class Inst4 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
4+
| Foo.qll:29:7:29:11 | Class Inst4 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |

ql/ql/test/queries/style/UseSetLiteral/UseSetLiteral.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
| test.qll:62:7:65:14 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
55
| test.qll:68:7:71:13 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
66
| test.qll:74:7:77:13 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
7-
| test.qll:87:3:90:9 | Disjunction | This formula of 4 predicate calls can be replaced with a single call on a set literal, improving readability. |
8-
| test.qll:128:3:134:3 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
7+
| test.qll:89:3:92:9 | Disjunction | This formula of 4 predicate calls can be replaced with a single call on a set literal, improving readability. |
8+
| test.qll:130:3:136:3 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |

ql/ql/test/queries/style/UseSetLiteral/test.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class MyTest8Class extends int {
8181
predicate is(int x) { x = this }
8282

8383
int get() { result = this }
84+
85+
string getS() { result = s }
8486
}
8587

8688
predicate test9(MyTest8Class c) {

0 commit comments

Comments
 (0)