param-names.js 877 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict'
  2. const getDocsUrl = require('./lib/get-docs-url')
  3. module.exports = {
  4. meta: {
  5. type: 'suggestion',
  6. docs: {
  7. url: getDocsUrl('param-names'),
  8. },
  9. },
  10. create(context) {
  11. return {
  12. NewExpression(node) {
  13. if (node.callee.name === 'Promise' && node.arguments.length === 1) {
  14. const params = node.arguments[0].params
  15. if (!params || !params.length) {
  16. return
  17. }
  18. if (
  19. (params[0].name !== 'resolve' && params[0].name !== '_resolve') ||
  20. (params[1] &&
  21. params[1].name !== 'reject' &&
  22. params[1].name !== '_reject')
  23. ) {
  24. context.report({
  25. node,
  26. message:
  27. 'Promise constructor parameters must be named resolve, reject',
  28. })
  29. }
  30. }
  31. },
  32. }
  33. },
  34. }