- 
      
- 
        Save ammonkc/1094266 to your computer and use it in GitHub Desktop. 
    JS: JSHint through NodeJS
  
        
  
    
      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 node | |
| /* | |
| * Takes a list of files and runs them through JSHint | |
| * | |
| * Usage: | |
| * check.js file1 file2 file3 | |
| */ | |
| var fs = require('fs'), | |
| jshint = require('./jshint').JSHINT, | |
| files = []; | |
| // Get list of files | |
| process.argv.forEach(function(val, index, array) { | |
| files.push(val); | |
| }); | |
| console.log('-----------------------------------------'); | |
| for(var i=2;i<files.length;i++) { | |
| fs.readFile(files[i], function(err, data) { | |
| if(err) { | |
| console.log('Error: ' + err); | |
| return; | |
| } | |
| if(jshint(data.toString())) { | |
| console.log('File ' + files[i] + ' has no errors. Congrats!'); | |
| } else { | |
| console.log('Errors in file ' + files[i]); | |
| console.log(''); | |
| var out = jshint.data(), | |
| errors = out.errors; | |
| for(var j=0;j<errors.length;j++) { | |
| console.log(errors[j].line + ':' + errors[j].character + ' -> ' + errors[j].reason + ' -> ' + errors[j].evidence); | |
| } | |
| // List globals | |
| console.log(''); | |
| console.log('Globals: '); | |
| for(j=0;j<out.globals.length;j++) { | |
| console.log(' ' + out.globals[j]); | |
| } | |
| } | |
| console.log('-----------------------------------------'); | |
| }); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment