JS: Promote js/suspicious-method-name-declaration to the Code Quality suite.#19741
Merged
Napalys merged 5 commits intogithub:mainfrom Jun 12, 2025
Merged
Conversation
Contributor
|
QHelp previews: javascript/ql/src/Declarations/SuspiciousMethodNameDeclaration.qhelpSuspicious method name declarationIn TypeScript, certain keywords have special meanings for member declarations, and misusing them can create confusion:
RecommendationConsider following these guidelines for clearer code:
ExampleThe following examples show common mistakes when using these keywords: This interface mistakenly uses // BAD: Using 'constructor' in an interface creates a method, not a constructor signature
interface Point {
x: number;
y: number;
constructor(x: number, y: number); // This is just a method named "constructor"
}Use // GOOD: Using 'new' for constructor signatures in interfaces
interface Point {
x: number;
y: number;
new(x: number, y: number): Point; // This is a proper constructor signature
}This class mistakenly uses // BAD: Using 'new' in a class creates a method, not a constructor
class Point {
x: number;
y: number;
new(x: number, y: number) {}; // This is just a method named "new"
}Use // GOOD: Using 'constructor' for constructors in classes
class Point {
x: number;
y: number;
constructor(x: number, y: number) { // This is a proper constructor
this.x = x;
this.y = y;
}
}This interface uses // BAD: Using 'function' as a method name is confusing
interface Calculator {
function(a: number, b: number): number; // This is just a method named "function"
}Use a descriptive method name instead: // GOOD: Using descriptive method names instead of 'function'
interface Calculator {
calculate(a: number, b: number): number; // Clear, descriptive method name
}References
|
04ac711 to
7b91a57
Compare
asgerf
reviewed
Jun 12, 2025
javascript/ql/src/Declarations/SuspiciousMethodNameDeclaration.qhelp
Outdated
Show resolved
Hide resolved
….qhelp Co-authored-by: Asger F <asgerf@github.com>
asgerf
approved these changes
Jun 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds the query
js/template-syntax-in-string-literalto the Code Quality suite.The
autofixfunctionality yields good results.The MRVA evaluation returned a small number of findings (15), all of which appear to be true positives. I am inclined to mark this query as
@precision very-high