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.

118 lines
3.9 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 validTestCaseNames = [_utils.TestCaseName.test, _utils.TestCaseName.it];
  9. const testFunctions = new Set([_utils.DescribeAlias.describe, ...validTestCaseNames]);
  10. const isConcurrentExpression = expression => (0, _utils.isSupportedAccessor)(expression.property, _utils.TestCaseProperty.concurrent) && !!expression.parent && expression.parent.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression;
  11. const matchesTestFunction = object => 'name' in object && typeof object.name === 'string' && (object.name in _utils.TestCaseName || object.name in _utils.DescribeAlias);
  12. const isCallToFocusedTestFunction = object => object.name.startsWith('f') && testFunctions.has(object.name.substring(1));
  13. const isCallToTestOnlyFunction = callee => matchesTestFunction(callee.object) && (0, _utils.isSupportedAccessor)(isConcurrentExpression(callee) ? callee.parent.property : callee.property, 'only');
  14. var _default = (0, _utils.createRule)({
  15. name: __filename,
  16. meta: {
  17. docs: {
  18. category: 'Best Practices',
  19. description: 'Disallow focused tests',
  20. recommended: 'error',
  21. suggestion: true
  22. },
  23. messages: {
  24. focusedTest: 'Unexpected focused test.',
  25. suggestRemoveFocus: 'Remove focus from test.'
  26. },
  27. schema: [],
  28. type: 'suggestion'
  29. },
  30. defaultOptions: [],
  31. create: context => ({
  32. CallExpression(node) {
  33. const callee = node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee;
  34. if (callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
  35. const calleeObject = callee.object;
  36. if (calleeObject.type === _experimentalUtils.AST_NODE_TYPES.Identifier && isCallToFocusedTestFunction(calleeObject)) {
  37. context.report({
  38. messageId: 'focusedTest',
  39. node: calleeObject,
  40. suggest: [{
  41. messageId: 'suggestRemoveFocus',
  42. fix(fixer) {
  43. return fixer.removeRange([calleeObject.range[0], calleeObject.range[0] + 1]);
  44. }
  45. }]
  46. });
  47. return;
  48. }
  49. if (calleeObject.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isCallToTestOnlyFunction(calleeObject)) {
  50. context.report({
  51. messageId: 'focusedTest',
  52. node: isConcurrentExpression(calleeObject) ? callee.property : calleeObject.property,
  53. suggest: [{
  54. messageId: 'suggestRemoveFocus',
  55. fix(fixer) {
  56. if (calleeObject.property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && calleeObject.property.name === 'only') {
  57. return fixer.removeRange([calleeObject.object.range[1], calleeObject.range[1]]);
  58. }
  59. return fixer.removeRange([calleeObject.range[1], callee.range[1]]);
  60. }
  61. }]
  62. });
  63. return;
  64. }
  65. if (isCallToTestOnlyFunction(callee)) {
  66. context.report({
  67. messageId: 'focusedTest',
  68. node: callee.property,
  69. suggest: [{
  70. messageId: 'suggestRemoveFocus',
  71. fix(fixer) {
  72. return fixer.removeRange([calleeObject.range[1], callee.range[1]]);
  73. }
  74. }]
  75. });
  76. return;
  77. }
  78. }
  79. if (callee.type === _experimentalUtils.AST_NODE_TYPES.Identifier && isCallToFocusedTestFunction(callee)) {
  80. context.report({
  81. messageId: 'focusedTest',
  82. node: callee,
  83. suggest: [{
  84. messageId: 'suggestRemoveFocus',
  85. fix(fixer) {
  86. return fixer.removeRange([callee.range[0], callee.range[0] + 1]);
  87. }
  88. }]
  89. });
  90. }
  91. }
  92. })
  93. });
  94. exports.default = _default;