Search code examples
gulp-eslint

Gulp-eslint throws errors on dynamically loaded JSs


I have a project structure like

Folder Structure

There are approx 10 JS files in com. lab1 and lab2 has a config.json file which tells, out of 10 files which files to be concatenated and placed as app-min.js in dist/lab1 or dist/lab2.

In the gulp file I've created something like this.

var filesArr = [];
var labName;

// Player Task
gulp.task('player', function () {
  return gulp.src(filesArr)
    .pipe(eslint())
    .pipe(babel())
    .pipe(concat('app-min.js'))
    .pipe(uglify({
      compress: {
        drop_console: true
      }
    }).on('error', gutil.log))
    .pipe(gulp.dest('dist/' + labName));
});

// Clean
gulp.task('clean', function () {
  if (readJson()) {
    return del([
      'dist/' + labName
    ]);
  }
  return null;
});

// Watch
gulp.task('watch', function () {
  gulp.watch(filesArr, gulp.series('player'));
});

// Read Json and create JS Array
function readJson() {
  // LAB STRUCTURE
  var _n = prompt('Specify the LAB name. ');
  labName = _n;
  var _path = path.resolve('./src/' + _n);
  var _exists = fs.existsSync(_path);
  if (_exists) {
    var _json = fs.readFileSync(path.resolve(_path + '/labstructure.json'), 'utf-8');
    var _jObj = JSON.parse(_json).labObj.components;
    for (var i = 0; i < _jObj.length; i++) {
      var _jsName = 'src/com/component/' + _jObj[i].ref + '.js';
      if (filesArr.indexOf(_jsName) === -1) {
        filesArr.push(_jsName);
      }
    }
  }
  return _exists;
}

gulp.task('default', gulp.series('clean', 'player', 'watch'));

Here the filesArr looks like:

[ 'src/com/component/ColorActClass.js',
  'src/com/component/PanelCompClass.js',
  'src/com/component/ToggleCompClass.js',
  'src/com/component/SliderCompClass.js',
  'src/com/component/CheckBoxCompClass.js',
  'src/com/component/ButtonCompClass.js',
  'src/com/component/LabelCompClass.js',
  'src/com/component/InputBoxClass.js',
  'src/com/component/ColorMonitorClass.js',
  'src/com/component/MsgBoxClass.js',
  'src/com/component/ConfBoxClass.js',
  'src/com/component/NumberPadClass.js',
  'src/com/main/lib/webfontloader.js',
  'src/com/main/lib/howler.core.min.js',
  'src/com/main/PlayerClass.js',
  'src/kl1001_color/BrainClass.js' ]

This works perfectly fine at the first place. But when any JS is modified then in watch player task throws eslint error on some files which are untouched. This doesn't happen always rather if watch is running for 10-20 mins then it throws error. Like this:

Error Image

In this case CheckBoxCompClass.js is not the file which is modified, but still got the issue. On top of that, the semicolon is in place. If this file has issue then eslint should have thrown the error at the first place.

Please help.


Solution

  • Accidentally, my NVM was set to an older version. Solved the issue after updating the NVM and by setting the current NVM version to the latest one.