hasEslintConfiguration.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.hasEslintConfiguration = hasEslintConfiguration;
  6. var _fs = require("fs");
  7. async function hasEslintConfiguration(eslintrcFile, packageJsonConfig) {
  8. const configObject = {
  9. exists: false,
  10. emptyEslintrc: false,
  11. emptyPkgJsonConfig: false
  12. };
  13. if (eslintrcFile) {
  14. const content = await _fs.promises.readFile(eslintrcFile, {
  15. encoding: "utf8"
  16. }).then((txt)=>txt.trim().replace(/\n/g, ""), ()=>null);
  17. if (content === "" || content === "{}" || content === "---" || content === "module.exports = {}") {
  18. return {
  19. ...configObject,
  20. emptyEslintrc: true
  21. };
  22. }
  23. return {
  24. ...configObject,
  25. exists: true
  26. };
  27. } else if (packageJsonConfig == null ? void 0 : packageJsonConfig.eslintConfig) {
  28. if (Object.keys(packageJsonConfig == null ? void 0 : packageJsonConfig.eslintConfig).length) {
  29. return {
  30. ...configObject,
  31. exists: true
  32. };
  33. }
  34. return {
  35. ...configObject,
  36. emptyPkgJsonConfig: true
  37. };
  38. }
  39. return configObject;
  40. }
  41. //# sourceMappingURL=hasEslintConfiguration.js.map