Sha256: 1e8297e3412015aced7b4bf80d697e19fff5865e8c344a2b1e4391c5f060f35e

Contents?: true

Size: 1.78 KB

Versions: 3

Compression:

Stored size: 1.78 KB

Contents

###
  (c) 2010 Geraud Boyer
  Adapted from rhino.js from Douglas Crockford  (www.JSLint.com)

  This is the node companion to fulljslint.js.
###
###global JSLINT
###
###jslint rhino: false, node: true, strict: false
###
###global require,sys,__filename,process
###

((args) ->
  sys = require 'sys'
  fs = require 'fs'
  path = require 'path'

  print_syntax = () ->
    sys.puts 'Usage: jslint.js [options] file.js'
    process.exit 1

  print_syntax() if args.length is 0

  filename = path.join path.dirname(__filename), 'jslint.js'
  JSLINT = fs.readFileSync(filename).toString 'UTF8'
  eval JSLINT

  # Sensible defaults
  options =
    rhino: no, node: no, passfail: no, bitwise: yes, immed: yes, newcap: yes,
    nomen: yes, onevar: yes, plusplus: yes, regexp: yes, undef: yes, white: yes

  input = null
  input_filename = null
  args.forEach (arg, index) ->

    if arg.match /^--no-(\w+)$/
      options[RegExp.$1] = no
    else if arg.match /^--(\w+)=(\S.*)$/
      options[RegExp.$1] = JSON.parse(RegExp.$2)
    else if arg.match /^--(\w+)$/
      options[RegExp.$1] = yes
    else
      input_filename = arg
      input = fs.readFileSync input_filename
      if not input
        sys.puts "jslint: Couldn't open file '#{input_filename}'."
        process.exit 1
      else
        # sys.debug('opening input');
        input = input.toString 'UTF8'
    return

  print_syntax() if not input

  if not JSLINT input, options
    JSLINT.errors.forEach (error) ->
      if error
        sys.puts "Lint at line #{error.line} character #{error.character}: #{error.reason}"
        sys.puts (error.evidence or '').replace /^\s*(\S*(\s+\S+)*)\s*$/, "$1"
        sys.puts ''
    process.exit 2
  else
    sys.puts "jslint: No problems found in #{input_filename}"
    process.exit 0

  return
) process.ARGV.slice 2

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jslint-1.1.2 jslint/node.coffee
jslint-1.1.1 jslint/node.coffee
jslint-1.1.0 jslint/node.coffee