'use strict';

var gulp = require('gulp');
var gutil = require('gulp-util');
var gulpif = require('gulp-if');
var jshint = require('gulp-jshint');
var cache = require('gulp-cached');
var jscs = require('gulp-jscs');
var notify = require('gulp-notify');
var tarsConfig = require('../../../tars-config');
var debug = require('gulp-debug');
var path = require('path');

var jsPathsToLint = [
  path.join('.', tarsConfig.fs.srcFolderName, tarsConfig.fs.componentFolderName, '**', '*.js'),
  path.join('!.', tarsConfig.fs.srcFolderName, tarsConfig.fs.componentFolderName, '**', '_*.js'),
  path.join('!.', tarsConfig.fs.srcFolderName, tarsConfig.fs.componentFolderName, '**', 'data', 'data.js')
];

if (tarsConfig.lintJsCodeBeforeModules) {
  tarsConfig.jsPathsToConcatBeforeModulesJs.forEach(function (path) {
    jsPathsToLint.push(path);
  });
}

if (tarsConfig.lintJsCodeAfterModules) {
  tarsConfig.jsPathsToConcatAfterModulesJs.forEach(function (path) {
    jsPathsToLint.push(path);
  });
}

/**
 * Check JS for style and errors (optional task)
 * @param  {object} buildOptions
 */
module.exports = function (buildOptions) {

  return gulp.task('js:check', function (cb) {
    if (tarsConfig.useJsLintAndHint) {
      return gulp.src(jsPathsToLint)
        .pipe(cache('hinting'))
        .pipe(jshint())
        // .pipe(jshint.reporter('jshint-stylish'))
        // .pipe(jscs())
        // .on('error', notify.onError(function (error) {
        //   return 'An error occurred while checking js.\nLook in the console for details.\n';
        // }));
        // .pipe(gulp.dest(path.join(tarsConfig.fs.srcFolderName, tarsConfig.fs.componentFolderName)))
        .pipe(debug({
          title: 'js:check'
        }));

    } else {
      gutil.log('!JS-style-check and hinting is not used!');
      cb(null);
    }
  });
};
@@ -358,16 +358,55 @@
 'path');
+%0Avar fixmyjs = require(%22gulp-fixmyjs%22);
 %0A%0Avar js
@@ -1390,35 +1390,32 @@
 ylish'))%0A       
- //
  .pipe(jscs())%0A 
@@ -1410,16 +1410,47 @@
 pe(jscs(
+%7B%0A          fix: true%0A        %7D
 ))%0A     
@@ -1617,27 +1617,24 @@
 %7D));%0A       
- //
  .pipe(gulp.

modify jscs task