Project

eslintrb

0.02
Repository is archived
No release in over 3 years
Low commit activity in last 3 years
Ruby wrapper for ESLint. Uses ExecJS
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0.0.3

Runtime

>= 0
>= 0
 Project Readme

eslintrb

Build Status

Forked from jshintrb who did all the hard work.

Ruby wrapper for ESLint. The main difference from eslint it does not depend on Java. Instead it uses ExecJS.

Installation

eslintrb is available as ruby gem.

$ gem install eslintrb

Ensure that your environment has a JavaScript interpreter supported by ExecJS. Usually, installing therubyracer gem is the best alternative.

Usage

require 'eslintrb'

Eslintrb.lint(File.read("source.js"), :defaults)
# => array of warnings

Eslintrb.report(File.read("source.js"), :defaults)
# => string

Or you can use it with rake

require "eslintrb/eslinttask"
Eslintrb::EslintTask.new :eslint do |t|
  t.pattern = 'javascript/**/*.js'
  t.options = :defaults
end

When initializing eslintrb, you can pass an options Hash.

Eslintrb::Lint.new('no-undef' => true).lint(source)
# Or
Eslintrb.lint(source, 'no-undef' => true)

List of all available options

If you pass :defaults as option, it is the same as if you pass the following options Hash.

options =
  {
    rules: {
      'no-bitwise' => 2,
      'curly' => 2,
      'eqeqeq' => 2,
      'guard-for-in' => 2,
      'no-use-before-define' => 2,
      'no-caller' => 2,
      'no-new-func' => 2,
      'no-plusplus' => 2,
      'no-undef' => 2,
      'strict' => 2
    },
    env: {
      'browser' => true
    }
  }

Eslintrb.lint(source, options)

# Or

Eslintrb.lint(source, :defaults)

If you have a JSON .eslintrc file at the current directory you can pass :eslintrc as option and the file will be parsed. The resulting Hash will be used as options.

// ./.eslintrc
{
  "rules": {
    "no-bitwise":  2,
    "curly":  2,
    "eqeqeq":  2,
    "guard-for-in":  2,
    "no-use-before-define":  2,
    "no-caller":  2,
    "no-new-func":  2,
    "no-plusplus":  2,
    "no-undef":  2,
    "strict":  2
  },
  "env": {
    "browser":  true
  }
}
Eslintrb.lint(source, :eslintrc)

TODO