From 2702dfb4648887b8c478e56f85bd2b95ed738cb4 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 12 Oct 2016 18:13:40 +0200 Subject: [PATCH 1/2] [WIP] Make use of glob utils from eslint --- package.json | 1 + src/utils/getFiles.js | 48 ++++++++++++++++--------------------------- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index ee947858..17ce0f13 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "touch": "1.0.0" }, "dependencies": { + "@simenb/eslint-file-util": "0.0.1", "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..bf0a7b15 100644 --- a/src/utils/getFiles.js +++ b/src/utils/getFiles.js @@ -1,9 +1,9 @@ '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 +15,33 @@ 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 ) - this.config.exclude.forEach( function( exclude ) { - excluded = excluded || exclude.match( relPath ) - } ) - - return !excluded - }, this ) - - 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 ) { + files = files + .filter( function( file ) { + return !file.ignored + } ) + .map( function( file ) { + return file.filename + } ) + .filter( function( file ) { var excluded = false + var relPath = path.dirname( file ) this.config.exclude.forEach( function( exclude ) { - excluded = excluded || exclude.match( filepath ) + excluded = excluded || exclude.match( relPath ) } ) 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 ) ) - } + this.cache.filesLen = files.length - 1 + this.cache.files = files + + return async.map( this.cache.files, fs.readFile, this.parse.bind( this ) ) } module.exports = getFiles From 31e23f29e21fc8290be54b4ac9edda0de8378149 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 12 Oct 2016 19:41:11 +0200 Subject: [PATCH 2/2] Use glob util to filter, and provide custom ignore file --- package.json | 2 +- src/utils/getFiles.js | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 17ce0f13..7f56c5a7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "touch": "1.0.0" }, "dependencies": { - "@simenb/eslint-file-util": "0.0.1", + "@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 bf0a7b15..d36d2517 100644 --- a/src/utils/getFiles.js +++ b/src/utils/getFiles.js @@ -2,7 +2,6 @@ var fs = require( 'fs' ) var async = require( 'async' ) -var path = require( 'path' ) var globUtil = require( '@simenb/eslint-file-util/lib/util/glob-util' ) /** @@ -18,7 +17,10 @@ var getFiles = function( dir ) { var arrayOfDirs = Array.isArray( dir ) ? dir : [dir] var globPatterns = globUtil.resolveFileGlobPatterns( arrayOfDirs, { extensions: ['.styl'] } ) - var files = globUtil.listFilesToProcess( globPatterns ) + var files = globUtil.listFilesToProcess( globPatterns, { + ignorePattern: this.config.exclude, + ignoreFileName: '.stylintignore' + } ) files = files .filter( function( file ) { @@ -27,16 +29,6 @@ var getFiles = function( dir ) { .map( function( file ) { return file.filename } ) - .filter( function( file ) { - var excluded = false - var relPath = path.dirname( file ) - - this.config.exclude.forEach( function( exclude ) { - excluded = excluded || exclude.match( relPath ) - } ) - - return !excluded - }, this ) this.cache.filesLen = files.length - 1 this.cache.files = files