no-new-statics.js 899 B

12345678910111213141516171819202122232425262728293031323334353637
  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. type: 'problem',
  7. docs: {
  8. url: getDocsUrl('no-new-statics'),
  9. },
  10. fixable: 'code',
  11. },
  12. create(context) {
  13. return {
  14. NewExpression(node) {
  15. if (
  16. node.callee.type === 'MemberExpression' &&
  17. node.callee.object.name === 'Promise' &&
  18. PROMISE_STATICS[node.callee.property.name]
  19. ) {
  20. context.report({
  21. node,
  22. message: "Avoid calling 'new' on 'Promise.{{ name }}()'",
  23. data: { name: node.callee.property.name },
  24. fix(fixer) {
  25. return fixer.replaceTextRange(
  26. [node.range[0], node.range[0] + 'new '.length],
  27. ''
  28. )
  29. },
  30. })
  31. }
  32. },
  33. }
  34. },
  35. }