2023-03-10 15:33:02 +00:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Copyright ( c ) Microsoft Corporation . All rights reserved .
* Licensed under the MIT License . See License . txt in the project root for license information .
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
const es = require ( 'event-stream' ) ;
const vfs = require ( 'vinyl-fs' ) ;
const { stylelintFilter } = require ( './filters' ) ;
const { getVariableNameValidator } = require ( './lib/stylelint/validateVariableNames' ) ;
module . exports = gulpstylelint ;
/** use regex on lines */
function gulpstylelint ( reporter ) {
const variableValidator = getVariableNameValidator ( ) ;
2023-03-22 13:59:25 +00:00
let errorCount = 0 ;
2023-03-10 15:33:02 +00:00
return es . through ( function ( file ) {
const lines = file . _ _lines || file . contents . toString ( 'utf8' ) . split ( /\r\n|\r|\n/ ) ;
file . _ _lines = lines ;
lines . forEach ( ( line , i ) => {
variableValidator ( line , unknownVariable => {
2023-03-22 13:59:25 +00:00
reporter ( file . relative + '(' + ( i + 1 ) + ',1): Unknown variable: ' + unknownVariable , true ) ;
errorCount ++ ;
2023-03-10 15:33:02 +00:00
} ) ;
} ) ;
this . emit ( 'data' , file ) ;
2023-03-22 13:59:25 +00:00
} , function ( ) {
if ( errorCount > 0 ) {
reporter ( 'All valid variable names are in `build/lib/stylelint/vscode-known-variables.json`\nTo update that file, run `./scripts/test-documentation.sh|bat.`' , false ) ;
}
this . emit ( 'end' ) ;
}
) ;
2023-03-10 15:33:02 +00:00
}
function stylelint ( ) {
return vfs
. src ( stylelintFilter , { base : '.' , follow : true , allowEmpty : true } )
2023-03-22 13:59:25 +00:00
. pipe ( gulpstylelint ( ( message , isError ) => {
if ( isError ) {
console . error ( message ) ;
} else {
console . info ( message ) ;
}
2023-03-10 15:33:02 +00:00
} ) )
. pipe ( es . through ( function ( ) { /* noop, important for the stream to end */ } ) ) ;
}
if ( require . main === module ) {
stylelint ( ) . on ( 'error' , ( err ) => {
console . error ( ) ;
console . error ( err ) ;
process . exit ( 1 ) ;
} ) ;
}