Notes-04-05-eslint-and-babel
Eslint
add
enventry for different global environment variables, and module systemadd for each rule, basic switches are
off,warnissue withexit(0),errorissue withexit(1)
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(04-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-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 NewReact.createEl */, or add pragma as shared settingsIn
preact, the recommended way is to usealiasin bundler(webpack/parcel/browersify), and thejsxcode can easily share same support with react before bundle.Use
babel-eslint >= v11.xand use a shared.babelrc
Babel
For compatibility reasons,
.babelrcis an alias for.babelrc.json
Use babel.config.js is a recommended way to do config cos it's more flexible, while cache is harder so explicit api.cache() setup is forced
Last updated
Was this helpful?