为何 eslint 在 node.js 里对 console.log 显示报错呢?

2018-04-15 21:43:18 +08:00
 ghostgril

我在写一个 node.js 的项目的时候设置了 eslint,但是当我写 console 的时候,他却显示报错,这是怎么回事?虽然运行正常但是就是无法直视红字报错。

还有就是 node.js 现在支持 es6 的写法了吗?

5219 次点击
所在节点    Node.js
7 条回复
noe132
2018-04-15 22:01:27 +08:00
eslint 默认是没有规则的。
你的规则设置了不允许使用 console 语句才会报错。
ghostgril
2018-04-15 22:09:29 +08:00
module.exports = {
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};

我的配置就是这样
ghostgril
2018-04-15 22:09:56 +08:00
@noe132

```
module.exports = {
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};
```
ghostgril
2018-04-15 22:10:29 +08:00
@noe132 == 这个排版有点问题,请问是哪个会导致这种报错呢
yagokoro
2018-04-15 22:11:33 +08:00
建议你去搜一下 eslint 的规则列表,有一条是 noconsole,手动加上改 false 试试(
kslr
2018-04-16 00:37:25 +08:00
zhwithsweet
2018-04-16 08:51:54 +08:00
no-console:0

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/447052

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX