-
Notifications
You must be signed in to change notification settings - Fork 1.7k
JS: Promote js/suspicious-method-name-declaration
to the Code Quality suite.
#19741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS: Promote js/suspicious-method-name-declaration
to the Code Quality suite.
#19741
Conversation
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
04ac711
to
7b91a57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit otherwise LGTM
javascript/ql/src/Declarations/SuspiciousMethodNameDeclaration.qhelp
Outdated
Show resolved
Hide resolved
….qhelp Co-authored-by: Asger F <asgerf@github.com>
This pull request adds the query
js/template-syntax-in-string-literal
to the Code Quality suite.The
autofix
functionality 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