createEslinter.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. var __importStar = (this && this.__importStar) || function (mod) {
  3. if (mod && mod.__esModule) return mod;
  4. var result = {};
  5. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  6. result["default"] = mod;
  7. return result;
  8. };
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. var path = __importStar(require("path"));
  11. var FsHelper_1 = require("./FsHelper");
  12. function createEslinter(eslintOptions) {
  13. // eslint-disable-next-line @typescript-eslint/no-var-requires
  14. var CLIEngine = require('eslint').CLIEngine;
  15. // See https://eslint.org/docs/developer-guide/nodejs-api#cliengine
  16. var eslinter = new CLIEngine(eslintOptions);
  17. function getReport(filepath) {
  18. try {
  19. if (eslinter.isPathIgnored(filepath) ||
  20. path.extname(filepath).localeCompare('.json', undefined, {
  21. sensitivity: 'accent'
  22. }) === 0) {
  23. return undefined;
  24. }
  25. var lintReport = eslinter.executeOnFiles([filepath]);
  26. if (eslintOptions && eslintOptions.fix) {
  27. CLIEngine.outputFixes(lintReport);
  28. }
  29. return lintReport;
  30. }
  31. catch (e) {
  32. FsHelper_1.throwIfIsInvalidSourceFileError(filepath, e);
  33. }
  34. return undefined;
  35. }
  36. return { getReport: getReport };
  37. }
  38. exports.createEslinter = createEslinter;
  39. //# sourceMappingURL=createEslinter.js.map