2016-11-23 36 views
4

我想在我的項目中使用一口,JSCS,所以我根據documentation安裝了它:咕嘟咕嘟JSCS - 類型錯誤:無法轉換未定義或爲空反對

npm install --save-dev gulp-jscs 

但是當我嘗試運行一飲而盡文件,我得到這個錯誤:

TypeError: Cannot convert undefined or null to object 
    at Function.keys (native) 
    at copyConfiguration (C:\Users\[User]\Desktop\[Project]\ 
    node_modules\jscs\lib\config\configuration.js:920:12) 

此外,還有與此相關的其他錯誤:

at NodeConfiguration.Configuration. 
_processConfig([location-path]\node_modules\jscs\lib\config\configuration.js:459:5) 
    at NodeConfiguration.Configuration.load 
([location-path]\node_modules\jscs\lib\config\configuration.js:211:10) 
    at null.StringChecker.configure 
([location-path]\node_modules\jscs\lib\string-checker.js:62:29) 
    at null.Checker.configure ([location-path]\node_modules\jscs\lib\checker.js:27:39) 
    at Object.module.exports ([location-path]\node_modules\gulp-jscs\index.js:35:10) 
    at Gulp.<anonymous> ([location-path]\Gulpfile.js:60:17) 
    at module.exports ([location-path]\node_modules\orchestrator\lib\runTask.js:34:7) 
    at Gulp.Orchestrator._runTask ([location-path]\node_modules\orchestrator\index.js:273:3) 
Process terminated with code 1. 

回答

8

您需要在項目的根目錄中有一個.jscsrc文件。在那裏你可以提供options for JSCS以及the code style rules應該遵循。

以下是.jscsrc這就是used by node-jscs project itself。你可以使用它來建立你自己的配置。

{ 
    "preset": "google", 
    "fileExtensions": [".js", "jscs"], 

    "requireSemicolons": true, 
    "requireParenthesesAroundIIFE": true, 
    "maximumLineLength": 120, 
    "validateLineBreaks": "LF", 
    "validateIndentation": 4, 
    "disallowTrailingComma": true, 
    "disallowUnusedParams": true, 

    "disallowSpacesInsideObjectBrackets": null, 
    "disallowImplicitTypeConversion": ["string"], 

    "safeContextKeyword": "_this", 

    "jsDoc": { 
     "checkAnnotations": "closurecompiler", 
     "checkParamNames": true, 
     "requireParamTypes": true, 
     "checkRedundantParams": true, 
     "checkReturnTypes": true, 
     "checkRedundantReturns": true, 
     "requireReturnTypes": true, 
     "checkTypes": "capitalizedNativeCase", 
     "checkRedundantAccess": true, 
     "requireNewlineAfterDescription": true 
    }, 

    "excludeFiles": [ 
     "test/data/**", 
     "patterns/*" 
    ] 
} 

注意jscs實際上不會檢查任何東西,除非你有你的.jscsrc一個"preset"或已明確規定應遵循的rules