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.

102 lines
2.6 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _experimentalUtils = require("@typescript-eslint/experimental-utils");
  7. var _utils = require("./utils");
  8. const testCaseNames = new Set([...Object.keys(_utils.TestCaseName), 'it.only', 'it.concurrent.only', 'it.skip', 'it.concurrent.skip', 'test.only', 'test.concurrent.only', 'test.skip', 'test.concurrent.skip', 'fit.concurrent']);
  9. const isTestFunctionExpression = node => node.parent !== undefined && node.parent.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && testCaseNames.has((0, _utils.getNodeName)(node.parent.callee));
  10. const conditionName = {
  11. [_experimentalUtils.AST_NODE_TYPES.ConditionalExpression]: 'conditional',
  12. [_experimentalUtils.AST_NODE_TYPES.SwitchStatement]: 'switch',
  13. [_experimentalUtils.AST_NODE_TYPES.IfStatement]: 'if'
  14. };
  15. var _default = (0, _utils.createRule)({
  16. name: __filename,
  17. meta: {
  18. docs: {
  19. description: 'Disallow conditional logic',
  20. category: 'Best Practices',
  21. recommended: false
  22. },
  23. messages: {
  24. conditionalInTest: 'Test should not contain {{ condition }} statements.'
  25. },
  26. schema: [],
  27. type: 'suggestion'
  28. },
  29. defaultOptions: [],
  30. create(context) {
  31. const stack = [];
  32. function validate(node) {
  33. const lastElementInStack = stack[stack.length - 1];
  34. if (stack.length === 0 || !lastElementInStack) {
  35. return;
  36. }
  37. context.report({
  38. data: {
  39. condition: conditionName[node.type]
  40. },
  41. messageId: 'conditionalInTest',
  42. node
  43. });
  44. }
  45. return {
  46. CallExpression(node) {
  47. if ((0, _utils.isTestCaseCall)(node)) {
  48. stack.push(true);
  49. }
  50. },
  51. FunctionExpression(node) {
  52. stack.push(isTestFunctionExpression(node));
  53. },
  54. FunctionDeclaration(node) {
  55. const declaredVariables = context.getDeclaredVariables(node);
  56. const testCallExpressions = (0, _utils.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
  57. stack.push(testCallExpressions.length > 0);
  58. },
  59. ArrowFunctionExpression(node) {
  60. stack.push(isTestFunctionExpression(node));
  61. },
  62. IfStatement: validate,
  63. SwitchStatement: validate,
  64. ConditionalExpression: validate,
  65. 'CallExpression:exit'() {
  66. stack.pop();
  67. },
  68. 'FunctionExpression:exit'() {
  69. stack.pop();
  70. },
  71. 'FunctionDeclaration:exit'() {
  72. stack.pop();
  73. },
  74. 'ArrowFunctionExpression:exit'() {
  75. stack.pop();
  76. }
  77. };
  78. }
  79. });
  80. exports.default = _default;