1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const NormalizedMessage_1 = require("./NormalizedMessage");
|
4 | const FsHelper_1 = require("./FsHelper");
|
5 | const NormalizedMessageFactories_1 = require("./NormalizedMessageFactories");
|
6 | function createEslinter(eslintOptions) {
|
7 |
|
8 | const eslint = require('eslint');
|
9 |
|
10 | const eslinter = new eslint.CLIEngine(eslintOptions);
|
11 | const createNormalizedMessageFromEsLintFailure = NormalizedMessageFactories_1.makeCreateNormalizedMessageFromEsLintFailure();
|
12 | function getLintsForFile(filepath) {
|
13 | try {
|
14 | const lints = eslinter.executeOnFiles([filepath]);
|
15 | return lints;
|
16 | }
|
17 | catch (e) {
|
18 | FsHelper_1.throwIfIsInvalidSourceFileError(filepath, e);
|
19 | }
|
20 | return undefined;
|
21 | }
|
22 | function getFormattedLints(lintReports) {
|
23 | const allEsLints = [];
|
24 | for (const value of lintReports) {
|
25 | for (const lint of value.results) {
|
26 | allEsLints.push(...lint.messages.map(message => createNormalizedMessageFromEsLintFailure(message, lint.filePath)));
|
27 | }
|
28 | }
|
29 | return NormalizedMessage_1.NormalizedMessage.deduplicate(allEsLints);
|
30 | }
|
31 | return { getLints: getLintsForFile, getFormattedLints };
|
32 | }
|
33 | exports.createEslinter = createEslinter;
|
34 |
|
\ | No newline at end of file |