Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade babel-eslint to resolve template strings bug #3

Open
cnrudd opened this issue Oct 27, 2020 · 2 comments
Open

Upgrade babel-eslint to resolve template strings bug #3

cnrudd opened this issue Oct 27, 2020 · 2 comments

Comments

@cnrudd
Copy link
Member

cnrudd commented Oct 27, 2020

A client developer is seeing this eslint error when running yarn lint:

$yarn lint
yarn run v1.22.10
$ yarn lint:js
$ eslint --ext .js,.jsx .
TypeError: Cannot read property 'range' of null
Occurred while linting xyz.jsx:1

The bug is triggered by a template string in a loop preceded by an optional chaining operator. This error prevents teamcity builds from succeeding as well.

The bug is reproduced in this toolbox branch:
https://github.com/xh/toolbox/tree/babel-eslint-bug

This issue is discussed extensively here:
babel/babel-eslint#799

The issue in the project can be resolved by not using an optional chaining operator in that jsx file, but
it might be worth seeing if the issue can be resolved by migrating from
use of
parser: 'babel-eslint',
to
parser: "@babel/eslint-parser"
in this project's (eslint-config) index.js file

as is described here:
https://babeljs.io/blog/2020/07/13/the-state-of-babel-eslint

@cnrudd
Copy link
Member Author

cnrudd commented Oct 31, 2020

This branch https://github.com/xh/eslint-config/tree/eslintUpgradeAndBugfix demonstrates that upgrading to @babel/eslint-parser fixes the bug. Run it against this toolbox branch https://github.com/xh/toolbox/tree/babel-eslint-bug to test (after having linked @xh/eslint-config with yarn link in this project & yarn link "@xh/eslint-config"in the toolbox client-app project.

But, @babel/eslint-parser comes with a pretty big new requirement: it must have a babel config file.
Our current babel config is inside our @xh/hoist-dev-utils project's configureWebpack.js file.
I ended up copying what I felt were the bits relevant for linting in a new babel.config.js file in @xh/eslint-config.

There may be a way to DRY this up, perhaps by having the configureWebpack.js import the @xh/eslint-config babel.config.js into its babel-loader section, and merge it with the bits of the babel config that have more to do with targeting and bundling.
But I thought some discussion would be better before spending time on that.

@mahenzon
Copy link

mahenzon commented Dec 28, 2020

Started to happen for me too :(

Problem with ESLint reformatting:
File.vue: TypeError: Cannot read property 'range' of null

but upgrading to @babel/eslint-parser helped me! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants