> For the complete documentation index, see [llms.txt](https://notes.lirenxn.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.lirenxn.com/2020/notes-04-05-eslint-and-babel.md).

# Notes-04-05-eslint-and-babel

### Eslint <a href="#eslint" id="eslint"></a>

* add `env` entry for different global environment variables, and module system
* add for each rule, basic switches are `off`, `warn` issue with `exit(0)` , `error` issue with `exit(1)`

**How eslint deal with jsx**

1. `parserOptions.ecmaFeatures.jsx: true`, parser(**espree**) will parse `jsx` to `JSXIdentifier` Node in `ast`
2. `react/react-in-jsx-scope` rule used to check: when there is jsx in file, there should be a `React` in 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

1. `react/react-in-jsx-scope` can be worked around with [**jsx pragma**](https://github.com/yannickcr/eslint-plugin-react/blob/80f3826dd854796d25244ad34782b9147b90db1d/lib/util/pragma.js#L45), it can be added as `/** jsx NewReact.createEl */`, or add pragma as [shared settings](https://eslint.org/docs/user-guide/configuring#adding-shared-settings)
2. In `preact`, the recommended way is to use `alias` in bundler(webpack/parcel/browersify), and the `jsx` code can easily share same support with react **before bundle**.
3. Use `babel-eslint >= v11.x` and use a shared `.babelrc`

### Babel <a href="#babel" id="babel"></a>

> For compatibility reasons, `.babelrc` is 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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://notes.lirenxn.com/2020/notes-04-05-eslint-and-babel.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
