diff --git a/package.json b/package.json index ee947858..7f56c5a7 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "touch": "1.0.0" }, "dependencies": { + "@simenb/eslint-file-util": "0.0.3", "async": "1.5.2", "chalk": "1.1.3", "chokidar": "1.5.2", diff --git a/src/utils/getFiles.js b/src/utils/getFiles.js index 57fadbca..d36d2517 100644 --- a/src/utils/getFiles.js +++ b/src/utils/getFiles.js @@ -1,9 +1,8 @@ 'use strict' var fs = require( 'fs' ) -var glob = require( 'glob' ) var async = require( 'async' ) -var path = require( 'path' ) +var globUtil = require( '@simenb/eslint-file-util/lib/util/glob-util' ) /** * @description globs files and returns an array, used in various methods @@ -15,45 +14,26 @@ var getFiles = function( dir ) { throw new TypeError( 'getFiles err. Expected string or array, but received: ' + typeof dir ) } - if ( typeof dir === 'string' ) { - return glob( dir, {}, function( err, files ) { - if ( err ) { throw err } + var arrayOfDirs = Array.isArray( dir ) ? dir : [dir] - files = files.filter( function( file ) { - var excluded = false - var relPath = path.relative( dir.replace( '/**/*.styl', '' ), file ) + var globPatterns = globUtil.resolveFileGlobPatterns( arrayOfDirs, { extensions: ['.styl'] } ) + var files = globUtil.listFilesToProcess( globPatterns, { + ignorePattern: this.config.exclude, + ignoreFileName: '.stylintignore' + } ) - this.config.exclude.forEach( function( exclude ) { - excluded = excluded || exclude.match( relPath ) - } ) + files = files + .filter( function( file ) { + return !file.ignored + } ) + .map( function( file ) { + return file.filename + } ) - return !excluded - }, this ) + this.cache.filesLen = files.length - 1 + this.cache.files = files - this.cache.filesLen = files.length - 1 - this.cache.files = files - - return async.map( this.cache.files, fs.readFile, this.parse.bind( this ) ) - }.bind( this ) ) - } - else if ( dir instanceof Array ) { - - var files = dir.filter( function( filepath ) { - var excluded = false - - this.config.exclude.forEach( function( exclude ) { - excluded = excluded || exclude.match( filepath ) - } ) - - return !excluded - }, this ) - - this.cache.filesLen = files.length - 1 - this.cache.files = files - return this.cache.files.forEach( function( file ) { - return this.read( file ) - }.bind( this ) ) - } + return async.map( this.cache.files, fs.readFile, this.parse.bind( this ) ) } module.exports = getFiles