import fs from 'fs-extra';

module.exports = options => {
    const { gulp } = options;

    // lints scss files but does not fail
    const scss = () => {
        return gulp.src(gulp.data.get('paths.src.allFiles.scss'))
            .pipe(gulp.plugins.sassLint({
                configFile: gulp.data.get('paths.config.scsslint')
            }))
            .pipe(gulp.plugins.sassLint.format());
    };

    // lints scss files and fails
    const scssFail = () => {
        return scss().pipe(gulp.plugins.sassLint.failOnError());
    };

    // lints scss files and create a report
    const scssReport = () => {
        const filePath = gulp.data.get('paths.reports.scss');

        fs.ensureFileSync(filePath);

        const fileStream = fs.createWriteStream(filePath);
        const stream = gulp.src(gulp.data.get('paths.src.allFiles.scss'))
            .pipe(gulp.plugins.sassLint({
                configFile: gulp.data.get('paths.config.scsslint'),
                options: {
                    formatter: 'checkstyle'
                }
            }))
            .pipe(gulp.plugins.sassLint.format(fileStream));

        stream.on('finish', function() {
            fileStream.end();
        });

        return stream;
    };

    // lints js files but does not fail
    const js = () => {
        return gulp.src(gulp.util._.flatten(gulp.data.get('paths.src.files.js')))
            .pipe(gulp.plugins.eslint({
                configFile: gulp.data.get('paths.config.eslint')
            }))
            .pipe(gulp.plugins.eslint.format());
    };

    // lints js files and fails
    const jsFail = () => {
        return js().pipe(gulp.plugins.eslint.failOnError());
    };

    // lints js files and create a report
    const jsReport = () => {
        const filePath = gulp.data.get('paths.reports.js');

        fs.ensureFileSync(filePath);

        const fileStream = fs.createWriteStream(filePath);
        const stream = gulp.src(gulp.util._.flatten(gulp.data.get('paths.src.files.js')))
            .pipe(gulp.plugins.eslint({
                configFile: gulp.data.get('paths.config.eslint')
            }))
            .pipe(gulp.plugins.eslint.format('checkstyle', fileStream));

        stream.on('finish', () => {
            fileStream.end();
        });

        return stream;
    };

    // lints html files but does not fail
    const html = () => {
        return gulp.src(gulp.data.get('paths.src.allFiles.html'))
            .pipe(gulp.plugins.htmllint({
                config: gulp.data.get('paths.config.htmllint')
            }));
    };

    // lints html files and fails
    const htmlFail = () => {
        // @todo does not really fail
        return gulp.src(gulp.data.get('paths.src.allFiles.html'))
            .pipe(gulp.plugins.htmllint({
                failOnError: true,
                config: gulp.data.get('paths.config.htmllint')
            }));
    };

    return {
        scss,
        'scss:fail': scssFail,
        'scss:report': scssReport,
        js,
        'js:fail': jsFail,
        'js:report': jsReport,
        html,
        'html:fail': htmlFail
    };
};

@@ -138,24 +138,48 @@
 nst scss = (
+options = %7B%7D, fileStream
 ) =%3E %7B%0A     
@@ -343,24 +343,49 @@
 g.scsslint')
+,%0A                options
 %0A           
@@ -428,32 +428,42 @@
 sassLint.format(
+fileStream
 ));%0A    %7D;%0A%0A    
@@ -856,200 +856,15 @@
 m = 
-gulp.src(gulp.data.get('paths.src.allFiles.scss'))%0A            .pipe(gulp.plugins.sassLint(%7B%0A                configFile: gulp.data.get('paths.config.scsslint'),%0A                options: %7B%0A    
+scss(%7B%0A
     
@@ -898,16 +898,17 @@
 ckstyle'
+,
 %0A       
@@ -916,17 +916,23 @@
         
-%7D
+options
 %0A       
@@ -941,58 +941,10 @@
    %7D
-))%0A            .pipe(gulp.plugins.sassLint.format(
+, 
 file
@@ -942,33 +942,32 @@
   %7D, fileStream)
-)
 ;%0A%0A        strea
@@ -1120,24 +1120,56 @@
 const js = (
+options = %7B%7D, format, fileStream
 ) =%3E %7B%0A     
@@ -1411,16 +1411,34 @@
 .format(
+format, fileStream
 ));%0A    
@@ -1825,112 +1825,10 @@
 m = 
-gulp.src(gulp.util._.flatten(gulp.data.get('paths.src.files.js')))%0A            .pipe(gulp.plugins.eslint
+js
 (%7B%0A 
@@ -1908,56 +1908,10 @@
    %7D
-))%0A            .pipe(gulp.plugins.eslint.format(
+, 
 'che
@@ -1931,17 +1931,16 @@
 eStream)
-)
 ;%0A%0A     
@@ -2100,24 +2100,43 @@
 nst html = (
+failOnError = false
 ) =%3E %7B%0A     
@@ -2230,32 +2230,61 @@
 gins.htmllint(%7B%0A
+                failOnError,%0A
                 
@@ -2475,213 +2475,17 @@
 urn 
-gulp.src(gulp.data.get('paths.src.allFiles.html'))%0A            .pipe(gulp.plugins.htmllint(%7B%0A                failOnError: true,%0A                config: gulp.data.get('paths.config.htmllint')%0A            %7D)
+html(true
 );%0A 

update lint.js - reusable methods