Gulp Jscs - TypeError: Cannot convert undefined or null to object

落花浮王杯 提交于 2019-12-10 15:55:15

问题


I wanted to use gulp-jscs in my project, so I've installed it according the documentation:

npm install --save-dev gulp-jscs

But when I try to run the gulp file, I'm getting this error:

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)

Also, there are other errors related to this:

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.

回答1:


You need to have a .jscsrc file in the root of you project present. In there you can provide options for JSCS as well as the code style rules that should be followed.

Below is the .jscsrc that's used by node-jscs project itself. You can use this to base your own configuration on.

{
    "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/*"
    ]
}

Note that jscs won't actually check for anything unless you have a "preset" in your .jscsrc or have explicitly specified the rules that should be followed.



来源:https://stackoverflow.com/questions/40773304/gulp-jscs-typeerror-cannot-convert-undefined-or-null-to-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!