jsx-uses-react.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @fileoverview Prevent React to be marked as unused
  3. * @author Glen Mailer
  4. */
  5. 'use strict';
  6. const pragmaUtil = require('../util/pragma');
  7. const docsUrl = require('../util/docsUrl');
  8. // ------------------------------------------------------------------------------
  9. // Rule Definition
  10. // ------------------------------------------------------------------------------
  11. module.exports = {
  12. meta: {
  13. docs: {
  14. description: 'Prevent React to be marked as unused',
  15. category: 'Best Practices',
  16. recommended: true,
  17. url: docsUrl('jsx-uses-react')
  18. },
  19. schema: []
  20. },
  21. create(context) {
  22. const pragma = pragmaUtil.getFromContext(context);
  23. const fragment = pragmaUtil.getFragmentFromContext(context);
  24. function handleOpeningElement() {
  25. context.markVariableAsUsed(pragma);
  26. }
  27. // --------------------------------------------------------------------------
  28. // Public
  29. // --------------------------------------------------------------------------
  30. return {
  31. JSXOpeningElement: handleOpeningElement,
  32. JSXOpeningFragment: handleOpeningElement,
  33. JSXFragment() {
  34. context.markVariableAsUsed(fragment);
  35. }
  36. };
  37. }
  38. };