项目原始demo,不改动
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.
 
 
 
 

59 Zeilen
1.2 KiB

  1. // Borrowed from here:
  2. // https://github.com/colonyamerican/eslint-plugin-cah/issues/3
  3. 'use strict'
  4. const getDocsUrl = require('./lib/get-docs-url')
  5. function isDeclared(scope, ref) {
  6. return scope.variables.some(function(variable) {
  7. if (variable.name !== ref.identifier.name) {
  8. return false
  9. }
  10. if (!variable.defs || !variable.defs.length) {
  11. return false
  12. }
  13. return true
  14. })
  15. }
  16. module.exports = {
  17. meta: {
  18. docs: {
  19. url: getDocsUrl('no-native')
  20. }
  21. },
  22. create: function(context) {
  23. const MESSAGE = '"{{name}}" is not defined.'
  24. /**
  25. * Checks for and reports reassigned constants
  26. *
  27. * @param {Scope} scope - an escope Scope object
  28. * @returns {void}
  29. * @private
  30. */
  31. return {
  32. 'Program:exit': function() {
  33. const scope = context.getScope()
  34. scope.implicit.left.forEach(function(ref) {
  35. if (ref.identifier.name !== 'Promise') {
  36. return
  37. }
  38. if (!isDeclared(scope, ref)) {
  39. context.report({
  40. node: ref.identifier,
  41. message: MESSAGE,
  42. data: { name: ref.identifier.name }
  43. })
  44. }
  45. })
  46. }
  47. }
  48. }
  49. }