jslint-rb 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,37 @@
1
+ Borne out of a set of Python/Bash scripts I had lugged around for several years. Decided
2
+ to turn into an actual program instead of setting it up on yet another machine.
3
+
4
+ Features:
5
+ * Converted to ruby for easy portability
6
+ * Using ExecJS, so no dependency on a particular JS runtime
7
+ * You can specify a list of globals at the commandline (config file in the future)
8
+ instead of having to update your source code files with ugly /*global x,y,z */
9
+ declarations
10
+ * will also be able to configure multiple formatters easily for use in different environments
11
+ (VIM, RubyMine, Continuous Integration, etc)
12
+
13
+ UPDATE June 15th 2012:
14
+
15
+ Got ExecJS integrated, and enabled the formatting so it will work with VIM.
16
+ Also converted to using JSHint instead of JSLint. General refactoring as well,
17
+ but should be good enough for a general beta release
18
+
19
+ UPDATE June 6th 2012:
20
+
21
+ Created a ruby version of this script. Can be used like this:
22
+
23
+ jslint foo.js [OPTIONS]
24
+
25
+ requires ruby 1.9.x
26
+
27
+ This version is missing the pretty formatting for use with VIM/Emacs, but that should be added
28
+ soon.
29
+
30
+ TODO:
31
+
32
+ 1. Make a task to pull the latest version of JSHint
33
+ 2. Test with MacVim
34
+ 3. Allow the specification of formatters at the command line
35
+ 4. Allow the spec of Globals from the commandline
36
+ 5. Allow configuration via a YAML file in the users home directory, so that you
37
+ don't have to input the same commandline options each time
data/bin/jslint-rb ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require File.expand_path("../lib/jslint-rb.rb", File.dirname(__FILE__))
5
+
6
+ config = JslintRb::OptionParser.new
7
+
8
+ instance = JslintRb::Runner.new(config.filename, config.options)
9
+ output = instance.execute
10
+
11
+ formatter = JslintRb::Formatter.new(JslintRb::Formatter::VIM)
12
+
13
+ formatter.print(output, config.filename)
@@ -0,0 +1,13 @@
1
+ module JslintRb
2
+ class Error
3
+ attr_reader :line_number, :character, :reason, :evidence
4
+
5
+ def initialize(jsobject)
6
+ @line_number = jsobject["line"]
7
+ @character = jsobject["character"]
8
+ @reason = jsobject["reason"]
9
+ @evidence = jsobject["evidence"]
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ module JslintRb
2
+ ##
3
+ #Formatters are used to parse the output from Lint and
4
+ #transform it for use with other programs (or simply to
5
+ #customize the output)
6
+ class Formatter
7
+
8
+ ##
9
+ #Formatter for use with VIM's :make command. Set your errorformat
10
+ #for JS files to '%f:%l:%c:%m' and it will work flawlessly with
11
+ #:cope
12
+ VIM = Proc.new do |errors, filename|
13
+ results = []
14
+ errors.each do |error|
15
+ results << "#{filename}:#{error.line_number}:"\
16
+ "#{error.character}:#{error.reason} -- #{error.evidence.strip}"
17
+ end
18
+ results
19
+ end
20
+
21
+ def initialize(formatter)
22
+ @command = formatter
23
+ end
24
+
25
+
26
+ def print(errors, filename)
27
+ output = @command.call(errors, filename)
28
+ puts output
29
+ end
30
+
31
+ end
32
+ end
33
+