tasks.js 958 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* jshint node: true, esnext: true */
  2. 'use strict';
  3. const gulp = require( 'gulp' );
  4. const jshint = require( 'gulp-jshint' );
  5. const jscs = require( 'gulp-jscs' );
  6. const fs = require( 'fs' );
  7. module.exports = ( config ) => {
  8. const src = [ '**/*.js' ].concat( config.IGNORED_FILES.map( i => '!' + i ), getGitIgnore() );
  9. gulp.task( 'lint', () => {
  10. return gulp.src( src )
  11. .pipe( jscs() )
  12. .pipe( jshint() )
  13. .pipe( jscs.reporter() )
  14. .pipe( jshint.reporter( 'jshint-reporter-jscs' ) );
  15. } );
  16. /**
  17. * Gets the list of ignores from `.gitignore`.
  18. *
  19. * @returns {String[]} The list of ignores.
  20. */
  21. function getGitIgnore( ) {
  22. let gitIgnoredFiles = fs.readFileSync( '.gitignore', 'utf8' );
  23. return gitIgnoredFiles
  24. // Remove comment lines.
  25. .replace( /^#.*$/gm, '' )
  26. // Transform into array.
  27. .split( /\n+/ )
  28. // Remove empty entries.
  29. .filter( ( path ) => !!path )
  30. // Add `!` for ignore glob.
  31. .map( i => '!' + i );
  32. }
  33. };