web 3d图形渲染器
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.

77 lines
2.0 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _utils = require("./utils");
  7. var _default = (0, _utils.createRule)({
  8. name: __filename,
  9. meta: {
  10. docs: {
  11. description: 'Prevent calling `expect` conditionally',
  12. category: 'Best Practices',
  13. recommended: 'error'
  14. },
  15. messages: {
  16. conditionalExpect: 'Avoid calling `expect` conditionally`'
  17. },
  18. type: 'problem',
  19. schema: []
  20. },
  21. defaultOptions: [],
  22. create(context) {
  23. let conditionalDepth = 0;
  24. let inTestCase = false;
  25. const increaseConditionalDepth = () => inTestCase && conditionalDepth++;
  26. const decreaseConditionalDepth = () => inTestCase && conditionalDepth--;
  27. return {
  28. FunctionDeclaration(node) {
  29. const declaredVariables = context.getDeclaredVariables(node);
  30. const testCallExpressions = (0, _utils.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
  31. if (testCallExpressions.length > 0) {
  32. inTestCase = true;
  33. }
  34. },
  35. CallExpression(node) {
  36. if ((0, _utils.isTestCaseCall)(node)) {
  37. inTestCase = true;
  38. }
  39. if (inTestCase && (0, _utils.isExpectCall)(node) && conditionalDepth > 0) {
  40. context.report({
  41. messageId: 'conditionalExpect',
  42. node
  43. });
  44. }
  45. },
  46. 'CallExpression:exit'(node) {
  47. if ((0, _utils.isTestCaseCall)(node)) {
  48. inTestCase = false;
  49. }
  50. },
  51. CatchClause: increaseConditionalDepth,
  52. 'CatchClause:exit': decreaseConditionalDepth,
  53. IfStatement: increaseConditionalDepth,
  54. 'IfStatement:exit': decreaseConditionalDepth,
  55. SwitchStatement: increaseConditionalDepth,
  56. 'SwitchStatement:exit': decreaseConditionalDepth,
  57. ConditionalExpression: increaseConditionalDepth,
  58. 'ConditionalExpression:exit': decreaseConditionalDepth,
  59. LogicalExpression: increaseConditionalDepth,
  60. 'LogicalExpression:exit': decreaseConditionalDepth
  61. };
  62. }
  63. });
  64. exports.default = _default;