jaxbot / syntastic-react

React.js JSX support for Syntastic
93 stars 4 forks source link

Syntastic Checker for React JSX files

New way using ESLint

This project has been deprecated in favor of using ESLint, which supports React, JSX, and new ES6 features, and is in very active development.

To use Syntastic with ESLint:

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! See this issue for more info.

Using this project and JSHint instead

This is a simple wrapper that:

This gives you the power of syntax checking in Vim, without the annoyance of "unexpected regular expression". Awesome.

Syntastic working with JSHint issues Syntastic working with JSX issues

Usage

npm install -g syntastic-react

If you don't have jshint or react-tools, install those too:

npm install -g jshint
npm install -g react-tools

Add these lines to your vimrc:

let g:syntastic_javascript_checkers = ['jsxhint']
let g:syntastic_javascript_jsxhint_exec = 'jsx-jshint-wrapper'

And, of course, install Syntastic.

More info

This is a part of a blog post on setting up Vim for React development.

Why? What about JSXHint?

JSXHint is being sunsetted and doesn't handle React errors correctly. This code is a simple wrapper that brings the best of both worlds, though this one is designed specifically for use with syntastic, and thus will not run the same way as the previous JSXHint wrapper.

JSON support

If you receive an Unexpected token error when editing JSON files, note that Vim defaults to json being ft=javascript. Two main options exist to remedy this:

  1. Use vim-json and get proper JSON highlighting and filetype support.

  2. Override the filetype manually in your vimrc, something like:

au BufRead,BufNewFile *.json set filetype=json
let g:syntastic_json_checkers=['jsonlint']

(Thanks, sharkinsspatial!)

About me

I'm Jonathan, I work on random Vim plugins, web development, Node.js, Android, and whatever else I feel like. Follow me if you're curious, or just want to make my day!