Skip to content

Commit

Permalink
deal with ansible-lint uncaught errors that were parsed warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Aug 1, 2024
1 parent 1979935 commit 8f29564
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
12 changes: 12 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export default {
const stdinMatches = /\.dirname/.exec(stderr);
const extraOutputMatches = /skip specific rules/.exec(stderr);
const warningMatches = /WARNING/.exec(stderr);
const errorMatches = /ERROR\s+(.*)/.exec(stderr);
const passedOutputMatches = /^Passed/.exec(stderr);

// check for stdin lint attempt
Expand All @@ -224,6 +225,17 @@ export default {
},
});
}
// check for fatal errors during linting
else if (errorMatches != null) {
toReturn.push({
severity: 'error',
excerpt: errorMatches[1],
location: {
file,
position: [[0, 0], [0, 1]],
},
});
}
// output other errors directly to Atom notification display, and ignore noisy output
else if ((extraOutputMatches == null) && (warningMatches == null) && (passedOutputMatches == null) && (stderr !== '')) {
atom.notifications.addError(
Expand Down
20 changes: 14 additions & 6 deletions spec/linter-ansible-linting-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,25 +242,33 @@ describe('The Ansible Lint provider for Linter', () => {
);
});

it('finds the error message', () => {
it('finds the error messages', () => {
waitsForPromise(() =>
lint(editor).then(messages => {
expect(messages.length).toEqual(1);
expect(messages.length).toEqual(2);
})
);
});

it('verifies the message', () => {
it('verifies the messages', () => {
waitsForPromise(() => {
return lint(editor).then(messages => {
expect(messages[0].severity).toBeDefined();
expect(messages[0].severity).toEqual('error');
expect(messages[0].severity).toEqual('warning');
expect(messages[0].excerpt).toBeDefined();
expect(messages[0].excerpt).toEqual('Ansible syntax check failed for unknown reason; use syntax checker for more information.');
expect(messages[0].excerpt).toEqual('yaml[indentation]: Wrong indentation: expected at least 3');
expect(messages[0].location.file).toBeDefined();
expect(messages[0].location.file).toMatch(/.+unreadable_file\.yml$/);
expect(messages[0].location.position).toBeDefined();
expect(messages[0].location.position).toEqual([[0, 0], [0, 1]]);
expect(messages[0].location.position).toEqual([[5, 0], [5, 1]]);
expect(messages[1].severity).toBeDefined();
expect(messages[1].severity).toEqual('error');
expect(messages[1].excerpt).toBeDefined();
expect(messages[1].excerpt).toEqual("Loading . caused an AnsibleParserError exception: an error occurred while trying to read the file '/home/matt/git_repos/maintenance/linter-ansible-linting/spec/fixtures': [Errno 21] Is a directory: b'/home/matt/git_repos/maintenance/linter-ansible-linting/spec/fixtures'. [Errno 21] Is a directory: b'/home/matt/git_repos/maintenance/linter-ansible-linting/spec/fixtures', file was ignored.");
expect(messages[1].location.file).toBeDefined();
expect(messages[1].location.file).toMatch(/.+unreadable_file\.yml$/);
expect(messages[1].location.position).toBeDefined();
expect(messages[1].location.position).toEqual([[0, 0], [0, 1]]);
});
});
});
Expand Down

0 comments on commit 8f29564

Please sign in to comment.