[英]Generated Javascript from Coffeescript is not lint ready? -> Throws Lint Error in Yeoman / Grunt
目前我正在努力改進構建網絡應用程序的工作流程。 安裝了Yeoman后,命令“grunt”為我提供了一個很好的方法來組合和縮小我的javascript文件。 我的main.js文件是從很多coffeescript文件生成的,我之前手動做過。 由於文件依賴性,我沒有使用編譯coffeescript的集成方法。 (還行吧)
但問題出在這里:當我現在嘗試運行“grunt”時,它會從我生成的js文件中給出“lint”錯誤,如:
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.
如果我 - 強制它繼續,outcoming dest文件夾中的main.js仍為空
我能做什么? 我認為編譯的coffeescript是“lint ready”javascript?
要編譯我的coffeescript文件,我使用“rehab”: 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()
更新:
如果我理解正確,我的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 :(
我不認為Coffeescript團隊關心生成的代碼是否通過了jslint。 (或者他們曾經,但那個時間過去了)。 請參閱Coffeescript Github存儲庫中由默認參數值錯誤導致的JavaScript Lint警告 。
您可以使用coffeelint檢查您的代碼(甚至還有一個Grunt模塊 )。
但是,Coffeelint會檢查幾件事情,但如果您期待jslint樣式檢查,則會錯過您可能會遇到的事情。 (Coffeelint更像是一種風格檢查者)。
在一個大型的Coffeescript項目中,我已經開始使用coffeelint 和 coffee-jshint 。 js * hint *對Javascript風格做出了更實用的選擇(並且有一個更簡單的界面可以關閉所有內容),這使用Coffeescript生成的Javascript更多。 coffee-jshint包將正確的參數傳遞給jshint,對機器生成的代碼不太嚴格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.