I use grunt + react-tools + jshint to lint the .js files built using react-tools. The output from react-tools is very good about keeping your spacing, indentation, etc, when converting your .jsx to .js, so it gives you an accurate file to lint against.
To setup, install grunt the normal way. Then install the grunt-contrib-watch, react-tools, grunt-react, and grunt-contrib-jshint.
npm install grunt-contrib-watch react-tools grunt-react grunt-contrib-jshint --save-dev
here is a sample grunt file:
'use strict';
module.exports = function (grunt) {
// Project configuration
grunt.initConfig({
// Task configuration
jshint: {
options: {
jshintrc: true,
},
react: {
src: ['react/**/*.js']
}
},
react: {
files: {
expand: true,
cwd: 'react/',
src: ['**/*.jsx'],
dest: 'react/',
ext: '.js'
}
},
watch: {
jsx: {
files: ['react/**/*.jsx'],
tasks: ['react', 'jshint:react']
}
}
});
// These plugins provide necessary tasks
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-react');
// Default task
grunt.registerTask('default', ['react', 'jshint:react']);
};
In this file, running "grunt" will compile your .jsx to .js and then lint the .js files. You can run "grunt watch" to run after every save.
Most of my usual .jshintrc settings work when running this way. I ran into a few issues initially, but most were resolved by making changes in your .jsx files. For exapmle, I have "newcap" set to true. When I followed the React tutorial's naming convention and capitalized the first letter of tags, this threw a lint error. It was fixed by lower-casing the first letter of tags.
I did have to set "trailing": false in my .jshintrc. The resulting .js files have trailing whitespaces where it converts tags to Javascript. I haven't figured out if there is a react-tools configuration to change this. You can use the method described in Dan's post if you don't want to change your .jshintrc.
In addition to linting, this process also helps catch issues with your .jsx to .js conversion.
The issue/downfall with this process is that you can't lint .jsx files in the editor. But keeping a terminal window open that you can see while editing is a helpful replacement. Uing TMUX with Vim and Grunt in different panes is my preferred way to use this.