ahmednuaman / grunt-scss-lint

A Grunt task to lint your SCSS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Errors Thrown When Linting 0 Files

justinanastos opened this issue · comments

When you try to run the task on 0 files, for example, when you are only linting files that have changed since the last commit and there are no scss files, an error is thrown:

Running "scsslint:changed" (scsslint) task
Running scss-lint on changed
>> scss-lint failed with error code: 66
>> and the following message:Error: Command failed:
Warning: Task "scsslint:changed" failed. Use --force to continue.

This is by design, error code 66 is no_input, I think you need to adjust your grunt task code to only run the linter when scss files have changed.

Eg:

grunt.config('watch', {
  compass: {
    files: [
      '<%= compass.dev.options.sassDir %>/**/*.scss'
    ],
    tasks: [
      'scsslint',
      'compass:dev'
    ]
  },

In my use case, I pass it a list of tasks to run, which calculate which files to run on depending on what has been staged in github. I don't know of a way to make it only run the grunt tasks on tasks that have >0 files so this made more sense since it'll behave similarly to jshint and jscs.

Try this:

module.exports = function (grunt) {
  var _ = require('lodash'),
      changedFiles = {},
      onChange;

  grunt.config('watch', {
    compass: {
      files: [
        '<%= compass.dev.options.sassDir %>/**/*.scss'
      ],
      tasks: [
        'scsslint',
        'compass:dev'
      ]
    },
    css: {
      files: [
        'assets/css/*.css',
        'assets/img/*.{gif,png,svg}',
        'assets/img/**/*.jpg'
      ],
      options: {
        livereload: true
      }
    },
    js: {
      files: [
        '*.js',
        'assets/js/**/*.js',
        'grunt/*.js',
        'test/**/*.js'
      ],
      tasks: [
        'jshint',
        'jscs',
        'karma:unit'
      ],
      options: {
        livereload: true,
        spawn: false
      }
    },
    html: {
      files: [
        'assets/partial/**/*.html',
        '*.html'
      ],
      options: {
        livereload: true
      }
    }
  });

  onChange = _.debounce(function () {
    var changedJSFiles = changedFiles['js'];

    if (changedJSFiles) {
      grunt.config('jshint.all', changedJSFiles);
      grunt.config('jscs.src', changedJSFiles);
    }

    changedFiles = {};
  }, 200);

  grunt.event.on('watch', function (action, file) {
    var ext = file.split('.').pop();

    if (!changedFiles[ext]) {
      changedFiles[ext] = [];
    }

    changedFiles[ext].push(file);
    onChange();
  });

  grunt.loadNpmTasks('grunt-contrib-watch');
};

This task is just abstracting the original linting gem, I think this problem is very trivial and can be fixed by smarter watcher tasks.