Last active
August 29, 2015 14:04
-
-
Save lowjoel/2916e2fb61a2b2bcbcfe to your computer and use it in GitHub Desktop.
Running JSHint from the command line without rake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'jshint' | |
require 'jshint/reporters' | |
reporter_name = ARGV[0] || :Default | |
file = ARGV[1] | |
linter = Jshint::Lint.new | |
linter.lint | |
reporter = Jshint::Reporters.const_get(reporter_name).new(linter.errors) | |
printer = lambda do |stream| | |
stream.puts reporter.report | |
end | |
if file | |
FileUtils.mkpath(File.dirname(file)) | |
File.open(file, 'w') do |stream| | |
printer.call(stream) | |
end | |
else | |
printer.call($stdout) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment