eslint with jsx
How eslint deal with jsx
parserOptions.ecmaFeatures.jsx: true, parser(espree) will parsejsxtoJSXIdentifierNode inastreact/react-in-jsx-scoperule used to check: when there is jsx in file, there should be aReactin variable
Gotchas
Til now (Apr-05-2020), eslint does not deal with jsx in a parsed way. That been said, eslint treat jsx as raw jsx syntax, and use react/react-in-jsx-scope to trick the way around to check if React exist.
The proper way, as babel did, parsing jsx to React.createElement(), providing proper/standard variable referencing, is not supported by babel-eslint <= v10.x. Since it parse the code with a set of default opts, without being able to access the project's .babalrc config file.
Tricky part is, github default page for babel-eslint is actually for UNRELEASED v11.x, in which a new config field parserOption.babelOptions is added. With babel changed to a peerDep and external parse config.
This ensures that the same Babel configuration is used during both linting and compilation.
To enable different jsx transpiler for eslint, there are 3 ways
react/react-in-jsx-scopecan be worked around with jsx pragma, it can be added as/** jsx Preact.createEl */, or add pragma as shared settingsIn
preact, the recommended way is to usealiasin bundler(webpack/parcel/browersify), andjsxcan easily share same support with react before bundle.Use
babel-eslint >= v11.xand use a shared.babelrc
Last updated
Was this helpful?