Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

no-deprecated-functions.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = exports._clearCachedJestVersion = void 0;
  6. var _experimentalUtils = require("@typescript-eslint/experimental-utils");
  7. var _utils = require("./utils");
  8. let cachedJestVersion = null;
  9. /** @internal */
  10. const _clearCachedJestVersion = () => cachedJestVersion = null;
  11. exports._clearCachedJestVersion = _clearCachedJestVersion;
  12. const detectJestVersion = () => {
  13. if (cachedJestVersion) {
  14. return cachedJestVersion;
  15. }
  16. try {
  17. const jestPath = require.resolve('jest/package.json', {
  18. paths: [process.cwd()]
  19. });
  20. const jestPackageJson = // eslint-disable-next-line @typescript-eslint/no-require-imports
  21. require(jestPath);
  22. if (jestPackageJson.version) {
  23. const [majorVersion] = jestPackageJson.version.split('.');
  24. return cachedJestVersion = parseInt(majorVersion, 10);
  25. }
  26. } catch {}
  27. throw new Error('Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly');
  28. };
  29. var _default = (0, _utils.createRule)({
  30. name: __filename,
  31. meta: {
  32. docs: {
  33. category: 'Best Practices',
  34. description: 'Disallow use of deprecated functions',
  35. recommended: 'error'
  36. },
  37. messages: {
  38. deprecatedFunction: '`{{ deprecation }}` has been deprecated in favor of `{{ replacement }}`'
  39. },
  40. type: 'suggestion',
  41. schema: [],
  42. fixable: 'code'
  43. },
  44. defaultOptions: [],
  45. create(context) {
  46. var _context$settings, _context$settings$jes;
  47. const jestVersion = ((_context$settings = context.settings) === null || _context$settings === void 0 ? void 0 : (_context$settings$jes = _context$settings.jest) === null || _context$settings$jes === void 0 ? void 0 : _context$settings$jes.version) || detectJestVersion();
  48. const deprecations = { ...(jestVersion >= 15 && {
  49. 'jest.resetModuleRegistry': 'jest.resetModules'
  50. }),
  51. ...(jestVersion >= 17 && {
  52. 'jest.addMatchers': 'expect.extend'
  53. }),
  54. ...(jestVersion >= 21 && {
  55. 'require.requireMock': 'jest.requireMock',
  56. 'require.requireActual': 'jest.requireActual'
  57. }),
  58. ...(jestVersion >= 22 && {
  59. 'jest.runTimersToTime': 'jest.advanceTimersByTime'
  60. }),
  61. ...(jestVersion >= 26 && {
  62. 'jest.genMockFromModule': 'jest.createMockFromModule'
  63. })
  64. };
  65. return {
  66. CallExpression(node) {
  67. if (node.callee.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
  68. return;
  69. }
  70. const deprecation = (0, _utils.getNodeName)(node);
  71. if (!deprecation || !(deprecation in deprecations)) {
  72. return;
  73. }
  74. const replacement = deprecations[deprecation];
  75. const {
  76. callee
  77. } = node;
  78. context.report({
  79. messageId: 'deprecatedFunction',
  80. data: {
  81. deprecation,
  82. replacement
  83. },
  84. node,
  85. fix(fixer) {
  86. let [name, func] = replacement.split('.');
  87. if (callee.property.type === _experimentalUtils.AST_NODE_TYPES.Literal) {
  88. func = `'${func}'`;
  89. }
  90. return [fixer.replaceText(callee.object, name), fixer.replaceText(callee.property, func)];
  91. }
  92. });
  93. }
  94. };
  95. }
  96. });
  97. exports.default = _default;