mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 20:13:32 +01:00
For #269213 This adds a new eslint rule for `as any` and `<any>({... })`. We'd like to remove almost all of these, however right now the first goal is to prevent them in new code. That's why with this first PR I simply add `eslint-disable` comments for all breaks Trying to get this change in soon after branching off for release to hopefully minimize disruption during debt week work
128 lines
3.2 KiB
TypeScript
128 lines
3.2 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import es from 'event-stream';
|
|
import fancyLog from 'fancy-log';
|
|
import ansiColors from 'ansi-colors';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
class ErrorLog {
|
|
constructor(public id: string) {
|
|
}
|
|
allErrors: string[][] = [];
|
|
startTime: number | null = null;
|
|
count = 0;
|
|
|
|
onStart(): void {
|
|
if (this.count++ > 0) {
|
|
return;
|
|
}
|
|
|
|
this.startTime = new Date().getTime();
|
|
fancyLog(`Starting ${ansiColors.green('compilation')}${this.id ? ansiColors.blue(` ${this.id}`) : ''}...`);
|
|
}
|
|
|
|
onEnd(): void {
|
|
if (--this.count > 0) {
|
|
return;
|
|
}
|
|
|
|
this.log();
|
|
}
|
|
|
|
log(): void {
|
|
const errors = this.allErrors.flat();
|
|
const seen = new Set<string>();
|
|
|
|
errors.map(err => {
|
|
if (!seen.has(err)) {
|
|
seen.add(err);
|
|
fancyLog(`${ansiColors.red('Error')}: ${err}`);
|
|
}
|
|
});
|
|
|
|
fancyLog(`Finished ${ansiColors.green('compilation')}${this.id ? ansiColors.blue(` ${this.id}`) : ''} with ${errors.length} errors after ${ansiColors.magenta((new Date().getTime() - this.startTime!) + ' ms')}`);
|
|
|
|
const regex = /^([^(]+)\((\d+),(\d+)\): (.*)$/s;
|
|
const messages = errors
|
|
.map(err => regex.exec(err))
|
|
.filter(match => !!match)
|
|
.map(x => x as string[])
|
|
.map(([, path, line, column, message]) => ({ path, line: parseInt(line), column: parseInt(column), message }));
|
|
|
|
try {
|
|
const logFileName = 'log' + (this.id ? `_${this.id}` : '');
|
|
fs.writeFileSync(path.join(buildLogFolder, logFileName), JSON.stringify(messages));
|
|
} catch (err) {
|
|
//noop
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
const errorLogsById = new Map<string, ErrorLog>();
|
|
function getErrorLog(id: string = '') {
|
|
let errorLog = errorLogsById.get(id);
|
|
if (!errorLog) {
|
|
errorLog = new ErrorLog(id);
|
|
errorLogsById.set(id, errorLog);
|
|
}
|
|
return errorLog;
|
|
}
|
|
|
|
const buildLogFolder = path.join(path.dirname(path.dirname(__dirname)), '.build');
|
|
|
|
try {
|
|
fs.mkdirSync(buildLogFolder);
|
|
} catch (err) {
|
|
// ignore
|
|
}
|
|
|
|
export interface IReporter {
|
|
(err: string): void;
|
|
hasErrors(): boolean;
|
|
end(emitError: boolean): NodeJS.ReadWriteStream;
|
|
}
|
|
|
|
export function createReporter(id?: string): IReporter {
|
|
const errorLog = getErrorLog(id);
|
|
|
|
const errors: string[] = [];
|
|
errorLog.allErrors.push(errors);
|
|
|
|
const result = (err: string) => errors.push(err);
|
|
|
|
result.hasErrors = () => errors.length > 0;
|
|
|
|
result.end = (emitError: boolean): NodeJS.ReadWriteStream => {
|
|
errors.length = 0;
|
|
errorLog.onStart();
|
|
|
|
return es.through(undefined, function () {
|
|
errorLog.onEnd();
|
|
|
|
if (emitError && errors.length > 0) {
|
|
// eslint-disable-next-line local/code-no-any-casts
|
|
if (!(errors as any).__logged__) {
|
|
errorLog.log();
|
|
}
|
|
|
|
// eslint-disable-next-line local/code-no-any-casts
|
|
(errors as any).__logged__ = true;
|
|
|
|
const err = new Error(`Found ${errors.length} errors`);
|
|
// eslint-disable-next-line local/code-no-any-casts
|
|
(err as any).__reporter__ = true;
|
|
this.emit('error', err);
|
|
} else {
|
|
this.emit('end');
|
|
}
|
|
});
|
|
};
|
|
|
|
return result;
|
|
}
|