Skip to content

Commit e7699cc

Browse files
committed
Fix an issue where ESLint output can be incorrectly parsed on Mac.
1 parent 8ea12f1 commit e7699cc

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

stack/rush-stack-compiler-shared/src/shared/EslintRunner.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,26 @@ export class EslintRunner extends RushStackCompilerBase<ILintRunnerConfig> {
7979
'src/**/*.{ts,tsx}'
8080
];
8181

82+
const stdoutBuffer: string[] = [];
83+
8284
return this._cmdRunner.runCmd({
8385
args: args,
86+
// ESLint errors are logged to stdout
87+
onError: (data: Buffer) => {
88+
this._terminal.writeErrorLine(`Unexpected STDERR output from ESLint: ${data.toString()}`)
89+
},
8490
onData: (data: Buffer) => {
85-
const dataStr: string = data.toString().trim();
86-
const eslintErrorLogFn: WriteFileIssueFunction = this._taskOptions.displayAsError
87-
? this._taskOptions.fileError
88-
: this._taskOptions.fileWarning;
91+
stdoutBuffer.push(data.toString());
92+
},
93+
onClose: (code: number, hasErrors: boolean, resolve: () => void, reject: (error: Error) => void) => {
94+
const dataStr: string = stdoutBuffer.join('');
8995

90-
// ESLint errors are logged to stdout
9196
try {
9297
const eslintFileResults: IEslintFileResult[] = JSON.parse(dataStr);
98+
99+
const eslintErrorLogFn: WriteFileIssueFunction = this._taskOptions.displayAsError
100+
? this._taskOptions.fileError
101+
: this._taskOptions.fileWarning;
93102
for (const eslintFileResult of eslintFileResults) {
94103
const pathFromRoot: string = path.relative(this._standardBuildFolders.projectFolderPath,
95104
eslintFileResult.filePath);
@@ -109,8 +118,7 @@ export class EslintRunner extends RushStackCompilerBase<ILintRunnerConfig> {
109118
// displayAsError value
110119
this._terminal.writeErrorLine(dataStr);
111120
}
112-
},
113-
onClose: (code: number, hasErrors: boolean, resolve: () => void, reject: (error: Error) => void) => {
121+
114122
if (this._taskOptions.displayAsError && (code !== 0 || hasErrors)) {
115123
reject(new Error(`exited with code ${code}`));
116124
} else {

0 commit comments

Comments
 (0)