2013-07-04 50 views
3

我想用grunt運行jshint。這工作,但現在我想輸出爲HTML。這裏是我的咕嚕文件grunt:如何生成jshint輸出爲HTML

module.exports = function(grunt) { 

    // Project configuration. 
    grunt.initConfig({ 
     jshint: { 
      all: ['Gruntfile.js', 'src/*.js'] 
      , options: { 
       //reporter: 'jslint' 
       reporter:'checkstyle' 
       , reporterOutput: 'jshint.html' 
      } 
     } 
    }); 

    grunt.loadNpmTasks('grunt-contrib-jshint'); 
}; 

運行此grunt taks,輸出是XML。任何建議如何將其轉化爲輸出HTML的東西?

非常感謝

回答

4

您需要編寫自定義記者。檢查編寫定製記者jshint文檔:http://jshint.com/docs/reporters/然後你就可以指定向記者路徑以:

options: { 
    reporter: '/path/to/custom/html/reporter', 
    reporterOutput: 'jshint.html' 
} 
+0

那麼,有人寫過這樣的記者嗎?這應該是非常簡單的,我寧願使用現有的而不是試圖重新實現它。 –

+0

我還沒有看到現有的HTML記者。大多數只是XML和JSON。 –

+2

你可以檢查這個:[jshint-html-reporter](https://www.npmjs.org/package/jshint-html-reporter)。 我曾經在CI版本中顯示報告,它像一個魅力。 – tuchi35

4

您可以使用來自的NodeJS

jshint記者這在HTML

產生輸出

https://www.npmjs.com/package/jshint-html-reporter

將此內容添加到您的GruntFile.js中

grunt.initConfig({ 
    jshint: { 
     options: { 
      reporter: require('jshint-html-reporter'), 
      reporterOutput: 'jshint-report.html' 
     }, 
     target: ['file.js'] 
    } 
}); 

grunt.loadNpmTasks('grunt-contrib-jshint'); 
grunt.registerTask('default', ['jshint']);