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

Commit 360e69c

Browse files
Khoa Buiricardogobbosouza
Khoa Bui
authored andcommitted
fix: module build failed error at Linter.parseResults (#294)
1 parent 4895987 commit 360e69c

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/Linter.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ export default class Linter {
113113

114114
parseResults({ results }) {
115115
// add filename for each results so formatter can have relevant filename
116-
results.forEach((r) => {
117-
// eslint-disable-next-line no-param-reassign
118-
r.filePath = this.loaderContext.resourcePath;
119-
});
116+
if (results) {
117+
results.forEach((r) => {
118+
// eslint-disable-next-line no-param-reassign
119+
r.filePath = this.loaderContext.resourcePath;
120+
});
121+
}
120122

121123
return results;
122124
}

test/Linter.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Linter from '../src/Linter';
2+
3+
const loaderContext = { resourcePath: 'test' };
4+
const options = {
5+
eslintPath: 'eslint',
6+
ignore: false,
7+
formatter: jest.fn(),
8+
};
9+
const res = { results: [{ filePath: '' }] };
10+
11+
describe('Linter', () => {
12+
let linter;
13+
beforeAll(() => {
14+
linter = new Linter(loaderContext, options);
15+
});
16+
17+
it('should parse undefined results without error', () => {
18+
expect(linter.parseResults({})).toBeUndefined();
19+
});
20+
21+
it('should parse results correctly', () => {
22+
expect(linter.parseResults(res)).toEqual([{ filePath: 'test' }]);
23+
});
24+
});

0 commit comments

Comments
 (0)