簡體   English   中英

為什么通過Grunt運行Google JavaScript Linter失敗?

[英]Why does running Google JavaScript Linter via Grunt fail?

我們將gjslinter與Grunt一起使用,以整理項目中的所有js文件。

Gruntfile.js中的配置如下所示:

gjslint: {
    options: {
        flags: ['--disable 220,110,200'],
        reporter: {
            name: 'gjslint_xml',
            dest: '<%= pkg.docs %>/gjslint/gjslint.xml'
        }
    },
    all: {
        src: ['<%= pkg.src %>/assets/js/modules/**', '<%= pkg.src %>/assets/js/lib/jquery/plugins/jquery-hse/**']
    }
}

但是,當我啟動棉絨失敗時:

$ grunt gjslint Running "gjslint:all" (gjslint) task
Warning: Task "gjslint:all" failed. Use --force to continue.

Aborted due to warnings.

為什么? 路徑應正確。 沒有更多錯誤消息或報告。 我該如何調試?

我按照以下步驟找到了解決方案(在Windows 10上):

  1. 安裝了Python2.7 https://www.python.org/downloads/
  2. PATHPYTHONPATH env變量中添加了Python安裝目錄C:/Python27以及C:/Python27/Scripts
  3. 通過在命令行中運行以下命令來安裝Google JavaScript Linter:

    pip install https://github.com/google/closure-linter/zipball/master

  4. 更改了Grunt的記者設置:

(Gruntfile.js):

reporter: {
    name: 'console' //report to console
}

現在,當運行grunt gjslint時,我在控制台中收到正確的錯誤消息。 它告訴我,有一個min.js文件,其中包含一些無效的代碼。 因此,我通過添加最小文件的異常將其從Gruntfile.js中刪除:

src: [
  '<%= pkg.src %>/assets/js/modules/**/*.js',
  '<%= pkg.src %>/assets/js/lib/jquery/plugins/jquery-hse/**/*.js',
  '!<%= pkg.src %>/assets/js/**/*.min.js'
]

這解決了問題!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM