Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
fix: module build failed error at Linter.parseResults (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
buihdk authored and ricardogobbosouza committed Sep 24, 2019
1 parent 4895987 commit 360e69c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Linter.js
Expand Up @@ -113,10 +113,12 @@ export default class Linter {

parseResults({ results }) {
// add filename for each results so formatter can have relevant filename
results.forEach((r) => {
// eslint-disable-next-line no-param-reassign
r.filePath = this.loaderContext.resourcePath;
});
if (results) {
results.forEach((r) => {
// eslint-disable-next-line no-param-reassign
r.filePath = this.loaderContext.resourcePath;
});
}

return results;
}
Expand Down
24 changes: 24 additions & 0 deletions test/Linter.test.js
@@ -0,0 +1,24 @@
import Linter from '../src/Linter';

const loaderContext = { resourcePath: 'test' };
const options = {
eslintPath: 'eslint',
ignore: false,
formatter: jest.fn(),
};
const res = { results: [{ filePath: '' }] };

describe('Linter', () => {
let linter;
beforeAll(() => {
linter = new Linter(loaderContext, options);
});

it('should parse undefined results without error', () => {
expect(linter.parseResults({})).toBeUndefined();
});

it('should parse results correctly', () => {
expect(linter.parseResults(res)).toEqual([{ filePath: 'test' }]);
});
});

0 comments on commit 360e69c

Please sign in to comment.