Skip to content

isabella232/eslintrb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Ruby gem for eslint

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.6%
  • Ruby 0.4%