如何在没有找到文件的情况下让gruntjs跳过eslint任务?

问题描述:

我正在用grunt-eslint插件使用grunt。这是一个较大的咕task任务的一部分,它首先找到更改的文件并使用它们执行各种任务。如果没有更改任何JS文件(例如,如果我只是更改CSS文件),则整个任务将中止,因为eslint失败,并显示“找不到任何要验证的文件”消息。如何在没有找到文件的情况下让gruntjs跳过eslint任务?

$ grunt eslint:precommit 
Running "eslint:precommit" (eslint) task 
Could not find any files to validate. 
Warning: Task "eslint:precommit" failed. Use --force to continue. 

Aborted due to warnings. 

如果找不到任何JS文件,我不希望任务失败。

有没有办法要么:

A.有繁重的任务,甚至不叫eslint,而不是如果没有文件被运行失败?

B.如果没有文件运行,Eslan不会失败?

(相关,但具体到一个从咕噜叫不同工具:Can an assemble target be silenced if there are no matching files? (Without using --force)

使用动态任务是您的解决方案,在这里的链接文档:http://gruntjs.com/frequently-asked-questions#dynamic-alias-tasks

相关链接:

+0

谢谢。因此,如果找不到文件,基本上没有选项可以跳过任务,但是我可以创建自己的任务来检查文件并调用我想调用的任务(如果找到它们)?这很好,我只是想让grunt.file.isMatch现在找到这些文件。 –

+1

它不是grunt.file.isMatch,而是grunt.file.expand,它实际上可以找到文件。在这里博客:http://www.marcstober.com/blog/2016/01/07/grunt-file-match-and-grunt-file-ismatch-do-not-access-file-system/ –