getBuiltinRule.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getBuiltinRule = void 0;
  6. /**
  7. * This is used to pull the definition of a builtin rule from eslint.
  8. *
  9. * Adopted from https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/rules/utils/get-builtin-rule.js.
  10. */
  11. var getBuiltinRule = function getBuiltinRule(id) {
  12. // TODO: Remove this when we drop support for ESLint 7
  13. var eslintVersion = require('eslint/package.json').version;
  14. if (eslintVersion.startsWith('7.')) {
  15. return require("eslint/lib/rules/".concat(id));
  16. } // In eslint 8 and beyond using https://nodejs.org/api/packages.html#subpath-exports
  17. // eslint has defined public exported paths and has locked the rest of the
  18. // directory as private.
  19. //
  20. // Though there is an issue when run with `jest` apparently where it does not support ESM.
  21. // So we're gonna do it the same old fashion way if it crashes when requiring.
  22. // ref: https://github.com/typescript-eslint/typescript-eslint/issues/4210#issuecomment-981203332
  23. try {
  24. // eslint-disable-next-line import/no-unresolved
  25. return require('eslint/use-at-your-own-risk').builtinRules.get(id);
  26. } catch (e) {
  27. return require("eslint/lib/rules/".concat(id));
  28. }
  29. };
  30. exports.getBuiltinRule = getBuiltinRule;