gpt4 book ai didi

gruntjs - 在 Grunt 中为单个文件运行 JSHint

转载 作者:行者123 更新时间:2023-12-04 20:11:08 25 4
gpt4 key购买 nike

我在 Grunt 中有多个子任务(src、lib 和 test)的 JSHint 设置,效果很好。但是,由于我们刚刚开始使用此设置,因此我们的许多源文件中存在很多错误。

$ grunt jshint:src
... lots of errors ...

一次处理一个文件时,是否可以重新整理该单个文件?
$ grunt jshint:src:one.js
... only errors from one.js ...

更新

一个复杂的问题是监视任务还有多个子任务,以根据编辑的文件类型触发不同的任务。
watch: {
src: {
files: [ SRC_DIR + "hgm*.js" ],
tasks: [ "jshint:src", "test" ]
},
lib: {
files: [ "lib/hgm-test-setup.js", "lib/hgm.loader.js" ],
tasks: [ "jshint:lib", "test" ]
},
test: {
files: [ "tests/**/*.js" ],
tasks: [ "jshint:test", "test" ]
}
}

这样做的原因是 srclib使用一个 .jshinttest使用另一个指定用于测试的全局变量,例如断言。我可以结合 srclib ,但是我可以覆盖 test 的 JSHint 配置文件吗? ?

最佳答案

grunt-contrib-watch-task ,提供了如何配置任务的示例,并使用 watch-event 仅对更改的文件进行 linting:

grunt.initConfig({
watch: {
scripts: {
files: ['lib/*.js'],
tasks: ['jshint'],
options: {
nospawn: true,
},
},
},
jshint: {
all: ['lib/*.js'],
},
});

// on watch events configure jshint:all to only run on changed file
grunt.event.on('watch', function(action, filepath) {
grunt.config(['jshint', 'all'], filepath);
});

关于gruntjs - 在 Grunt 中为单个文件运行 JSHint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17129407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com