【问题标题】:How to have gruntjs skip eslint task if no files are found?如果找不到文件,如何让 gruntjs 跳过 eslint 任务?
【发布时间】:2016-01-06 16:33:09
【问题描述】:

我正在使用带有 grunt-eslint 插件的 grunt。这是一个更大的 grunt 任务的一部分,它首先找到更改的文件并使用它们执行各种任务。如果没有更改任何 JS 文件(例如,如果我只是更改 CSS 文件),则整个任务将中止,因为 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.如果没有文件运行,grunt 任务甚至没有调用 eslint 并且不会失败吗?

B.没有文件运行 eslint 不会失败吗?

(相关,但特定于从 grunt 调用的不同工具:Can an assemble target be silenced if there are no matching files? (Without using --force)

【问题讨论】:

    标签: gruntjs eslint grunt-eslint


    【解决方案1】:

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

    相关链接:

    【讨论】:

    • 谢谢。因此,如果找不到文件,基本上没有选项可以跳过任务,但是我可以创建自己的任务来检查文件并在找到文件时调用我想调用的任务?没关系,我现在只是想让 grunt.file.isMatch 找到文件。
    • 实际上找到文件的不是 grunt.file.isMatch,而是 grunt.file.expand。在这里写博客:marcstober.com/blog/2016/01/07/…
    猜你喜欢
    • 2023-04-11
    • 2014-02-28
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 2014-04-23
    • 2019-07-29
    • 1970-01-01
    相关资源
    最近更新 更多