Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 1c5ab20420740a07809c0095636829b25bdca83b 0 parents
@brentlintner brentlintner authored
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "packages/jshint"]
+ path = packages/jshint
+ url = git://github.com/jshint/jshint.git
5 HELP
@@ -0,0 +1,5 @@
+Usage: node-hint path path2 [options]
+
+Options:
+
+ --config custom config file
3  Jakefile
@@ -0,0 +1,3 @@
+task('default', [], require('./build/test'));
+task('test', [], require('./build/test'));
+task('lint', [], require('./build/lint'));
9 LICENSE
@@ -0,0 +1,9 @@
+** Licensed Under **
+
+The MIT License
+http://www.opensource.org/licenses/mit-license.php
+
+Copyright 2010 Brent Lintner
+
+Contributors:
+ Brent Lintner (http://github.com/brentlintner)
32 README.md
@@ -0,0 +1,32 @@
+# node-hint
+
+A command line interface for jshint.
+
+## Install
+
+ npm install node-hint
+
+## Using
+
+ node-hint path path2 [options]
+
+## Options
+
+ --config path/to/config.json
+
+## Running Tests
+
+ npm install sinon nodeunit
+
+## Jake Commands
+
+ // run tests
+ jake test
+
+ // run jshint
+ jake lint
+
+# TODO
+
+* move bulk of code in cli to a separate module and put under test (tdd fail)
+* add custom reporters
2  bin/node-hint
@@ -0,0 +1,2 @@
+#!/usr/bin/env node
+require('./../lib/cli').interpret(process.argv);
8 build/lint.js
@@ -0,0 +1,8 @@
+module.exports = function (files) {
+ var args = files && files.length > 0 ? files : ["build", "test", "lib"],
+ spawn = require('child_process').spawn,
+ cmd = spawn("node-hint", args),
+ sys = require('sys');
+ cmd.stdout.on('data', sys.print);
+ cmd.stderr.on('data', sys.print);
+};
9 build/test.js
@@ -0,0 +1,9 @@
+module.exports = function () {
+ var args = Array.prototype.map.call(arguments, function (test) {
+ return "test/" + test + ".js";
+ }), cmd,
+ sys = require('sys');
+ cmd = require('child_process').spawn("nodeunit", args.length > 0 ? args : ["test/"]);
+ cmd.stdout.on('data', sys.print);
+ cmd.stderr.on('data', sys.print);
+};
88 lib/cli.js
@@ -0,0 +1,88 @@
+// inspired by github.com/tav/nodelint
+var _fs = require('fs'),
+ _sys = require('sys'),
+ _path = require('path'),
+ _jshint = require('./../packages/jshint/jshint.js').JSHINT,
+ _config;
+
+function _collect(path, files) {
+ if (_fs.statSync(path).isDirectory()) {
+ _fs.readdirSync(path).forEach(function (item) {
+ _collect(_path.join(path, item), files);
+ });
+ } else if (path.match(/\.js$/)) {
+ files.push(path);
+ }
+}
+
+function _reporter(results) {
+ var len = results.length,
+ str = '',
+ file, error;
+
+ results.forEach(function (result) {
+ file = result.file;
+ error = result.error;
+ str += file + ': line ' + error.line + ', col ' +
+ error.character + ', ' + error.reason + '\n';
+ });
+
+ _sys.puts(len > 0 ? (str + "\n" + len + ' error' + ((len === 1) ? '' : 's')) : "Lint Free!");
+}
+
+function _lint(file, results) {
+ var buffer;
+
+ try {
+ buffer = _fs.readFileSync(file, 'utf8');
+ } catch (e) {
+ _sys.puts("Error: Cant open: " + file);
+ _sys.puts(e + '\n');
+ }
+
+ if (!_jshint(buffer, _config)) {
+ _jshint.errors.forEach(function (error) {
+ if (error) results.push({file: file, error: error});
+ });
+ }
+}
+
+function _help() {
+ _sys.print(_fs.readFileSync(__dirname + "/../HELP", "utf-8"));
+}
+
+module.exports = {
+ interpret: function (args) {
+ var files = [],
+ results = [],
+ options = require('argsparser').parse(args),
+ customConfig = options["--config"],
+ targets = typeof options.node === "string" ?
+ null : options.node.slice(1);
+
+ if (customConfig) {
+ try {
+ _config = JSON.parse(_fs.readFileSync(customConfig));
+ } catch (e) {
+ _sys.puts("Error opening config file: " + options["--config"]);
+ _sys.puts(e + "\n");
+ process.exit(1);
+ }
+ }
+
+ if (!targets || options["--help"]) {
+ _help();
+ return;
+ }
+
+ targets.forEach(function (target) {
+ _collect(target, files);
+ });
+
+ files.forEach(function (file) {
+ _lint(file, results);
+ });
+
+ _reporter(results);
+ }
+};
27 package.json
@@ -0,0 +1,27 @@
+{
+ "name": "node-hint",
+ "version": "0.1.0",
+ "description": "jshint as a npm package + cli",
+ "homepage": "http://github.com/brentlintner/node-hint",
+ "author": {
+ "name": "Brent Lintner",
+ "email": "brent.lintner@gmail.com",
+ "url": "http://github.com/brentlintner"
+ },
+ "licenses": [{
+ "type": "MIT",
+ "url": "http://www.opensource.org/licenses/mit-license.php"
+ }],
+ "bin": "./bin/node-hint",
+ "main": "./lib",
+ "files": [
+ "packages/jshint/README.markdown",
+ "packages/jshint/jshint.js",
+ "README.md",
+ "LICENSE",
+ "HELP"
+ ],
+ "dependencies": {
+ "argsparser": ">=0.0.3"
+ }
+}
1  packages/jshint
@@ -0,0 +1 @@
+Subproject commit 521230dae2c9ca94b6c6e8047497b2f34dbe5b90
33 test/cli.js
@@ -0,0 +1,33 @@
+var s,
+ sys = require('sys'),
+ cli = require('./../lib/cli');
+
+module.exports = require('nodeunit').testCase({
+
+ setUp: function (done) {
+ s = require('sinon').sandbox.create();
+ done();
+ },
+
+ tearDown: function (done) {
+ s.verifyAndRestore();
+ done();
+ },
+
+ "interprets --help with no args": function (test) {
+ var txt = require('fs').readFileSync(__dirname + "/../HELP", "utf-8");
+ s.mock(sys).expects("print").once().withExactArgs(txt);
+ s.stub(process, "exit");
+ cli.interpret(["node", "file.js"]);
+ test.done();
+ },
+
+ "interprets --help": function (test) {
+ var txt = require('fs').readFileSync(__dirname + "/../HELP", "utf-8");
+ s.mock(sys).expects("print").once().withExactArgs(txt);
+ s.stub(process, "exit");
+ cli.interpret(["node", "file.js", "--help"]);
+ test.done();
+ }
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.