Setting up Vim for React.js

Original blog: https://jaxbot.me/articles/setting-up-vim-for-react-js-jsx-02-03-2015

React.js is gaining a lot of traction lately, but developing with its inline-XML-in-JS requires a few tweaks to Vim for a smooth experience.

Syntax highlighting

To get the syntax highlighting to look right, use mxw’s Vim JSX highlighting.

If you use Vundle, add:

Plugin 'mxw/vim-jsx'

Other plugin loaders, see the GitHub page.

If you use JSX syntax in .js files, which is now becoming standard, add:

let g:jsx_ext_required = 0 " Allow JSX in normal JS files

to your vimrc.

Syntax checking

If you use Syntastic, you’ll notice immediate errors wherever XML nodes appear, which is to be expected. Here’s a work around.

Update 3/30/15: I’ve added instructions on using ESLint instead of the old wrapper package.

Install eslint, babel-eslint (for ES6 support), and eslint-plugin-react:

npm install -g eslint
npm install -g babel-eslint
npm install -g eslint-plugin-react

Create a config like this in your project’s .eslintrc, or do so globally by placing it in ~/.eslintrc:

{
    "parser": "babel-eslint",
    "env": {
        "browser": true,
        "node": true
    },
    "settings": {
        "ecmascript": 6,
        "jsx": true
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "strict": 0,
        "quotes": 0,
        "no-unused-vars": 0,
        "camelcase": 0,
        "no-underscore-dangle": 0
    }
}

Finally, configure Syntastic to use ESLint:

let g:syntastic_javascript_checkers = ['eslint']

You should be good to go, and JSX with ES6 features will syntax check correctly! See this issue for more info.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值