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

fix module build failed error at Linter.parseResults #294

Merged
merged 4 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Linter.js
Original file line number Diff line number Diff line change
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
22 changes: 22 additions & 0 deletions test/Linter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Linter from '../src/Linter';

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

describe('Linter', () => {
const linter = new Linter(loaderContext, options);
buihdk marked this conversation as resolved.
Show resolved Hide resolved

it('should parse undefined results without error', () => {
// eslint-disable-next-line no-undefined
expect(linter.parseResults({})).toEqual(undefined);
buihdk marked this conversation as resolved.
Show resolved Hide resolved
});

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