eslint throws error on arrow function class methods
See original GitHub issueI think I’ve found a bug. According to the es6 spec, class methods are free to use arrow function declarations. However, eslint throws a Parsing error: unexpected token =
when it encounters these methods.
Try the following:
class App{
classMethod = () => { console.log('hi world');}
}
I’ve tried configuring my .eslintrc to cover all the obvious features without success.
{
"ecmaFeatures": {
"modules":true,
"arrowFunctions":true,
"classes":true
},
"env": {
"es6": true
},
}
Edit: I’m using v1.10.3
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:14 (6 by maintainers)
Top Results From Across the Web
How do I configure ESLint to allow fat arrow class methods
What configuration parameter am I missing to enable fat arrow class methods in eslint?
Read more >class-methods-use-this - ESLint - Pluggable JavaScript Linter
This rule is aimed to flag class methods that do not use this . Examples of incorrect code for this rule: /*eslint class-methods-use-this:...
Read more >explicit-function-return-type | typescript-eslint
Require explicit return types on functions and class methods. ... Whether to allow arrow functions that start with the `void` keyword.
Read more >Fixing eslint no-invalid-this error for fat arrow class methods
Fixing eslint no-invalid-this error for fat arrow class methods · npm install these 2 guys: babel-eslint and eslint-plugin-babel · in .eslintrc add plugins:...
Read more >Require space before/after arrow function's arrow (arrow ...
This rule normalize style of spacing before/after an arrow function's arrow( => ). /*eslint-env es6*/ // { "before": true, "after": true } (a) ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Following @mysticatea’s comment, if you are using babel and you still want eslint to work based on that, you can add
to your
eslintrc
file.For somer reason this no longer works for me. Eslint is now throwing an error that a class method as arrow function was used before defined. Anyone else with a similar setup facing this issue?
I also tried changing
parserOptions
to specify newer ECMA versions, to no avail.Not sure if it makes a difference but the project was created with
create-react-app
, which I know does have some babel settings that may have an affect but that should be overridden via my .babelrc I think.I’ve also noticed that a fellow dev on the same project does not see this issue in his VS Code, which is odd because ESLint should be running an identical version from the project’s node modules with the same settings. Any clues there?
.eslintrc
Eslint version
.babelrc