diff --git a/lib/main.js b/lib/main.js index dd72231..656fbfd 100644 --- a/lib/main.js +++ b/lib/main.js @@ -108,6 +108,7 @@ export default { return helpers.exec(atom.config.get('linter-ansible-syntax.ansibleExecutablePath'), args, { cwd: require('path').dirname(file), stream: 'stderr', allowEmptyStderr: true }).then(output => { // capture the error const matchesError = /ERROR!\s(.*)/.exec(output); + const matchesYAMLError = /Syntax Error while loading YAML\.\n\s*(.*)\n/; // check if the output is guessing at which file has the issue; if so, capture the file name with an issue if it is elsewhere const matchesFile = /The error appears to (?:have been|be) in '(.*)':/.exec(output); @@ -119,13 +120,17 @@ export default { const matchesRange = /line\s(\d+),\scolumn\s(\d+)/.exec(output); let theRange = [[0, 0], [0, 1]]; + // if this is a yaml syntax error, then replace the ansible error message with the yaml syntax error + let excerpt = matchesYAMLError == null ? matchesError[1] : matchesYAMLError[1]; + + // parse range if (matchesRange != null) { theRange = [[Number.parseInt(matchesRange[1], 10) - 1, Number.parseInt(matchesRange[2], 10) - 1], [Number.parseInt(matchesRange[1], 10) - 1, Number.parseInt(matchesRange[2], 10)]]; } toReturn.push({ severity: 'error', - excerpt: matchesError[1], + excerpt, location: { file: theFile, position: theRange, diff --git a/spec/linter-ansible-syntax-spec.js b/spec/linter-ansible-syntax-spec.js index 2c87790..e61e10d 100644 --- a/spec/linter-ansible-syntax-spec.js +++ b/spec/linter-ansible-syntax-spec.js @@ -87,7 +87,7 @@ describe('The Ansible Syntax Check provider for Linter', () => { expect(messages[0].location.file).toBeDefined(); expect(messages[0].location.file).toMatch(/.+yaml_syntax\.yml$/); expect(messages[0].location.position).toBeDefined(); - expect(messages[0].location.position).toEqual([[9, 0], [9, 1]]); + expect(messages[0].location.position).toEqual([[8, 0], [8, 1]]); }); }); });