import * as path from 'path' ; import Config from '../types/config/Config' ; import GoodFencesError from '../types/GoodFencesError' ; import GoodFencesResult from '../types/GoodFencesResult' ; import ImportRecord from './ImportRecord' ; let result = { errors : [ ] , warnings : [ ] , } ; export function resetResult ( ) { result = { errors : [ ] , warnings : [ ] , } ; } export function getResult ( ) { return result ; } export function reportViolation ( message , sourceFile , importRecord , config ) { let fencePath = config . path + path . sep + 'fence.json' ; let detailedMessage = `Good-fences violation in ${ sourceFile }:\n` + `    ${ message }: ${ importRecord . rawImport }\n` + `    Fence: ${ fencePath }` ; const error = { message , sourceFile , rawImport : importRecord . rawImport , fencePath , detailedMessage , } ; result . errors . push ( error ) ; } export function reportConfigError ( message , configPath ) { let fencePath = configPath + path . sep + 'fence.json' ; let detailedMessage = `Good-fences configuration error: ${ message }\n` + `    Fence: ${ fencePath }` ; const error = { message , fencePath , detailedMessage , } ; result . errors . push ( error ) ; } export function reportWarning ( message , configPath ? ) { let fencePath = configPath + path . sep + 'fence.json' ; let detailedMessage = `Good-fences warning: ${ message }` ; if ( configPath ) { detailedMessage += `\n    Fence: ${ fencePath }` ; } const warning = { message , fencePath , detailedMessage , } ; result . warnings . push ( warning ) ; }