@@ -26,20 +26,17 @@ predicate isSuspisousMethodName(string name, ClassOrInterface container) {
2626 name = "new" and container instanceof ClassDefinition
2727}
2828
29- from MethodDeclaration member , ClassOrInterface container , string suffixMsg
29+ from MethodDeclaration member , ClassOrInterface container , string name , string msg
3030where
3131 container .getLocation ( ) .getFile ( ) .getFileType ( ) .isTypeScript ( ) and
32- container .getAMember ( ) = member and
33- isSuspisousMethodName ( member . getName ( ) , container ) and
32+ container .getMember ( name ) = member and
33+ isSuspisousMethodName ( name , container ) and
3434
3535 // Assume that a "new" method is intentional if the class has an explicit constructor.
3636 not (
37- member . getName ( ) = "new" and
37+ name = "new" and
3838 container instanceof ClassDefinition and
39- exists ( ConstructorDeclaration constructor |
40- container .getAMember ( ) = constructor and
41- not constructor .isSynthetic ( )
42- )
39+ not container .getMember ( "constructor" ) .( ConstructorDeclaration ) .isSynthetic ( )
4340 ) and
4441
4542 // Explicitly declared static methods are fine.
@@ -53,18 +50,18 @@ where
5350
5451 // The developer was not confused about "function" when there are other methods in the interface.
5552 not (
56- member . getName ( ) = "function" and
57- exists ( MethodDeclaration other | other = container .getMethod ( _ ) |
58- other . getName ( ) != "function" and
53+ name = "function" and
54+ exists ( MethodDeclaration other | other = container .getAMethod ( ) |
55+ name != "function" and
5956 not other .( ConstructorDeclaration ) .isSynthetic ( )
6057 )
6158 ) and
6259
6360 (
64- member . getName ( ) = "constructor" and suffixMsg = "Did you mean to write a class instead of an interface? "
61+ name = "constructor" and msg = "The member name 'constructor' does not declare a constructor in interface declarations, but it does in class declarations. "
6562 or
66- member . getName ( ) = "new" and suffixMsg = "Did you mean \" constructor\"? "
63+ name = "new" and msg = "The member name 'new' does not declare a constructor, but 'constructor' does in class declarations. "
6764 or
68- member . getName ( ) = "function" and suffixMsg = "Did you mean to omit \" function\"? "
65+ name = "function" and msg = "The member name 'function' does not declare a function, it declares a method named 'function'. "
6966 )
70- select member , "Declares a suspiciously named method \"" + member . getName ( ) + "\". " + suffixMsg
67+ select member , msg
0 commit comments