Closed mscarchilli closed 8 years ago
One solution I think will work for now is the following. It should work, but I haven't tested it fully. I think I'm more in denial that it actually works after many failed attempts!
This will lint the saved (newer) file, unless it's the main.scss file. The main.scss file is to @ import and compile the SCSS, so I excluded it from being linted with the grunt.event as it will run with the watch.css task. Granted having it just work with newer would be nicer. Hopefully this will help anybody out in the meantime. :)
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
scsslint: {
allFiles: ['web/assets/scss/**/*.scss'],
newerFiles: ['<%= scsslintCurrentFile %>'],
options: {
config: '.scss-lint.yml',
colorizeOutput: true,
compact: true,
force: true,
},
},
watch: {
options: {
livereload: true,
spawn: false,
},
css: {
files: ['web/assets/scss/main.scss'],
tasks: ['scsslint:allFiles'],
},
scsslint: {
files: ['web/assets/scss/**/*.scss', '!web/assets/scss/main.scss']
},
},
});
grunt.event.on('watch', function (action, filePath) {
var fileName = filePath.replace(/^.*[\\\/]/, '');
var fileExtension = fileName.split('.').pop();
if (fileName != 'main.scss' && fileExtension != 'js') {
grunt.config.set('scsslintCurrentFile', filePath);
grunt.task.run('scsslint:newerFiles:[' + filePath + ']');
}
});
grunt.loadNpmTasks('grunt-scss-lint');
grunt.registerTask('default',['watch']);
}
Sure, feel free to create a PR
@ahmednuaman Is there an update of this issue?
Nothing yet, waiting for a pull request.
Is there a way to do this if you are using grunt-config files? My watch is separate from my scsslint.
Would you please consider adding support for grunt-newer in a future release? Projects with a large amount of files to lint, really slows the entire task down significantly.
I tried to use your suggestion from this ticket but it's just a bit much to add. Trying to work it into a more normal Grunt task set up is a challenge in itself, especially when not using lodash or compass, and it's a bit more advanced than most users will be able to comprehend.
I would LOVE it if it supports grunt-newer in the future!