eslint-rails-ee: the more active fork of eslint-rails
Big shoutout to the original authors of this gem, for their awesome contribution to the more JS-leaning Rails devs of the world!
Run ESLint against your Rails repo, and even auto-correct issues! The supported javascript file extensions are the following:
- .js
- .jsx
- .es6
Add this line to your application's Gemfile:
gem 'eslint-rails-ee'
gem 'therubyracer'
gem 'execjs'
This uses TheRubyRacer as a runtime. For most environments, this works fine. However if you run your application on Windows do this to your gemfile:
gem 'eslint-rails-ee'
gem 'therubyracer', :platforms => :ruby
gem 'execjs'
To customize configuration, place an eslint config file in your app's
config/eslint.json
.
You can print the configuration thusly:
# Print the configuration that we're using. If there's a custom configuration
# present, print that; if not, print the default configuration.
rake eslint:print_config
# Or print the default configuration even if a custom one exists.
rake eslint:print_config[true]
You can also retrieve the current eslint.json by visiting /eslint/eslint.json
in your browser. To force retrieval of the default conguration, use
/eslint/eslint.json?force_default=true
.
This will analyze all of the javascript files in the project:
rake eslint:run_all
Or you can run it on a single file. This will analyze application.js
:
rake eslint:run
Or, you can supply a filename to the task, using several different formats, and it will lint just that file. For example, to analyze app/assets/javascripts/components/utilities.js
, you can run any of the following:
rake eslint:run[components/utilities]
rake eslint:run[components/utilities.js]
rake eslint:run[app/assets/javascripts/components/utilities]
rake eslint:run[app/assets/javascripts/components/utilities.js]
To auto-correct files in either execution of the above rake tasks just add true
to the arguments like so:
rake eslint:run_all[true]
or
rake eslint:run[test.js,true]
On non-production environments, visit these URLs on your application:
Path | Description |
---|---|
/eslint |
Optionally supply a filename parameter to analyze a file other than application.js , e.g. /eslint?filename=foo to analyze foo.js. |
/eslint/source?filename=application |
Optionally replace application with the name of another JavaScript file, e.g. eslint/source?filename=button_stuff can show you button_stuff.js , and eslint/source?filename=components/buttons/icon_button can show you components/buttons/icon_button.js.coffee.erb . This returns the source code with syntax highlighting |
/eslint?filename=<path+filename> |
Providing you give a correct path/filename, it will run the eslint report and show you the errors |
/eslint?filename=<path+filename>&should_autocorrect=true |
Same as above, but will report errors AFTER auto-correcting any auto-correct-able issues |
It's easiest to contribute by forking the repo and creating a pull request. For help with this, see this helpful article.
For all of the example shell commands below, I'm going to assume that you've set these two variables, so go ahead and customize these and set them before you start.
ESLINT=~/src/eslint
ESLINT_RAILS=~/src/eslint-rails-ee
git clone https://github.com/DLvalentine/eslint-rails-ee $ESLINT_RAILS
- Clone the ESLint repository
- Install dependencies
- Render
eslint.js
- Copy
eslint.js
intoeslint-rails
- Update the file in git
- Commit, push, and create a pull request
First, make sure you set the environment variables as suggested above.
Clone the ESLint repository
I would recommend only trying this with a released version unless you have a good reason to. In this example, I'm going to check out v1.10.1 and work with that.
git clone https://github.com/eslint/eslint $ESLINT
cd $ESLINT
git checkout v1.10.1
cd $ESLINT
npm install
cd $ESLINT
node Makefile.js browserify
# Assuming you cloned eslint into a repository next to eslint-rails
cp $ESLINT/build/eslint.js $ESLINT_RAILS/vendor/assets/javascripts/eslint.js
cd $ESLINT_RAILS
git add vendor/assets/javascripts/eslint.js
The details of how to create your own branch, commit, push, and create a pull request are outside the scope of this README. If you need help with this part, here's a helpful article. This is the gist.
cd $ESLINT_RAILS
# Make your changes
git add :/
git commit
git push origin master
# Open a pull request
Since the original repo lacked some features I wanted and hasn't seen support/PRs in over a year, I decided to make this repo. Future maintenance of this gem will exist in the new eslint-rails-ee repo:
- David Valentine <[email protected]>
This repo was orignially written by the following people:
- Jon Kessler <[email protected]>
- Justin Force <[email protected]>