如何在 Atom 编辑器上为 React 配置 ESLint [英] How to config ESLint for React on Atom Editor

查看:38
本文介绍了如何在 Atom 编辑器上为 React 配置 ESLint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Atom Editor 中我安装了以下插件

In Atom Editor I installed the following plugins

  1. 棉绒
  2. linter-eslint

他们似乎不认识 JSX 语法.

It seems they don't recognize the JSX syntaxis.

我让它在命令行上工作,但不得不使用其他插件,如 esprima-fbeslint-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:

  1. 安装 linter &linter-eslint 插件
  2. 运行 npm install eslint-plugin-react
  3. "plugins": ["react"] 添加到您的 .eslintrc 配置文件中
  4. "ecmaFeatures": {"jsx": true} 添加到您的 .eslintrc 配置文件
  1. Install linter & linter-eslint plugins
  2. Run npm install eslint-plugin-react
  3. Add "plugins": ["react"] to your .eslintrc config file
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆