-
-
Notifications
You must be signed in to change notification settings - Fork 94
feat(rule): add no-new-statics rule #82
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
Conversation
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.
Some thoughts 🗣
index.js
Outdated
@@ -32,6 +35,7 @@ module.exports = { | |||
'promise/no-promise-in-callback': 'warn', | |||
'promise/no-callback-in-promise': 'warn', | |||
'promise/avoid-new': 'warn', | |||
'promise/no-new-statics': 'warn', |
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.
I added this rule to the recommended configuration as a warning - does this need adjustment?
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.
I'm thinking this should actually be an error. Playing around in a Node REPL:
❯ node
> new Promise.resolve()
TypeError: Promise.resolve is not a constructor
rules/lib/is-promise.js
Outdated
@@ -2,37 +2,35 @@ | |||
* Library: isPromise | |||
* Makes sure that an Expression node is part of a promise. | |||
*/ | |||
var STATIC_METHODS = [ |
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.
I extracted this array into its own module so that I could use it in multiple files.
rules/lib/is-promise.js
Outdated
|
||
'use strict' | ||
|
||
const PROMISE_STATICS = require('./promise-statics') |
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.
Open to a better file/module name than promise-statics
if you have suggestions!
rules/no-new-statics.js
Outdated
) { | ||
context.report({ | ||
node, | ||
message: 'Avoid calling new on a Promise static method' |
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.
This is a generic message right now that helps get the point across (I think). Improvement suggestions welcome.
32ac83a
to
d7ab89e
Compare
7b84d75
to
40796b5
Compare
40796b5
to
ad9c7f8
Compare
Ready to merge if CI passes! |
Resolves #75
Hoping to continue discussion from #75 to solidify this feature.
For now, I've created a new rule named
no-new-statics
, which warns if you call any of the Promise static methods withnew
. I'm open to new naming or including it in another rule, if that would be more appropriate. Feedback appreciated. 😄