5

Grunt で複数のサブタスク (src、lib、および test) を使用して JSHint をセットアップすると、うまく機能します。ただし、このセットアップを使い始めたばかりなので、多くのソース ファイルに多くのエラーがあります。

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

一度に 1 つのファイルで作業しているときに、その 1 つのファイルを再リントすることはできますか?

$ grunt jshint:src:one.js
... only errors from one.js ...

アップデート

複雑な点の 1 つは、監視タスクにも複数のサブタスクがあり、編集されるファイルの種類に基づいてさまざまなタスクを起動することです。

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" ]
    }
}

この理由は、アサーションなどのテストに使用されるすべてのグローバルを指定する別のものを使用しているsrc間に、 lib1 つ.jshintを使用するためです。とtestを組み合わせることができますが、 の JSHint 構成ファイルをオーバーライドできますか?srclibtest

4

2 に答える 2

4

grunt-contrib-watch-taskは、タスクを構成する方法の例を提供し、監視イベントを使用して変更されたファイルのみをリンティングします。

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);
});
于 2013-06-16T08:22:16.067 に答える