繁体   English   中英

从Coffeescript生成的Javascript不是lint准备好了吗? - >在Yeoman / Grunt中引发Lint错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM