"unexpected console statement no-console"
Asked Answered
U

6

12

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);
Upwards answered 1/6, 2019 at 19:53 Comment(4)
Why are you opening JS files?Shackelford
For the sake of editing them of course.Upwards
Is it an error or a warning? Often no-console is a warning.Rotenone
It's an error. And it disrupts all the code and representation of it in a browser console.Upwards
R
23

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);
Rotenone answered 1/6, 2019 at 20:12 Comment(8)
How? 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.Upwards
If 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.Rotenone
The 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?Rotenone
Yes 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);Upwards
Are you using any sort of a transpiler on this code? For console to not be defined is extremely strange.Rotenone
No. 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.Upwards
I wish I could say.... I don't understand the whole project well enough to see. But I'm glad you got it working.Rotenone
I appreciate that. I wish I could have helped more.Rotenone
G
8

Just add "no-console": 0 to the rules part of .eslintrc.js file.

E.g.

"rules": {
    "no-console": 0
},
Gametogenesis answered 31/10, 2019 at 23:26 Comment(0)
W
5

Add the following to your .eslintrc.js file

"no-console": ["error", { "allow": ["warn", "error"] }]
Wallin answered 30/1, 2020 at 12:25 Comment(1)
How would that look in a yaml file? The following does not work. yaml no-console: - error - allow - warn - error Pappy
A
2

Install the "brackets-eslint" extension and reload your Brackets editor

img1

Alyworth answered 21/6, 2020 at 9:51 Comment(0)
A
-2

Please try to change console.log to document.write

and then open your html file in browser

var now = 2018;
var yearJohn = 1989;
var fullAge = 18;

//Multiple operators
var isFullAge = now - yearJohn >= fullAge; //true
document.write(isFullAge);

//Grouping

var ageJohn = now - yearJohn;
var ageMark = 35;
var average = (ageJohn + ageMark)/2;
document.write(average);

// Multiple assigments
var x, y;
x = y = (3 + 5) * 4 - 6; // 8 * 4 - 6 // 32 - 6 // 26

document.write(x, y);

// More operators
x *= 2;
document.write(x);
x += 10;
// eslint-disable-next-line no-console
document.write(x);
Assonance answered 2/6, 2019 at 0:32 Comment(0)
A
-4

Use console.warn(""); instead of console.log

Abbotson answered 29/9, 2021 at 5:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.