Gulp Jscs-TypeError:无法将未定义或null转换为对象 [英] Gulp Jscs - TypeError: Cannot convert undefined or null to object

查看:117
本文介绍了Gulp Jscs-TypeError:无法将未定义或null转换为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在项目中使用gulp-jscs,所以我已经根据文档:

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

npm install --save-dev gulp-jscs

但是当我尝试运行gulp文件时,出现此错误:

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.

推荐答案

您需要在项目的根目录中有一个.jscsrc文件.在此处,您可以提供JSCS的选项以及应遵循的代码样式规则.

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.

下面是.jscsrc,它是node-jscs项目本身使用的 .您可以使用它来建立自己的配置.

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

请注意,除非您在.jscsrc中包含"preset"或已明确指定规则.

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.

这篇关于Gulp Jscs-TypeError:无法将未定义或null转换为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆