diff --git a/ql/test/queries/style/ImplicitThis/Bad.qll b/ql/test/queries/style/ImplicitThis/Bad.qll new file mode 100644 index 00000000000..97b51284acc --- /dev/null +++ b/ql/test/queries/style/ImplicitThis/Bad.qll @@ -0,0 +1,11 @@ +import ql + +class Foo extends string { + Foo() { this = "hello" } + + string getBar() { result = "bar" } + + string getBarWithThis() { result = this.getBar() } + + string getBarWithoutThis() { result = getBar() } +} diff --git a/ql/test/queries/style/ImplicitThis/Good.qll b/ql/test/queries/style/ImplicitThis/Good.qll new file mode 100644 index 00000000000..95b5f17f1de --- /dev/null +++ b/ql/test/queries/style/ImplicitThis/Good.qll @@ -0,0 +1,16 @@ +import ql + +class Foo extends string { + Foo() { this = "hello" } + + string getBar() { result = "bar" } + + string getBarWithThis() { result = this.getBar() } + + /* Okay because not a member predicate. */ + string getBaz() { result = Baz::baz() } +} + +module Baz { + string baz() { result = "baz" } +} diff --git a/ql/test/queries/style/ImplicitThis/ImplicitThis.expected b/ql/test/queries/style/ImplicitThis/ImplicitThis.expected new file mode 100644 index 00000000000..fa3adbaf992 --- /dev/null +++ b/ql/test/queries/style/ImplicitThis/ImplicitThis.expected @@ -0,0 +1 @@ +| Bad.qll:10:41:10:48 | PredicateCall | Use of implicit `this`. | diff --git a/ql/test/queries/style/ImplicitThis/ImplicitThis.qlref b/ql/test/queries/style/ImplicitThis/ImplicitThis.qlref new file mode 100644 index 00000000000..0bdcd3b4b5b --- /dev/null +++ b/ql/test/queries/style/ImplicitThis/ImplicitThis.qlref @@ -0,0 +1 @@ +queries/style/ImplicitThis.ql diff --git a/ql/test/queries/style/ImplicitThis/Okay.qll b/ql/test/queries/style/ImplicitThis/Okay.qll new file mode 100644 index 00000000000..37c9dd4ab2a --- /dev/null +++ b/ql/test/queries/style/ImplicitThis/Okay.qll @@ -0,0 +1,13 @@ +import ql + +class Foo extends string { + Foo() { this = "hello" } + + string getBar() { result = "bar" } + + /* Okay, because we don't write `this.some_method` anywhere */ + string getBarWithoutThis() { result = getBar() } + + /* Okay, because this is the only way to cast `this`. */ + string useThisWithInlineCast() { result = this.(string).toUpperCase() } +}