Skip to content

Commit

Permalink
Make file heading link to the first error (#38)
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
jamestalmage authored and sindresorhus committed Jan 11, 2019
1 parent 492a0e3 commit a0cc031
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ module.exports = results => {
lines.push({type: 'separator'});
}

const firstErrorOrWarning = messages.find(({severity}) => severity === 2) || messages[0];

lines.push({
type: 'header',
filePath,
relativeFilePath: path.relative('.', filePath),
firstLineCol: messages[0].line + ':' + messages[0].column
firstLineCol: firstErrorOrWarning.line + ':' + firstErrorOrWarning.column
});

messages
Expand Down
16 changes: 15 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,24 @@ test('output', t => {
disableHyperlinks();
const output = m(defaultFixture);
console.log(output);
t.regex(stripAnsi(output), /index\.js:8:2\n/);
t.regex(stripAnsi(output), /index\.js:18:2\n/);
t.regex(stripAnsi(output), /✖[ ]{3}1:1[ ]{2}AVA should be imported as test.[ ]{6}ava\/use-test/);
});

test('file heading links to the first error line', t => {
disableHyperlinks();
const output = m(defaultFixture);
console.log(output);
t.regex(stripAnsi(output), /index\.js:18:2\n/);
});

test('file heading links to the first warning line if no errors in the file', t => {
disableHyperlinks();
const output = m(defaultFixture);
console.log(output);
t.regex(stripAnsi(output), /test\.js:1:1\n/);
});

test('no line numbers', t => {
disableHyperlinks();
const output = m(noLineNumbers);
Expand Down

0 comments on commit a0cc031

Please sign in to comment.