mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Ql: Fix some Ql4Ql violations.
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
import ql
|
import ql
|
||||||
|
|
||||||
class RedundantInlineCast extends AstNode instanceof InlineCast {
|
class RedundantInlineCast extends AstNode instanceof InlineCast {
|
||||||
Type t;
|
|
||||||
|
|
||||||
RedundantInlineCast() {
|
RedundantInlineCast() {
|
||||||
t = unique( | | super.getType()) and
|
exists(Type t |
|
||||||
(
|
t = unique( | | super.getType()) and
|
||||||
|
// noopt can require explicit casts
|
||||||
|
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
|
||||||
|
|
|
||||||
// The cast is to the type the base expression already has
|
// The cast is to the type the base expression already has
|
||||||
t = unique( | | super.getBase().getType())
|
t = unique( | | super.getBase().getType())
|
||||||
or
|
or
|
||||||
@@ -23,9 +24,7 @@ class RedundantInlineCast extends AstNode instanceof InlineCast {
|
|||||||
target = unique( | | call.getTarget()) and
|
target = unique( | | call.getTarget()) and
|
||||||
t = unique( | | target.getParameterType(i))
|
t = unique( | | target.getParameterType(i))
|
||||||
)
|
)
|
||||||
) and
|
)
|
||||||
// noopt can require explicit casts
|
|
||||||
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeExpr getTypeExpr() { result = super.getTypeExpr() }
|
TypeExpr getTypeExpr() { result = super.getTypeExpr() }
|
||||||
@@ -49,15 +48,16 @@ private class AnyCast extends AstNode instanceof FullAggregate {
|
|||||||
// `foo = any(Bar b)` is effectively a cast to `Bar`.
|
// `foo = any(Bar b)` is effectively a cast to `Bar`.
|
||||||
class RedundantAnyCast extends AstNode instanceof ComparisonFormula {
|
class RedundantAnyCast extends AstNode instanceof ComparisonFormula {
|
||||||
AnyCast cast;
|
AnyCast cast;
|
||||||
Expr operand;
|
|
||||||
|
|
||||||
RedundantAnyCast() {
|
RedundantAnyCast() {
|
||||||
super.getOperator() = "=" and
|
super.getOperator() = "=" and
|
||||||
super.getAnOperand() = cast and
|
super.getAnOperand() = cast and
|
||||||
super.getAnOperand() = operand and
|
exists(Expr operand |
|
||||||
cast != operand and
|
super.getAnOperand() = operand and
|
||||||
unique( | | operand.getType()).getASuperType*() =
|
cast != operand and
|
||||||
unique( | | cast.getTypeExpr().getResolvedType()) and
|
unique( | | operand.getType()).getASuperType*() =
|
||||||
|
unique( | | cast.getTypeExpr().getResolvedType())
|
||||||
|
) and
|
||||||
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
|
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -165,4 +165,6 @@ class HasField extends Big {
|
|||||||
or
|
or
|
||||||
this.toString().matches("%foo") // <- field only defined here.
|
this.toString().matches("%foo") // <- field only defined here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Big getField() { result = field }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
| Test.qll:4:7:4:26 | Class PublicallyAccessible | This class name contains the common misspelling 'publically', which should instead be 'publicly'. |
|
| Test.qll:4:7:4:26 | Class PublicallyAccessible | This class name contains the common misspelling 'publically', which should instead be 'publicly'. |
|
||||||
| Test.qll:5:3:5:20 | FieldDecl | This field name contains the common misspelling 'occurences', which should instead be 'occurrences'. |
|
| Test.qll:5:3:5:20 | FieldDecl | This field name contains the common misspelling 'occurences', which should instead be 'occurrences'. |
|
||||||
| Test.qll:10:13:10:23 | ClassPredicate hasAgrument | This predicate name contains the common misspelling 'agrument', which should instead be 'argument'. |
|
| Test.qll:10:13:10:23 | ClassPredicate hasAgrument | This predicate name contains the common misspelling 'agrument', which should instead be 'argument'. |
|
||||||
| Test.qll:13:1:16:3 | QLDoc | This comment contains the non-US spelling 'colour', which should instead be 'color'. |
|
| Test.qll:15:1:18:3 | QLDoc | This comment contains the non-US spelling 'colour', which should instead be 'color'. |
|
||||||
| Test.qll:17:7:17:17 | Class AnalysedInt | This class name contains the non-US spelling 'analysed', which should instead be 'analyzed'. |
|
| Test.qll:19:7:19:17 | Class AnalysedInt | This class name contains the non-US spelling 'analysed', which should instead be 'analyzed'. |
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ class PublicallyAccessible extends string {
|
|||||||
|
|
||||||
// should be argument
|
// should be argument
|
||||||
predicate hasAgrument() { none() }
|
predicate hasAgrument() { none() }
|
||||||
|
|
||||||
|
int getNum() { result = numOccurences }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ class Inst3 extends string {
|
|||||||
Range range;
|
Range range;
|
||||||
|
|
||||||
Inst3() { this = range }
|
Inst3() { this = range }
|
||||||
|
|
||||||
|
Range getRange() { result = range }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Inst4 extends string {
|
class Inst4 extends string {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
| 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 |
|
| 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 |
|
||||||
| 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 |
|
| 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 |
|
||||||
| 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 |
|
| 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 |
|
||||||
| 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 |
|
| 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 |
|
||||||
|
|||||||
@@ -4,5 +4,5 @@
|
|||||||
| 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. |
|
| 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. |
|
||||||
| 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. |
|
| 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. |
|
||||||
| 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. |
|
| 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. |
|
||||||
| 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. |
|
| 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. |
|
||||||
| 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. |
|
| 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. |
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ class MyTest8Class extends int {
|
|||||||
predicate is(int x) { x = this }
|
predicate is(int x) { x = this }
|
||||||
|
|
||||||
int get() { result = this }
|
int get() { result = this }
|
||||||
|
|
||||||
|
string getS() { result = s }
|
||||||
}
|
}
|
||||||
|
|
||||||
predicate test9(MyTest8Class c) {
|
predicate test9(MyTest8Class c) {
|
||||||
|
|||||||
Reference in New Issue
Block a user