2020-09-14 21:56:35 +00:00
|
|
|
/* eslint-disable no-console */
|
2018-09-20 22:24:52 +00:00
|
|
|
|
|
|
|
import { readFileSync } from 'fs';
|
|
|
|
|
|
|
|
import { orderBy } from 'lodash';
|
|
|
|
|
|
|
|
import { ExceptionType } from './types';
|
|
|
|
|
|
|
|
export const ENCODING = 'utf8';
|
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
export function loadJSON<T>(target: string): T {
|
2018-09-20 22:24:52 +00:00
|
|
|
try {
|
|
|
|
const contents = readFileSync(target, ENCODING);
|
|
|
|
|
|
|
|
return JSON.parse(contents);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`Error loading JSON from ${target}: ${error.stack}`);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
export function sortExceptions(
|
|
|
|
exceptions: Array<ExceptionType>
|
|
|
|
): Array<ExceptionType> {
|
2018-09-20 22:24:52 +00:00
|
|
|
return orderBy(exceptions, ['path', 'lineNumber', 'rule']);
|
|
|
|
}
|