Permalink
Browse files

* 0.1.1 corrections (executable does not work in npm)

  • Loading branch information...
1 parent ae6f5c7 commit 5e9f85506038569ebe206f07d92db75b6e6d8592 Julien Polo committed Nov 29, 2010
Showing with 228 additions and 113 deletions.
  1. +123 −12 bin/node-lint
  2. +101 −99 lib/lint/formatter.js
  3. +2 −1 lib/lint/index.js
  4. +2 −1 package.json
View
@@ -1,18 +1,129 @@
-#! /bin/sh
+#!/usr/bin/env node
+var path = require('path');
-__DIR__=`dirname $0`
-__DIR__=$(readlink -f "$__DIR__")
-__ROOT__=`dirname $__DIR__`
+var ROOT_PATH, LIB_PATH;
+//Build path
+ROOT_PATH = path.dirname(__dirname);
+LIB_PATH = path.join(path.dirname(__dirname), 'lib');
+require.paths.unshift(LIB_PATH);
-#Can be overriden by makefile
-LIB_PATH=$__ROOT__/lib
-#used by the launcher
-export NODELINT_CONFIG_FILE=$__ROOT__/etc/config.json
+//Include lint library
+var lint = require('lint');
+var Launcher = lint.Launcher;
-#node
-NODE_BIN=`which node`
-#launch command
-$NODE_BIN "$LIB_PATH/lint/launcher.js" $@
+
+if (__filename === process.ARGV[1]) {
+ var usage, args, positionals, launcher, options, configFile;
+
+ //called as main executable
+
+ usage = "Usage: " + process.ARGV[0] + " file.js [dir1 file2 dir2 ...] [options]\n" +
+ "Options:\n\n" +
+ " --config=FILE the path to a JSON file with JSLINT options\n" +
+ " --formatter=FILE optional path to a /dir/dir/file.hs file to customize the output\n" +
+ " -h, --help display this help and exit\n" +
+ " -v, --version output version information and exit";
+
+ args = process.ARGV.splice(2);
+ positionals = [];
+ options = {
+ formatter: {
+ },
+ parser: {
+ }
+ };
+ configFile = process.env.NODELINT_CONFIG_FILE;
+
+ launcher = new Launcher();
+ while (args.length !== 0) {
+ arg = args.shift();
+ switch (arg) {
+ case '-v':
+ case '--version':
+ var content, pkg;
+ content = fs.readFileSync(path.join(__filename, '..', '..', '..', 'package.json'), 'utf8');
+ pkg = JSON.parse(content);
+ util.puts(pkg.version);
+ process.exit(0);
+ break;
+ case '-h':
+ case '--help':
+ util.puts(usage);
+ process.exit(0);
+ break;
+ case '--silent':
+ options.silent = true;
+ break;
+ case '--pretty':
+ options.formatter.pretty = true;
+ break;
+ case '--no-color':
+ case '--no-colors':
+ options.formatter.colors = false;
+ break;
+ default:
+ if (arg.indexOf('--formatter') >= 0) {
+ options.formatter.type = 'callback';
+ options.formatter.callback = fs.readFileSync(arg.split('=')[1], 'utf8');
+ } else if (arg.indexOf('--format') >= 0) {
+ options.formatter.type = arg.split('=')[1];
+ } else if (arg.indexOf('--mode') >= 0) {
+ options.formatter.mode = arg.split('=')[1];
+ } else if (arg.indexOf('--config') >= 0) {
+ var file, source;
+
+ configFile = arg.split('=')[1];
+
+ } else {
+ positionals.push(arg);
+ }
+ }
+ }
+
+ //Load default config file from environment
+ if (configFile) {
+ var source;
+
+ //read config file
+ try {
+ source = fs.readFileSync(configFile, 'utf8');
+ } catch (e) {
+ launcher.printError('Read error when accessing "' + configFile + '".');
+ }
+
+ //Remove comments
+ source = source.replace(/\/\*.+?\*\/|\/\/.*(?=[\n\r])/g, '');
+
+ //Parse config
+ try {
+ source = JSON.parse(source);
+ } catch (e) {
+ console.log(e.toString());
+ launcher.printError('Parse Error in "' + configFile + '"');
+ }
+
+
+ try {
+ launcher.configure(source);
+ } catch (e) {
+ console.log(e.toString());
+ launcher.printError('Parse Error in "' + configFile + '"');
+ }
+ }
+
+ try {
+ launcher.configure(options);
+ } catch (e) {
+ launcher.printError('Configuration : ' + e.toString());
+ }
+
+ try {
+ launcher.run(positionals);
+ } catch (e) {
+ launcher.printError('Execution : ' + e.toString());
+ }
+}
+
View
@@ -4,6 +4,107 @@
*/
/*******************************************************************************
+ * Report class
+ *
+ * Usage:
+ *
+ * <pre>
+ * var report = new Report();
+ * report.addFile('foo.js', [
+ * //... some errors
+ * ]);
+ * report.addFile('bar.js', [
+ * //... some other errors
+ * ]);
+ * </pre>
+ ******************************************************************************/
+/**
+ * Report constructor
+ *
+ * @constructor
+ * @return
+ */
+function Report() {
+ this._files = {};
+ this._count = 0;
+}
+
+/**
+ * Add file report
+ *
+ * @param {string} filePath
+ * @param {Array} errors
+ * @return
+ */
+Report.prototype.addFile = function (filePath, errors) {
+ errors = errors || [];
+
+ this._files[filePath] = {};
+ this._files[filePath].file = filePath;
+ this._files[filePath].errors = errors;
+ this._files[filePath].isValid = errors.length === 0;
+
+ this._count += errors.length;
+ return this;
+};
+
+/**
+ * Return the file report
+ *
+ * @param {string} file
+ * @return {Object}
+ */
+Report.prototype.getFile = function (file) {
+ return this._files[file];
+};
+
+/**
+ *
+ * @param {string} file
+ * @return {int}
+ */
+Report.prototype.countFile = function (file) {
+ var fileIterator, count;
+
+ count = 0;
+ for (fileIterator in this._files) {
+ if (this._files.hasOwnProperty(fileIterator)) {
+ count += 1;
+ }
+ }
+ return count;
+};
+
+/**
+ *
+ * @param {string} file
+ * @return {int}
+ */
+Report.prototype.countErrors = function (file) {
+ if (file) {
+ return this._files[file].errors.length;
+ }
+ return this._count;
+};
+
+/**
+ * Iterate over the file reports
+ *
+ * @param {Function} iterator
+ * @return this
+ */
+Report.prototype.forEach = function (iterator) {
+ var file;
+
+ for (file in this._files) {
+ if (this._files.hasOwnProperty(file)) {
+ iterator(this._files[file], file);
+ }
+ }
+ return this;
+};
+
+/*******************************************************************************
* Formatter class
*
* Usage:
@@ -223,106 +324,7 @@ Base.prototype._guessEol = function () {
};
-/*******************************************************************************
- * Report class
- *
- * Usage:
- *
- * <pre>
- * var report = new Report();
- * report.addFile('foo.js', [
- * //... some errors
- * ]);
- * report.addFile('bar.js', [
- * //... some other errors
- * ]);
- * </pre>
- ******************************************************************************/
-/**
- * Report constructor
- *
- * @constructor
- * @return
- */
-function Report() {
- this._files = {};
- this._count = 0;
-}
-
-/**
- * Add file report
- *
- * @param {string} filePath
- * @param {Array} errors
- * @return
- */
-Report.prototype.addFile = function (filePath, errors) {
- errors = errors || [];
-
- this._files[filePath] = {};
- this._files[filePath].file = filePath;
- this._files[filePath].errors = errors;
- this._files[filePath].isValid = errors.length === 0;
-
- this._count += errors.length;
- return this;
-};
-
-/**
- * Return the file report
- *
- * @param {string} file
- * @return {Object}
- */
-Report.prototype.getFile = function (file) {
- return this._files[file];
-};
-
-/**
- *
- * @param {string} file
- * @return {int}
- */
-Report.prototype.countFile = function (file) {
- var fileIterator, count;
-
- count = 0;
- for (fileIterator in this._files) {
- if (this._files.hasOwnProperty(fileIterator)) {
- count += 1;
- }
- }
- return count;
-};
-
-/**
- *
- * @param {string} file
- * @return {int}
- */
-Report.prototype.countErrors = function (file) {
- if (file) {
- return this._files[file].errors.length;
- }
- return this._count;
-};
-/**
- * Iterate over the file reports
- *
- * @param {Function} iterator
- * @return this
- */
-Report.prototype.forEach = function (iterator) {
- var file;
-
- for (file in this._files) {
- if (this._files.hasOwnProperty(file)) {
- iterator(this._files[file], file);
- }
- }
- return this;
-};
View
@@ -4,11 +4,12 @@
*/
var formatter = require('./formatter');
var parser = require('./parser');
+var launcher = require('./launcher');
//Apply assert patch
require('../assert/extension');
exports.Formatter = formatter.Formatter;
-exports.Launcher = parser.Launcher;
+exports.Launcher = launcher.Launcher;
exports.Parser = parser.Parser;
View
@@ -1,7 +1,7 @@
{
"name": "lint",
"description": "This package provide lint validation library + node-lint command line tool allows you to check for problems using JSLint. You can specify your own --config file to use alternate JSLint options and your own --formatter file if you want to customize the generated output.",
- "version": "0.1.0",
+ "version": "0.1.1",
"homepage": "https://github.com/as-jpolo/node-lint",
"author": "tav <tav@espians.com> (http://tav.espians.com)",
"contributors": [
@@ -15,6 +15,7 @@
"Felix Geisendörfer (http://debuggable.com)",
"Nathan Landis (http://github.com/my8bird)"
],
+ "main" : "./lib/vows",
"bin": {
"node-lint": "./bin/node-lint"
},

0 comments on commit 5e9f855

Please sign in to comment.