import * as path from 'path' ; import Config from '../types/config/Config' ; import NormalizedPath from '../types/NormalizedPath' ; import getConfigsForFile from '../utils/getConfigsForFile' ; import { reportViolation } from '../core/result' ; import ImportRecord from '../core/ImportRecord' ; import getTagsForFile from '../utils/getTagsForFile' ; export default function validateImportRules ( sourceFile , importRecord ) { let configsForSource = getConfigsForFile ( sourceFile ) ; for ( let config of configsForSource ) { validateConfig ( config , sourceFile , importRecord ) ; } } function validateConfig ( config , sourceFile , importRecord ) { if ( ! config . imports ) { return ; } if ( ! path . relative ( config . path , importRecord . filePath ) . startsWith ( '..' ) ) { return ; } let importTags = getTagsForFile ( importRecord . filePath ) ; for ( let tag of config . imports ) { if ( importTags . indexOf ( tag ) != - 1 ) { return ; } } reportViolation ( 'Import not allowed' , sourceFile , importRecord , config ) ; }