mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
JS: Autoformat everything
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @name Suspicious method name declaration
|
||||
* @description A method declaration with a name that is a special keyword in another
|
||||
* context is suspicious.
|
||||
* @description A method declaration with a name that is a special keyword in another
|
||||
* context is suspicious.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @id js/suspicious-method-name-declaration
|
||||
@@ -19,7 +19,7 @@ import javascript
|
||||
predicate isSuspiciousMethodName(string name, ClassOrInterface container) {
|
||||
name = "function"
|
||||
or
|
||||
// "constructor" is only suspicious outside a class.
|
||||
// "constructor" is only suspicious outside a class.
|
||||
name = "constructor" and not container instanceof ClassDefinition
|
||||
or
|
||||
// "new" is only suspicious inside a class.
|
||||
@@ -31,7 +31,6 @@ where
|
||||
container.getLocation().getFile().getFileType().isTypeScript() and
|
||||
container.getMember(name) = member and
|
||||
isSuspiciousMethodName(name, container) and
|
||||
|
||||
// Cases to ignore.
|
||||
not (
|
||||
// Assume that a "new" method is intentional if the class has an explicit constructor.
|
||||
@@ -39,31 +38,34 @@ where
|
||||
container instanceof ClassDefinition and
|
||||
exists(ConstructorDeclaration constructor |
|
||||
container.getMember("constructor") = constructor and
|
||||
not constructor.isSynthetic()
|
||||
)
|
||||
not constructor.isSynthetic()
|
||||
)
|
||||
or
|
||||
// Explicitly declared static methods are fine.
|
||||
container instanceof ClassDefinition and
|
||||
member.isStatic()
|
||||
or
|
||||
// Only looking for declared methods. Methods with a body are OK.
|
||||
// Only looking for declared methods. Methods with a body are OK.
|
||||
exists(member.getBody().getBody())
|
||||
or
|
||||
// The developer was not confused about "function" when there are other methods in the interface.
|
||||
name = "function" and
|
||||
name = "function" and
|
||||
exists(MethodDeclaration other | other = container.getAMethod() |
|
||||
other.getName() != "function" and
|
||||
not other.(ConstructorDeclaration).isSynthetic()
|
||||
)
|
||||
)
|
||||
|
||||
and
|
||||
|
||||
) and
|
||||
(
|
||||
name = "constructor" and msg = "The member name 'constructor' does not declare a constructor in interfaces, but it does in classes."
|
||||
name = "constructor" and
|
||||
msg =
|
||||
"The member name 'constructor' does not declare a constructor in interfaces, but it does in classes."
|
||||
or
|
||||
name = "new" and msg = "The member name 'new' does not declare a constructor, but 'constructor' does in class declarations."
|
||||
name = "new" and
|
||||
msg =
|
||||
"The member name 'new' does not declare a constructor, but 'constructor' does in class declarations."
|
||||
or
|
||||
name = "function" and msg = "The member name 'function' does not declare a function, it declares a method named 'function'."
|
||||
name = "function" and
|
||||
msg =
|
||||
"The member name 'function' does not declare a function, it declares a method named 'function'."
|
||||
)
|
||||
select member, msg
|
||||
|
||||
Reference in New Issue
Block a user