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.

105 lines
2.7 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 paramsLocation = params => {
  9. const [first] = params;
  10. const last = params[params.length - 1];
  11. return {
  12. start: first.loc.start,
  13. end: last.loc.end
  14. };
  15. };
  16. var _default = (0, _utils.createRule)({
  17. name: __filename,
  18. meta: {
  19. type: 'problem',
  20. docs: {
  21. category: 'Possible Errors',
  22. description: 'Enforce valid `describe()` callback',
  23. recommended: 'error'
  24. },
  25. messages: {
  26. nameAndCallback: 'Describe requires name and callback arguments',
  27. secondArgumentMustBeFunction: 'Second argument must be function',
  28. noAsyncDescribeCallback: 'No async describe callback',
  29. unexpectedDescribeArgument: 'Unexpected argument(s) in describe callback',
  30. unexpectedReturnInDescribe: 'Unexpected return statement in describe callback'
  31. },
  32. schema: []
  33. },
  34. defaultOptions: [],
  35. create(context) {
  36. return {
  37. CallExpression(node) {
  38. if (!(0, _utils.isDescribeCall)(node) || node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression) {
  39. return;
  40. }
  41. const nodeArguments = (0, _utils.getJestFunctionArguments)(node);
  42. if (nodeArguments.length < 1) {
  43. return context.report({
  44. messageId: 'nameAndCallback',
  45. loc: node.loc
  46. });
  47. }
  48. const [, callback] = nodeArguments;
  49. if (!callback) {
  50. context.report({
  51. messageId: 'nameAndCallback',
  52. loc: paramsLocation(nodeArguments)
  53. });
  54. return;
  55. }
  56. if (!(0, _utils.isFunction)(callback)) {
  57. context.report({
  58. messageId: 'secondArgumentMustBeFunction',
  59. loc: paramsLocation(nodeArguments)
  60. });
  61. return;
  62. }
  63. if (callback.async) {
  64. context.report({
  65. messageId: 'noAsyncDescribeCallback',
  66. node: callback
  67. });
  68. }
  69. if (!(0, _utils.isEachCall)(node) && callback.params.length) {
  70. context.report({
  71. messageId: 'unexpectedDescribeArgument',
  72. loc: paramsLocation(callback.params)
  73. });
  74. }
  75. if (callback.body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
  76. callback.body.body.forEach(node => {
  77. if (node.type === _experimentalUtils.AST_NODE_TYPES.ReturnStatement) {
  78. context.report({
  79. messageId: 'unexpectedReturnInDescribe',
  80. node
  81. });
  82. }
  83. });
  84. }
  85. }
  86. };
  87. }
  88. });
  89. exports.default = _default;