Console.log error in Brackets

巧了我就是萌 提交于 2019-12-13 17:37:44

问题


Every time i try to use console.log i get this kind of error.

ERROR: Unexpected console statement. [no-console] console.log(name + ' is a ' + age + ' years old ' + job + ' who is married ' + isMarried + ' . '); 36 ERROR: 'console' is not defined. [no-undef] console.log(name + ' is a ' + age + ' years old ' + job + ' who is married ' + isMarried + ' . '); 44 ERROR: Unexpected console statement. [no-console] console.log(name + ' is a ' + age + ' years old ' + job + ' who is married ' + isMarried + ' . '); 44 ERROR: 'console' is not defined. [no-undef] console.log(name + ' is a ' + age + ' years old ' + job + ' who is married ' + isMarried + ' . ');

What will be the error on this lines

Error Screenshot Here


回答1:


After looking at the console error i see that this is related to the ESLint so to prevent ESLint rules on console at global level you can add this rule on rules object of your .eslintrc.json

"rules": {
    ...,
    "no-console": ["warning"],
    ...
} 

Or for specific line of console you can use /*eslint-disable*/ just above that line, like this

/*eslint-disable*/
console.log('some text'); 

/*eslint-enable*/     //this will now enable eslint rules that follows this



回答2:


It's a ESlint error for not using console.

You can disable it by changing this rule.

For specific line you can disable it with a comment:

console.log('test') // eslint-disable-line no-console

For the next line, it can be disabled with comment:

// eslint-disable-next-line no-console



回答3:


If you don't want to make change to .eslintrc file then add these two lines to disable it completely in the whole .js file:

/*global console*/ /* eslint no-console: "off" */




回答4:


You can also change the default by going to the Brackets extension manager and scrolling down to ESLint and disable there for all files.

extension manager button

extensions window with disable button



来源:https://stackoverflow.com/questions/48124988/console-log-error-in-brackets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!