/*** @name Suspicious method name declaration* @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* @precision high* @tags correctness* typescript* methods*/import javascript/*** Holds if the method name on the given container is likely to be a mistake.*/predicate isSuspiciousMethodName(string name, ClassOrInterface container) {name = "function" and exists(container) // suspicious in any containeror// "constructor" is only suspicious outside a class.name = "constructor" and not container instanceof ClassDefinitionor// "new" is only suspicious inside a class.name = "new" and container instanceof ClassDefinition}from MethodDeclaration member, ClassOrInterface container, string name, string msgwherecontainer.getLocation().getFile().getFileType().isTypeScript() andcontainer.getMember(name) = member andisSuspiciousMethodName(name, container) and// Cases to ignore.not (// Assume that a "new" method is intentional if the class has an explicit constructor.name = "new" andcontainer instanceof ClassDefinition andexists(ConstructorDeclaration constructor |container.getMember("constructor") = constructor andnot constructor.isSynthetic())or// Explicitly declared static methods are fine.container instanceof ClassDefinition andmember.isStatic()or// 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" andexists(MethodDeclaration other | other = container.getAMethod() |other.getName() != "function" andnot other.(ConstructorDeclaration).isSynthetic())) and(name = "constructor" andmsg ="The member name 'constructor' does not declare a constructor in interfaces, but it does in classes."orname = "new" andmsg ="The member name 'new' does not declare a constructor, but 'constructor' does in class declarations."orname = "function" andmsg ="The member name 'function' does not declare a function, it declares a method named 'function'.")select member, msg
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。