param-names.js 782 B

123456789101112131415161718192021222324252627282930313233343536
  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' ||
  20. (params[1] && params[1].name !== 'reject')
  21. ) {
  22. context.report({
  23. node,
  24. message:
  25. 'Promise constructor parameters must be named resolve, reject',
  26. })
  27. }
  28. }
  29. },
  30. }
  31. },
  32. }