2014-03-02 11 views
4

此刻我正試圖改進我的工作流程以構建Web應用程序。 隨着Yeoman的安裝,命令「咕嚕」給了我一個很好的方法來結合和縮小我的JavaScript文件。 我的main.js文件是從很多coffeescript文件生成的,我之前手動完成了這些文件。由於文件依賴性,我不使用編譯coffeescript的集成方式。 (這是確定)從Coffeescript生成Javascript是不是lint準備好了? - >在Yeoman/Grunt中拋出Lint錯誤

但這裏有一個問題: 現在當我試圖運行「咕嚕」它給從我的生成JS文件和我一樣「皮棉」錯誤:

line 3 col 3 Missing "use strict" statement. 
line 3 col 3 Expected 'var' to have an indentation at 5 instead at 3. 
line 4 col 102 Expected '{' and instead saw 'child'. 
line 4 col 233 A constructor name should start with an uppercase letter. 

Warning: Task "jshint:all" failed. Use --force to continue. 

如果我 - 強制它繼續,dest out文件夾中的main.js仍爲空

我該怎麼辦? 我認爲編譯後的coffeescript是「lint ready」的javascript?

編譯我的CoffeeScript文件,我用 「康復」: https://www.npmjs.org/package/rehab

提供我這個Cakefile:

{exec, spawn} = require 'child_process' 
Rehab = require 'rehab' 

build = -> 
     console.log "Building project from src/*.coffee to app/scripts/main.js" 

     files = new Rehab().process 'src' 
     files = files.join " " 

     join_to_single_file = "--join app/scripts/main.js" 
     compile_from_files = "--compile #{files}" 

     exec "coffee #{join_to_single_file} #{compile_from_files}", (err, stdout, stderr) -> 
     throw err if err 

task 'build', 'Build coffee2js using Rehab', sbuild = -> 
    build() 

UPDATE:

如果我理解正確的話我main.js文件將永遠不會傳遞jshint,所以我必須從yeoman/grunt中刪除檢查才能繼續?我刪除了這條線從我gruntfile.js:

// Make sure code styles are up to par and there are no obvious mistakes 
    jshint: { 
     options: { 
      jshintrc: '.jshintrc', 
      reporter: require('jshint-stylish') 
     }, 
     all: [ 
      'Gruntfile.js', 
      // removed '<%= yeoman.app %>/scripts/{,*/}*.js', 
      '!<%= yeoman.app %>/scripts/vendor/*', 
      'test/spec/{,*/}*.js' 
     ] 
    }, 

現在我如果運行的「咕嚕」有沒有錯誤,但我在dest文件夾輸出包含還是空main.js :(

+0

lint檢查編譯好的CoffeeScript沒有意義。您可以調整您的設置以適應CoffeeScript生成的內容,但它不會讓您獲得任何位置,因爲CoffeeScript *會始終生成代碼以適應該模式。 – Ryan

回答

4

我不牛逼認爲CoffeeScript的團隊關心有其生成的代碼通過JSLint的。(或者他們不習慣,但時間已經過去了)。查看該CoffeeScript的GitHub庫JavaScript Lint warnings caused by default argument values錯誤。

你可以使用coffeelint來檢查你的代碼(有甚至是Grunt module)。

但是,如果您期待jslint樣式檢查,Coffeelint會檢查幾件事情,但會漏掉您可能期望的事情。 (咖啡因更像是一種文體檢查工具)。

在一個大型Coffeescript項目中,我已經採用了coffeelint coffee-jshint。 js * 提示 *對Javascript風格做了更實用的選擇(並且有一個更簡單的界面可以關閉所有內容),它更多地使用Coffeescript生成的Javascript。 coffee-jshint包將正確的參數傳遞給jshint,以免機器生成的代碼過於嚴格。