error: Unexpected console statement (no-console)

最讨厌这些繁文缛节,去看 eslint 的官方破网站的解释:

https://eslint.org/docs/rules/no-console

In JavaScript that is designed to be executed in the browser, it’s considered a best practice to avoid using methods on console. Such messages are considered to be for debugging purposes and therefore not suitable to ship to the client. In general, calls using console should be stripped before being pushed to production.

意思就是:js 这玩意儿是在浏览器用的,你搞些 console.log 和用户没关系,你别写 console.log 了。不过有趣的是,eslint 的官方 repo 中却大把大把地写 console.log (https://github.com/eslint/eslint/search?q=console.log&unscoped_q=console.log

那我怎么办??它给的建议是:

// custom console
Console.log("Hello world!");

自己写一个 console。这?有病吧?

解决方法:禁用 eslint,或者禁用这一条规则。

...
"eslintConfig": {
    ...
    "rules": {
      "no-console": "off"
    },
    ...

发表留言

本站启用了垃圾评论检测插件,如果误删请联系我~