'use strict' ; import * as nodes from '../parser/cssNodes' ; import { LintConfigurationSettings , Rules } from './lintRules' ; import { LintVisitor } from './lint' ; import { TextDocument , Range , Diagnostic , DiagnosticSeverity , LanguageSettings } from '../cssLanguageTypes' ; import { CSSDataManager } from '../languageFacts/dataManager' ; export class CSSValidation { private settings ? : LanguageSettings ; constructor ( private cssDataManager ) { } public configure ( settings ? ) { this . settings = settings ; } public doValidation ( document , stylesheet , settings = this . settings ) { if ( settings && settings . validate === false ) { return [ ] ; } const entries = [ ] ; entries . push . apply ( entries , nodes . ParseErrorCollector . entries ( stylesheet ) ) ; entries . push . apply ( entries , LintVisitor . entries ( stylesheet , document , new LintConfigurationSettings ( settings && settings . lint ) , this . cssDataManager ) ) ; const ruleIds = [ ] ; for ( const r in Rules ) { ruleIds . push ( Rules [ r as keyof typeof Rules ] . id ) ; } function toDiagnostic ( marker ) { const range = Range . create ( document . positionAt ( marker . getOffset ( ) ) , document . positionAt ( marker . getOffset ( ) + marker . getLength ( ) ) ) ; const source = document . languageId ; return < Diagnostic > { code : marker . getRule ( ) . id , source : source , message : marker . getMessage ( ) , severity : marker . getLevel ( ) === nodes . Level . Warning ? DiagnosticSeverity . Warning : DiagnosticSeverity . Error , range : range } ; } return entries . filter ( entry => entry . getLevel ( ) !== nodes . Level . Ignore ) . map ( toDiagnostic ) ; } }