in packages/flow-dev-tools/src/update-suppressions/update-suppressionsRunner.js [69:132]
async function getErrorsForAllRootsForBinary(
bin: string,
roots: Array<RootPath>,
rootNames: Array<RootName>,
errorCheckCommand: 'check' | 'status',
flowconfigName: string,
only: ?('add' | 'remove'),
errorsByFile: Map<string, Map<number, ErrorsForLine>>,
): Promise<Map<string, Map<number, ErrorsForLine>>> {
for (let i = 0; i < roots.length; i++) {
const root = roots[i];
const rootName = rootNames[i];
let errors: Array<FlowError> = (
await getFlowErrorsWithWarnings(
bin,
errorCheckCommand,
root,
flowconfigName,
)
).errors;
for (const [file, errorsInFile] of collateErrors(errors)) {
const errorsByLine: Map<number, ErrorsForLine> =
errorsByFile.get(file) || new Map();
const errorsInFileWithMainSourceLocs = filterErrors(errorsInFile);
for (const error of errorsInFileWithMainSourceLocs) {
if (error.level === 'warning' && !isUnusedSuppression(error)) {
// Skip regular warnings
continue;
}
// Only errors with locations can be in here
if (error.message[0].loc === null) {
throw new Error('Found an error without a location');
} else {
// $FlowFixMe loc is non-null from check above
const loc: FlowLoc = error.message[0].loc;
const dataForLine: ErrorsForLine = errorsByLine.get(
loc.start.line,
) || {
unusedSuppressions: null,
errorCodes: new Set(),
loc,
};
if (isUnusedSuppression(error) && only !== 'add') {
const unusedSuppressions = dataForLine.unusedSuppressions || {
roots: new Set(),
bins: new Set(),
loc,
};
unusedSuppressions.roots.add(rootName);
unusedSuppressions.bins.add(bin);
dataForLine.unusedSuppressions = unusedSuppressions;
} else if (only !== 'remove') {
for (const code of error.error_codes) {
dataForLine.errorCodes.add(code);
}
}
errorsByLine.set(loc.start.line, dataForLine);
}
}
errorsByFile.set(file, errorsByLine);
}
}
return errorsByFile;
}