项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

43 lines
1006 B

  1. 'use strict'
  2. const getDocsUrl = require('./lib/get-docs-url')
  3. module.exports = {
  4. meta: {
  5. docs: {
  6. url: getDocsUrl('param-names')
  7. },
  8. fixable: 'code'
  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. fix(fixer) {
  27. return [
  28. fixer.replaceText(params[0], 'resolve'),
  29. params[1] && fixer.replaceText(params[1], 'reject')
  30. ].filter(Boolean)
  31. }
  32. })
  33. }
  34. }
  35. }
  36. }
  37. }
  38. }