我有一个 GitHub project已通过 Travis CI。创建 pull request对于新功能,Travis CI fails pr 和 push 由于两个 eslint 错误:
/home/travis/build/enove/Thriver/packages/thriver-accounts/lib/accounts.js
121:5 error Strings must use singlequote quotes
122:5 error Strings must use singlequote quotes
accounts.js
第 119 行到第 122 行如下:
119: return `Hello ${user.profile.firstname}!\n\n` +
120: `To verify your account email, simply click the link below.\n\n${url}\n\n` +
121: `If you weren't expecting this email, simply delete it.\n\n` +
122: `Thanks!\n\nAll of us at WCASA`;
提交甚至没有更改 accounts.js
,并且本地 eslint 顺利通过。我检查并验证了 node、npm 和 meteor 的版本在本地与它们在 Travis CI 中的版本相同。
Travis CI配置如下:
{
"sudo": "required",
"language": "node_js",
"node_js": "4.1.1",
"before_install": [
"curl -L https://git.io/ejPSng | /bin/sh"
],
"env": "CXX=g++-4.8",
"addons": {
"apt": {
"sources": [
"ubuntu-toolchain-r-test"
],
"packages": [
"g++-4.8"
]
}
},
"services": "mongodb",
"script": [
"meteor npm run lint"
],
"group": "stable",
"dist": "precise",
"os": "linux"
}
.eslintrc
如下:
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"impliedStrict": true
}
},
"env": {
"browser": true,
"node": true,
"mongo": true,
"meteor": true
},
"extends": [
"airbnb"
//"plugin:meteor/recommended"
],
"globals": {
"Thriver": true,
"SimpleSchema": true,
"Marked": true,
"SHA256": true,
"google": true,
"geoXML3": true,
"AutoForm": true,
"details_shim": true
},
"rules": {
"no-underscore-dangle": 0,
"new-cap": 0
}
}
这之前在另一个文件中发生过,我通过让 eslint 忽略该行来“解决”了这个问题。但我不能对每个神秘问题都这样做。有什么建议吗?
最佳答案
http://eslint.org/docs/rules/quotes
这很可能是您问题的解决方案。
JavaScript allows you to define strings in one of three ways: double quotes, single quotes, and backticks (as of ECMAScript 6). For example:
/*eslint-env es6*/
var double = "double";
var single = 'single';
var backtick = `backtick`; // ES6 only
The choice of how to define strings in a codebase is a stylistic one outside of template literals (which allow embedded of expressions to be interpreted). Many codebases require strings to be defined in a consistent manner.
我会尝试设置这些规则之一并再次运行测试。
如果这不能解决您的问题,请告诉我!
关于node.js - Travis CI 中的 eslint 失败,但不是本地的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40901653/