Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

53 строки
1.4 KiB

  1. /**
  2. * @fileoverview Prevent usage of isMounted
  3. * @author Joe Lencioni
  4. */
  5. 'use strict';
  6. const docsUrl = require('../util/docsUrl');
  7. // ------------------------------------------------------------------------------
  8. // Rule Definition
  9. // ------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. docs: {
  13. description: 'Prevent usage of isMounted',
  14. category: 'Best Practices',
  15. recommended: true,
  16. url: docsUrl('no-is-mounted')
  17. },
  18. schema: []
  19. },
  20. create: function(context) {
  21. // --------------------------------------------------------------------------
  22. // Public
  23. // --------------------------------------------------------------------------
  24. return {
  25. CallExpression: function(node) {
  26. const callee = node.callee;
  27. if (callee.type !== 'MemberExpression') {
  28. return;
  29. }
  30. if (callee.object.type !== 'ThisExpression' || callee.property.name !== 'isMounted') {
  31. return;
  32. }
  33. const ancestors = context.getAncestors(callee);
  34. for (let i = 0, j = ancestors.length; i < j; i++) {
  35. if (ancestors[i].type === 'Property' || ancestors[i].type === 'MethodDefinition') {
  36. context.report({
  37. node: callee,
  38. message: 'Do not use isMounted'
  39. });
  40. break;
  41. }
  42. }
  43. }
  44. };
  45. }
  46. };