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