简体   繁体   中英

Eslint disable no console not working

I am trying to log to console something by disabling the no console rule in eslint like this:

// eslint-disable-next-line no-console
console.log(props.hasSubmittedForm);

But, I get an error:

Module build failed

unexpected token

For the dot the console.log. Why can't I log to the console like that?

You can wrap your code with /* eslint-disable no-console */ in order to disable eslint just for that part:

/* eslint-disable no-console */
console.log(props.hasSubmittedForm);
/* eslint-enable no-console */

Interestingly for me when I switch from eslint-disable-next-line to eslint-disable I have to also change the comment from // to /* */ .

This didn't work:

// eslint-disable no-console

This worked:

/* eslint-disable no-console */

Perhaps you didn't stage the eslint-disable... change? My code failed running the pre-commit hook, after staging the eslint-disable... change, it passed the hook.

Instead of wrapping (which is using two lines), or disable the whole file, you can simply use above the concerned line:

// eslint-disable-next-line no-console
console.log("I am ignored");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM