Gulp Jscs - 类型错误:无法将未定义或 null 转换为对象

2024-04-21

我想在我的项目中使用 gulp-jscs,所以我按照文档 https://github.com/jscs-dev/gulp-jscs:

npm install --save-dev gulp-jscs

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

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.

你需要有一个.jscsrc文件存在于您项目的根目录中。在那里你可以提供JSCS 的选项 http://jscs.info/overview#options代码风格规则 http://jscs.info/rules.html应该遵循这一点。

下面是.jscsrc that's used by node-jscs项目本身 https://github.com/jscs-dev/node-jscs/blob/master/.jscsrc。您可以使用它作为您自己的配置的基础。

{
    "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实际上不会检查任何东西,除非你有"preset"在你的.jscsrc或已明确指定rules http://jscs.info/rules.html应该遵循这一点。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Gulp Jscs - 类型错误:无法将未定义或 null 转换为对象 的相关文章