Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 69aa809

Browse files
authored
Merge pull request #187 from AtomLinter/json_output
convert output parsing to json
2 parents 9b35ab8 + a8bde23 commit 69aa809

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/main.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ export default {
5757
const filePath = activeEditor.getPath();
5858
const [projectPath, projectRelativeFilePath] = atom.project.relativizePath(filePath);
5959

60-
// With the custom format the puppet-int ouput looks like this:
61-
// error mongodb::service not in autoload module layout 3 7
62-
const regexLine = /^(warning|error)\s(.*)\s(\d+)\s(\d+)$/;
63-
const args = ['--relative', '--log-format', '%{kind} %{message} %{line} %{column}', '--error-level', errorLevel];
60+
// Setup args
61+
const args = ['--relative', '--json', '--error-level', errorLevel];
6462

6563
const optionsMap = require('./flags.js');
6664

@@ -82,23 +80,27 @@ export default {
8280
}
8381
const toReturn = [];
8482

83+
// Parse JSON output and immediately access zeroth element of redundant outer array
84+
const info = JSON.parse(output)[0];
85+
8586
// Check for proper warnings and errors from stdout
86-
output.split(/\r?\n/).forEach((line) => {
87-
const matches = regexLine.exec(line);
88-
if (matches != null) {
89-
const errLine = Number.parseInt(matches[3], 10) - 1;
90-
const errCol = Number.parseInt(matches[4], 10) - 1;
87+
if (info.length > 0) {
88+
info.forEach((issue) => {
89+
// bypass char line limit
90+
const line = issue.line - 1;
91+
const col = issue.column - 1;
9192

9293
toReturn.push({
93-
severity: matches[1],
94-
excerpt: matches[2],
94+
severity: issue.kind,
95+
excerpt: issue.message,
9596
location: {
97+
// bug in atom-linter cannot use issue.path
9698
file: filePath,
97-
position: helpers.generateRange(activeEditor, errLine, errCol),
99+
position: helpers.generateRange(activeEditor, line, col),
98100
},
99101
});
100-
}
101-
});
102+
});
103+
}
102104
return toReturn;
103105
});
104106
},

0 commit comments

Comments
 (0)