gulp-jscs在非对象上调用Object.keys

时间:2015-02-06 15:06:16

标签: javascript node.js gulp jscs gulp-jscs

我是gulp的新手,并尝试使用它。我尝试使用gulp-jscs

时出现此错误
'default' errored after 98 ms
[16:58:00] TypeError: Object.keys called on non-object
    at Function.keys (native)
    at NodeConfiguration.Configuration._throwNonCamelCaseErrorIfNeeded (/home/kbadr/Node_Projects/demo/membership/node_modules/gulp-jscs/node_modules/jscs/lib/config/configuration.js:440:12)
    at NodeConfiguration.Configuration.load (/home/kbadr/Node_Projects/demo/membership/node_modules/gulp-jscs/node_modules/jscs/lib/config/configuration.js:51:10)
    at StringChecker.configure (/home/kbadr/Node_Projects/demo/membership/node_modules/gulp-jscs/node_modules/jscs/lib/string-checker.js:66:29)
    at Checker.configure (/home/kbadr/Node_Projects/demo/membership/node_modules/gulp-jscs/node_modules/jscs/lib/checker.js:26:39)
    at module.exports (/home/kbadr/Node_Projects/demo/membership/node_modules/gulp-jscs/index.js:31:11)
    at Gulp.<anonymous> (/home/kbadr/Node_Projects/demo/membership/gulpfile.js:22:15)
    at module.exports (/home/kbadr/Node_Projects/demo/membership/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/home/kbadr/Node_Projects/demo/membership/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/home/kbadr/Node_Projects/demo/membership/node_modules/gulp/node_modules/orchestrator/index.js:214:10

这是我的gulpfile

var gulp = require('gulp');
var jscs = require('gulp-jscs');

gulp.task('default', function () {
    return gulp.src('src/app.js')
        .pipe(jscs());
});

3 个答案:

答案 0 :(得分:7)

如果jscs没有.jscsrc的读取权限或者它不存在,这似乎就会发生。这是在我从一个旧的git repro复制并粘贴之后发生的。要解决此问题,请使用文本编辑器打开文件并重新保存,接受覆盖提示以及从&#39;开始。&#39; (例如.jscsrc)再次运行您的任务,它将完成。

答案 1 :(得分:2)

我遇到了同样的问题:“无法在 /Desktop/node/My_Project_Name/.jscsrc加载JSCS配置文件 意外的输入结束....“

我能够通过首先检查文件是否存在于项目的根目录中来解决问题。在终端运行此命令: ls -ld。?*

该文件从未为我创建过,因此我创建了 .jscsrc 文件,然后添加了以下代码:

{
 "excludeFiles": ["node_modules/**", "bower_components/**"],

"requireCurlyBraces": [
    "if",
    "else",
    "for",
    "while",
    "do",
    "try",
    "catch"
],
"requireOperatorBeforeLineBreak": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"maximumLineLength": {
  "value": 100,
  "allowComments": true,
  "allowRegex": true
},
"validateIndentation": 4,
"validateQuoteMarks": "'",

"disallowMultipleLineStrings": true,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowMultipleVarDecl": null,

"requireSpaceAfterKeywords": [
  "if",
  "else",
  "for",
  "while",
  "do",
  "switch",
  "return",
  "try",
  "catch"
],
"requireSpaceBeforeBinaryOperators": [
    "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=",
    "&=", "|=", "^=", "+=",

    "+", "-", "*", "/", "%", "<<", ">>", ">>>", "&",
    "|", "^", "&&", "||", "===", "==", ">=",
    "<=", "<", ">", "!=", "!=="
],
"requireSpaceAfterBinaryOperators": true,
"requireSpacesInConditionalExpression": true,
"requireSpaceBeforeBlockStatements": true,
"requireLineFeedAtFileEnd": true,
"disallowSpacesInsideObjectBrackets": "all",
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,

"validateJSDoc": {
    "checkParamNames": true,
    "requireParamTypes": true
},

"disallowMultipleLineBreaks": true,

"disallowCommaBeforeLineBreak": null,
"disallowDanglingUnderscores": null,
"disallowEmptyBlocks": null,
"disallowMultipleLineStrings": null,
"disallowTrailingComma": null,
"requireCommaBeforeLineBreak": null,
"requireDotNotation": null,
"requireMultipleVarDecl": null,
"requireParenthesesAroundIIFE": true
}

将此文件保存到项目的根目录,然后再次运行gulp task命令它应该可以工作。

答案 2 :(得分:0)

在ngCordova上更新了bower.json中的依赖项并解决了问题!!!