简体   繁体   English

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

[英]Generated Javascript from Coffeescript is not lint ready? -> Throws Lint Error in Yeoman / Grunt

at the moment i am trying to improve my workflow for building an web-app. 目前我正在努力改进构建网络应用程序的工作流程。 With Yeoman installed, the command "grunt" gives me a good way to combine and minify my javascript files. 安装了Yeoman后,命令“grunt”为我提供了一个很好的方法来组合和缩小我的javascript文件。 My main.js file gets generated from a lot of coffeescript files, which i'm doing manually before. 我的main.js文件是从很多coffeescript文件生成的,我之前手动做过。 I don't use the integrated way of compiling coffeescript because of file dependencies. 由于文件依赖性,我没有使用编译coffeescript的集成方法。 (this is ok) (还行吧)

But here's the problem: when i now trying to run "grunt" it gives me "lint" errors from my generated js file like: 但问题出在这里:当我现在尝试运行“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.

if i --force it to continue, the main.js in the outcoming dest folder is still empty 如果我 - 强制它继续,outcoming dest文件夹中的main.js仍为空

What can i do? 我能做什么? I thought that compiled coffeescript is "lint ready" javascript? 我认为编译的coffeescript是“lint ready”javascript?

To compile my coffeescript files i use "rehab": https://www.npmjs.org/package/rehab 要编译我的coffeescript文件,我使用“rehab”: https ://www.npmjs.org/package/rehab

which provides me this Cakefile: 它为我提供了这个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: 更新:

If I understand correctly my main.js file will never passing jshint, so i have to remove the checking from yeoman / grunt to go further? 如果我理解正确,我的main.js文件将永远不会传递jshint,所以我必须从yeoman / grunt删除检查以进一步? I removed this line from my gruntfile.js: 我从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'
        ]
    },

Now i got no errors if running "grunt", but my output in dest folder contains still an empty main.js :( 现在我没有错误,如果运行“咕噜”,但我在dest文件夹中的输出仍包含一个空的main.js :(

I don't think the Coffeescript team cares about having its generated code pass jslint. 我不认为Coffeescript团队关心生成的代码是否通过了jslint。 (Or they used to, but that time has passed). (或者他们曾经,但那个时间过去了)。 See JavaScript Lint warnings caused by default argument values bug on the Coffeescript Github repo. 请参阅Coffeescript Github存储库中由默认参数值错误导致的JavaScript Lint警告

You could use coffeelint to check your code (there's even a Grunt module ). 您可以使用coffeelint检查您的代码(甚至还有一个Grunt模块 )。

However, Coffeelint checks several things but misses things that you may expect if you're expecting jslint style checks. 但是,Coffeelint会检查几件事情,但如果您期待jslint样式检查,则会错过您可能会遇到的事情。 (Coffeelint is more a stylistic checker). (Coffeelint更像是一种风格检查者)。

In a large Coffeescript project I've taken to using both coffeelint and coffee-jshint . 在一个大型的Coffeescript项目中,我已经开始使用coffeelint coffee-jshint js* hint * makes more pragmatic choices about Javascript style (and has an easier interface to turn everything off), which jives more with the Javascript that Coffeescript produces. js * hint *对Javascript风格做出了更实用的选择(并且有一个更简单的界面可以关闭所有内容),这使用Coffeescript生成的Javascript更多。 The coffee-jshint package passes the right parameters to jshint to not be too strict with the machine generated code. coffee-jshint包将正确的参数传递给jshint,对机器生成的代码不太严格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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