jslint-rb 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/GPL-3-LICENSE +674 -0
- data/README +37 -0
- data/bin/jslint-rb +13 -0
- data/lib/jslint-rb/error.rb +13 -0
- data/lib/jslint-rb/formatter.rb +33 -0
- data/lib/jslint-rb/js/jshint.js +4551 -0
- data/lib/jslint-rb/js/jslint.js +538 -0
- data/lib/jslint-rb/option_parser.rb +74 -0
- data/lib/jslint-rb/runner.rb +40 -0
- data/lib/jslint-rb.rb +8 -0
- metadata +87 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
module JslintRb
|
2
|
+
##
|
3
|
+
#Not sure what to call this class, but it basically parses
|
4
|
+
#the commandline args and puts them in instance vars. pass -h to
|
5
|
+
#see a list of valid command line opts
|
6
|
+
class OptionParser
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
attr_reader :options
|
10
|
+
attr_reader :filename
|
11
|
+
|
12
|
+
##
|
13
|
+
#These are just some defaults that I wanted.
|
14
|
+
#Part of the fun in writing software is imposing your
|
15
|
+
#opinions on people.
|
16
|
+
DEFAULT_OPT =
|
17
|
+
{ white: false,
|
18
|
+
undef: true,
|
19
|
+
bitwise: true,
|
20
|
+
onevar: true,
|
21
|
+
curly: true,
|
22
|
+
latedef: true,
|
23
|
+
newcap: true,
|
24
|
+
noarg: true,
|
25
|
+
trailing: true,
|
26
|
+
eqeqeq: true,
|
27
|
+
eqnull: true
|
28
|
+
}
|
29
|
+
|
30
|
+
def initialize
|
31
|
+
@filename = ARGV[0]
|
32
|
+
|
33
|
+
@options = {
|
34
|
+
#Location of the jslint.js file
|
35
|
+
lint_location: File.expand_path("js/jshint.js", File.dirname(__FILE__)),
|
36
|
+
#tempfile location; make sure it's writable by your user
|
37
|
+
temp_file: 'jslint_wrap.tmp',
|
38
|
+
#this is passed to JSLint so that it will not falsely call
|
39
|
+
#an undefined error on them
|
40
|
+
global_vars: "Ext,console,Compass,currentUser",
|
41
|
+
#A hash of JSHINT options
|
42
|
+
lint_options: {}
|
43
|
+
#default_options: ['white: false', 'nomen: false', 'undef: true']
|
44
|
+
}
|
45
|
+
|
46
|
+
ARGV.options do |opt|
|
47
|
+
opt.banner = "Usage: jslint-rb [FILENAME] [OPTIONS]"
|
48
|
+
|
49
|
+
opt.on('-o', "--options ['OPTIONNAME : VALUE',]", Array,
|
50
|
+
"List of JsHint options. "\
|
51
|
+
"Passing default : true will "\
|
52
|
+
"enable default options") do |options|
|
53
|
+
|
54
|
+
options.each do |lint_opt|
|
55
|
+
key,value = lint_opt.split(':')
|
56
|
+
if key == 'default'
|
57
|
+
@options[:lint_options].merge!(DEFAULT_OPT)
|
58
|
+
else
|
59
|
+
@options[:lint_options][key] = value
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
opt.on_tail("-h", "--help", 'Show this message') do
|
65
|
+
puts opt
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
opt.parse!
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module JslintRb
|
2
|
+
##
|
3
|
+
#The main ruby file that you call to run JSLint
|
4
|
+
#It is setup with some default options, that you will
|
5
|
+
#have to edit the class to override. Once I turn this
|
6
|
+
#into a gem, you'll be able to set these by config file
|
7
|
+
#or command line options.
|
8
|
+
class Runner
|
9
|
+
require 'execjs'
|
10
|
+
require 'multi_json'
|
11
|
+
|
12
|
+
def initialize(filename, options)
|
13
|
+
@filename = filename
|
14
|
+
@config = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute
|
18
|
+
set_globals
|
19
|
+
context = ExecJS.compile(File.read(@config[:lint_location]))
|
20
|
+
output = context.exec("JSHINT(#{MultiJson.dump(File.read(@config[:temp_file]))},"\
|
21
|
+
"#{MultiJson.dump(@config[:lint_options])});"\
|
22
|
+
"return JSHINT.errors")
|
23
|
+
output.compact.map {|x| JslintRb::Error.new(x) }
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
#This prepends a list of globals to the file you're working on.
|
28
|
+
#Saves it off to the location defined by @config[:temp_file]
|
29
|
+
def set_globals
|
30
|
+
f = File.open(@filename, 'r')
|
31
|
+
contents = "/*global #{@config[:global_vars]} */ #{f.read}"
|
32
|
+
f.close
|
33
|
+
|
34
|
+
tmp_file_handle = File.open(@config[:temp_file], "w")
|
35
|
+
tmp_file_handle.write(contents)
|
36
|
+
tmp_file_handle.close()
|
37
|
+
end
|
38
|
+
|
39
|
+
end#Runner
|
40
|
+
end#JslintRb
|
data/lib/jslint-rb.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
module JslintRb end
|
2
|
+
|
3
|
+
#require "jslint-rb/runner"
|
4
|
+
require File.expand_path("jslint-rb/runner", File.dirname(__FILE__))
|
5
|
+
require File.expand_path("jslint-rb/formatter", File.dirname(__FILE__))
|
6
|
+
require File.expand_path("jslint-rb/option_parser", File.dirname(__FILE__))
|
7
|
+
require File.expand_path("jslint-rb/error", File.dirname(__FILE__))
|
8
|
+
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jslint-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Brodt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: execjs
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.3.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.3.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multi_json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.3.6
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.3.6
|
46
|
+
description: Ruby wrapper for JSHint, using execJS
|
47
|
+
email: chris@uberbrodt.net
|
48
|
+
executables:
|
49
|
+
- jslint-rb
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- bin/jslint-rb
|
54
|
+
- lib/jslint-rb/runner.rb
|
55
|
+
- lib/jslint-rb/error.rb
|
56
|
+
- lib/jslint-rb/option_parser.rb
|
57
|
+
- lib/jslint-rb/js/jslint.js
|
58
|
+
- lib/jslint-rb/js/jshint.js
|
59
|
+
- lib/jslint-rb/formatter.rb
|
60
|
+
- lib/jslint-rb.rb
|
61
|
+
- README
|
62
|
+
- GPL-3-LICENSE
|
63
|
+
homepage: https://github.com/uberbrodt/jslint-rb
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.23
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Ruby wrapper to run and format JSLint, using execJS
|
87
|
+
test_files: []
|