"unexpected console statement no-console"
16,555
Solution 1
If it really is ESLint that is causing errors for this change, you can fix it by disabling the rule for that particular line:
// eslint-disable-next-line no-console
console.log(isFullAge);
Solution 2
Just add "no-console": 0
to the rules part of .eslintrc.js file.
E.g.
"rules": {
"no-console": 0
},
Solution 3
Add the following to your .eslintrc.js
file
"no-console": ["error", { "allow": ["warn", "error"] }]
Author by
Segal Pal
Updated on June 15, 2022Comments
-
Segal Pal almost 2 years
I'm getting this error in Brackets.
I want to stress the fact that it's literally the second time I opened a JS file. As I stressed It I want also to emphasize the fact that I have no clue what Eslint and node.js are.
All the fixes on the StackOverflow and other sites assume knowing how abovementioned entities work.
Please help to a complete newb to fix the problem and learn something new.
Thank you in advance!
Here's the piece of code, but I don't think it will help with anything.
Html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript</title> </head> <body> <h1>Javascript starter</h1> <script src=Script.js> </script> </body> </html>
Javascript:
var now = 2018; var yearJohn = 1989; var fullAge = 18; //Multiple operators var isFullAge = now - yearJohn >= fullAge; //true сonsole.log(isFullAge); //Grouping var ageJohn = now - yearJohn; var ageMark = 35; var average = (ageJohn + ageMark)/2; console.log(average); // Multiple assigments var x, y; x = y = (3 + 5) * 4 - 6; // 8 * 4 - 6 // 32 - 6 // 26 console.log(x, y); // More operators x *= 2; console.log(x); x += 10; // eslint-disable-next-line no-console console.log(x);
-
Segal Pal almost 5 yearsHow? If I add the line without comment tag it does nothing. If I add the line with the comment tag it obviously does nothing. Why the code worked the first time I created the file and it doesn't now? Why in every single tutorial for beginners there's no such a thing as disabling this rule? All these questions might sound obvious or dead-stupid, but I just don't get it.
-
Dr_Derp almost 5 yearsIf you add the line with the comment tag it won't disable the line, it will just tell eslint to not run the given rule for that line. You might need to post the entire file in the question, so we have better understanding of the whole context. Some tutorials for beginners tackle ESLint but many do not, which is why, I suspect, you haven't seen this before. Also disabling a lint rule is not something that's generally encouraged, since it tends to result in code that doesn't conform to the standard.
-
Dr_Derp almost 5 yearsThe javascript file is called Script.js? And it is located in the same folder as the HTML? Are you getting any errors in your browser console when you load this file? Any errors in the network tab?
-
Segal Pal almost 5 yearsYes it is. I closed the folder in an editor and opened it up again. As a result, the error in Brackets disappeared but the browser console gives me this now "Uncaught ReferenceError: сonsole is not defined at Script.js:89" the line 89 correlates with сonsole.log(isFullAge);
-
Dr_Derp almost 5 yearsAre you using any sort of a transpiler on this code? For console to not be defined is extremely strange.
-
Segal Pal almost 5 yearsNo. There was a mistake. The variable called fullAge. But I use isFullAge. But. It was giving me the same mistake after I fix it until I just delete and inserted the console.log(isFullAge) a few times. What's sort of alchemy is this. And still, I haven't figured out what caused the problem I've described in the topic and how I fixed it.
-
Dr_Derp almost 5 yearsI wish I could say.... I don't understand the whole project well enough to see. But I'm glad you got it working.
-
Dr_Derp almost 5 yearsI appreciate that. I wish I could have helped more.
-
Corné over 2 yearsHow would that look in a yaml file? The following does not work.
yaml no-console: - error - allow - warn - error