0.01
No commit activity in last 3 years
No release in over 3 years
A Rails wrapper for ESLint
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0

Runtime

 Project Readme

Gem Version RamenBless

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

Installation

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'

Configuration

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.

Usage

CLI

rake-eslint-rails-run

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]

Web interface

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

eslint-rails-web

eslint-rails-web-source

Contributing

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

Cloning the repository

git clone https://github.com/DLvalentine/eslint-rails-ee $ESLINT_RAILS

Updating ESLint version

Summary

  1. Clone the ESLint repository
  2. Install dependencies
  3. Render eslint.js
  4. Copy eslint.js into eslint-rails
  5. Update the file in git
  6. Commit, push, and create a pull request

Step-by-step instructions

First, make sure you set the environment variables as suggested above.

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

Install dependencies

cd $ESLINT
npm install

Render eslint.js

cd $ESLINT
node Makefile.js browserify

Copy eslint.js into eslint-rails

# Assuming you cloned eslint into a repository next to eslint-rails
cp $ESLINT/build/eslint.js $ESLINT_RAILS/vendor/assets/javascripts/eslint.js

Update the file in git

cd $ESLINT_RAILS
git add vendor/assets/javascripts/eslint.js

Commit, push, and create a pull request

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

Fork Authors

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:

Original Authors

This repo was orignially written by the following people:

License

MIT License.