如何在 Atom 编辑器上为 React 配置 ESLint [英] How to config ESLint for React on Atom Editor
问题描述
在 Atom Editor 中我安装了以下插件
In Atom Editor I installed the following plugins
- 棉绒
- linter-eslint
他们似乎不认识 JSX 语法.
It seems they don't recognize the JSX syntaxis.
我让它在命令行上工作,但不得不使用其他插件,如 esprima-fb
和 eslint-plugin-react
.看起来 Atom Editor 没有这样的插件,想知道你们中是否有人知道解决这个问题的方法.
I have it working on the command line but had to use other plugins like esprima-fb
and eslint-plugin-react
. Looks like there are no such plugins for Atom Editor and would like to know if anyone of you knows a way to hack around this.
推荐答案
为了让 Eslint 与 React.js 很好地工作:
To get Eslint working nicely with React.js:
- 安装 linter &linter-eslint 插件
- 运行
npm install eslint-plugin-react
- 将
"plugins": ["react"]
添加到您的 .eslintrc 配置文件中 - 将
"ecmaFeatures": {"jsx": true}
添加到您的 .eslintrc 配置文件
- Install linter & linter-eslint plugins
- Run
npm install eslint-plugin-react
- Add
"plugins": ["react"]
to your .eslintrc config file - Add
"ecmaFeatures": {"jsx": true}
to your .eslintrc config file
这是一个 .eslintrc
配置文件的例子:
Here is an example of a .eslintrc
config file:
{
"env": {
"browser": true,
"node": true
},
"globals": {
"React": true
},
"ecmaFeatures": {
"jsx": true
},
"plugins": [
"react"
]
}
我目前使用的是 Eslint v1.1.0.
I am using Eslint v1.1.0 at the moment.
附注:我必须同时安装 eslint 和 eslint-plugin-react 作为项目依赖项(例如,npm install eslint eslint-plugin-react --save-dev
).希望这会有所帮助.
Side note:
I had to install both eslint and eslint-plugin-react as project dependencies (e.g., npm install eslint eslint-plugin-react --save-dev
). Hopefully this helps.
这篇关于如何在 Atom 编辑器上为 React 配置 ESLint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!