no-new-statics.js 668 B

1234567891011121314151617181920212223242526272829
  1. 'use strict'
  2. const PROMISE_STATICS = require('./lib/promise-statics')
  3. const getDocsUrl = require('./lib/get-docs-url')
  4. module.exports = {
  5. meta: {
  6. docs: {
  7. url: getDocsUrl('no-new-statics')
  8. }
  9. },
  10. create(context) {
  11. return {
  12. NewExpression(node) {
  13. if (
  14. node.callee.type === 'MemberExpression' &&
  15. node.callee.object.name === 'Promise' &&
  16. PROMISE_STATICS[node.callee.property.name]
  17. ) {
  18. context.report({
  19. node,
  20. message: "Avoid calling 'new' on 'Promise.{{ name }}()'",
  21. data: { name: node.callee.property.name }
  22. })
  23. }
  24. }
  25. }
  26. }
  27. }