I have looked around in Stackoverflow and the ESLint docs for an answer, but most are not what I need since they pertain to React.
I am using Node v14.17.0, and ESLint v7.32.0 as a dev dependency. I have the following piece of code.
class Service {
constructor(){
this.numbers = [1,2,3];
}
doAnotherThing = () => {
console.log("I do the thing after 100 millis", this.numbers);
}
doSomething(){
setTimeout(this.doAnotherThing, 100);
}
}
let service = new Service();
service.doSomething();
Simply running node test.js
runs the application fine and I get the expected result printed to STDOUT.
All sounds good, let me add ESLint and the eslint config file.
{
"env": {
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest"
},
}
Now run when I run eslint on the file, I get the following error.
/test.js
2:10 error Parsing error: Unexpected token =
Keep in mind I am NOT using Babel or any transpiling, so do I need to specify a variable or something in the config? Why is this error happening and why does installing @babel/eslint-parser
solve the issue? I am not using Babel at all. Is this a limit to ESLint or simply something I don't understand?
Using a regular method(){}
does NOT work and is not the solution since I lose the this.number
value. See: https://jsfiddle.net/0crpx6bv
Reading around I see a lot of React and NONE Node.js solutions. This is plain Node without Babel and not in React.