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 fileHasNecessaryTag from '../utils/fileHasNecessaryTag' ; const minimatch = require ( 'minimatch' ) ; export default function validateDependencyRules ( sourceFile , importRecord ) { let configsForSource = getConfigsForFile ( sourceFile ) ; for ( let config of configsForSource ) { validateConfig ( config , sourceFile , importRecord ) ; } } function validateConfig ( config , sourceFile , importRecord ) { if ( ! config . dependencies ) { return ; } for ( let dependencyRule of config . dependencies ) { if ( minimatch ( importRecord . rawImport , dependencyRule . dependency ) && fileHasNecessaryTag ( sourceFile , dependencyRule . accessibleTo ) ) { return ; } } reportViolation ( 'Dependency is not allowed' , sourceFile , importRecord , config ) ; }