Skip to content
This repository has been archived by the owner on Aug 7, 2020. It is now read-only.

Commit

Permalink
* auto lint validation corrections
Browse files Browse the repository at this point in the history
* added some ansi console codes
  • Loading branch information
Julien Polo committed Dec 23, 2010
1 parent 881a4fb commit 74e30c7
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 291 deletions.
1 change: 1 addition & 0 deletions lib/assert/extension.js
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,4 @@
/*jslint indent:4 */
var assert = require('assert'); var assert = require('assert');
var fs = require('fs'); var fs = require('fs');
var lint = require('../lint/parser'); var lint = require('../lint/parser');
Expand Down
74 changes: 37 additions & 37 deletions lib/lint/formatter.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@


/******************************************************************************* /*******************************************************************************
* Report class * Report class
* *
* Usage: * Usage:
* *
* <pre> * <pre>
* var report = new Report(); * var report = new Report();
* report.addFile('foo.js', [ * report.addFile('foo.js', [
Expand All @@ -20,7 +20,7 @@
******************************************************************************/ ******************************************************************************/
/** /**
* Report constructor * Report constructor
* *
* @constructor * @constructor
* @return * @return
*/ */
Expand All @@ -31,26 +31,26 @@ function Report() {


/** /**
* Add file report * Add file report
* *
* @param {string} filePath * @param {string} filePath
* @param {Array} errors * @param {Array} errors
* @return * @return
*/ */
Report.prototype.addFile = function (filePath, errors) { Report.prototype.addFile = function (filePath, errors) {
errors = errors || []; errors = errors || [];

this._files[filePath] = {}; this._files[filePath] = {};
this._files[filePath].file = filePath; this._files[filePath].file = filePath;
this._files[filePath].errors = errors; this._files[filePath].errors = errors;
this._files[filePath].isValid = errors.length === 0; this._files[filePath].isValid = errors.length === 0;

this._count += errors.length; this._count += errors.length;
return this; return this;
}; };


/** /**
* Return the file report * Return the file report
* *
* @param {string} file * @param {string} file
* @return {Object} * @return {Object}
*/ */
Expand All @@ -59,13 +59,13 @@ Report.prototype.getFile = function (file) {
}; };


/** /**
* *
* @param {string} file * @param {string} file
* @return {int} * @return {int}
*/ */
Report.prototype.countFile = function (file) { Report.prototype.countFile = function (file) {
var fileIterator, count; var fileIterator, count;

count = 0; count = 0;
for (fileIterator in this._files) { for (fileIterator in this._files) {
if (this._files.hasOwnProperty(fileIterator)) { if (this._files.hasOwnProperty(fileIterator)) {
Expand All @@ -76,7 +76,7 @@ Report.prototype.countFile = function (file) {
}; };


/** /**
* *
* @param {string} file * @param {string} file
* @return {int} * @return {int}
*/ */
Expand All @@ -89,13 +89,13 @@ Report.prototype.countErrors = function (file) {


/** /**
* Iterate over the file reports * Iterate over the file reports
* *
* @param {Function} iterator * @param {Function} iterator
* @return this * @return this
*/ */
Report.prototype.forEach = function (iterator) { Report.prototype.forEach = function (iterator) {
var file; var file;

for (file in this._files) { for (file in this._files) {
if (this._files.hasOwnProperty(file)) { if (this._files.hasOwnProperty(file)) {
iterator(this._files[file], file); iterator(this._files[file], file);
Expand All @@ -106,24 +106,24 @@ Report.prototype.forEach = function (iterator) {


/******************************************************************************* /*******************************************************************************
* Formatter class * Formatter class
* *
* Usage: * Usage:
* *
* <pre> * <pre>
* var formatter = new Formatter({type: 'json'}); * var formatter = new Formatter({type: 'json'});
* *
* formatter.formater( report)//report is instance of Report * formatter.formater( report)//report is instance of Report
* </pre> * </pre>
******************************************************************************/ ******************************************************************************/
/** /**
* Formatter constructor * Formatter constructor
* *
* @constructor * @constructor
*/ */
function Formatter(options) { function Formatter(options) {
this._adapterType = 'cli'; this._adapterType = 'cli';
this._adapter = null; this._adapter = null;

this.configure(options); this.configure(options);
} }


Expand All @@ -133,37 +133,37 @@ Formatter.FULL = 'full';


/** /**
* Return the adapter from configuration * Return the adapter from configuration
* *
* @return {Base} * @return {Base}
*/ */
Formatter.prototype._getAdapter = function () { Formatter.prototype._getAdapter = function () {
if (!this._adapter) { if (!this._adapter) {
var formatterModule, FormatterClass; var formatterModule, FormatterClass, options;

options = { options = {
type: this._adapterType, type: this._adapterType,
mode: Formatter.NORMAL mode: Formatter.NORMAL
}; };

try { try {
formatterModule = require('./formatter/' + options.type); formatterModule = require('./formatter/' + options.type);
} catch (e) { } catch (e) {
throw new Error('Formatter "' + options.type + '" not found'); throw new Error('Formatter "' + options.type + '" not found');
} }
FormatterClass = formatterModule.Formatter; FormatterClass = formatterModule.Formatter;

if (FormatterClass === undefined) { if (FormatterClass === undefined) {
throw new Error('Formatter class not found in module "' + options.type + '"'); throw new Error('Formatter class not found in module "' + options.type + '"');
} }

this._adapter = new FormatterClass(options); this._adapter = new FormatterClass(options);
} }
return this._adapter; return this._adapter;
}; };


/** /**
* Configure the formatter * Configure the formatter
* *
* @return this * @return this
*/ */
Formatter.prototype.configure = function (options) { Formatter.prototype.configure = function (options) {
Expand All @@ -172,14 +172,14 @@ Formatter.prototype.configure = function (options) {
this._adapterType = options.type; this._adapterType = options.type;
this._adapter = null; this._adapter = null;
} }

this._getAdapter().configure(options); this._getAdapter().configure(options);
return this; return this;
}; };


/** /**
* Return a formatted text * Return a formatted text
* *
* @return {string} * @return {string}
*/ */
Formatter.prototype.format = function (report) { Formatter.prototype.format = function (report) {
Expand All @@ -188,14 +188,14 @@ Formatter.prototype.format = function (report) {


/******************************************************************************* /*******************************************************************************
* Base class * Base class
* *
* Usage: * Usage:
* *
* > inherits from this class to create a new formatter * > inherits from this class to create a new formatter
******************************************************************************/ ******************************************************************************/
/** /**
* Base constructor * Base constructor
* *
* @constructor * @constructor
* @param {Object} options * @param {Object} options
*/ */
Expand All @@ -214,14 +214,14 @@ function Base(options) {


/** /**
* Configure the formatter * Configure the formatter
* *
* @param {Object} options * @param {Object} options
* - mode: quantity of information displayed (= simple|normal|full) * - mode: quantity of information displayed (= simple|normal|full)
* - encoding: character encoding utf-8 * - encoding: character encoding utf-8
* - tab: tabulation character used (default: "\t") * - tab: tabulation character used (default: "\t")
* - eol: end of line character (default: "\n") * - eol: end of line character (default: "\n")
* - limit: limit the error count (default: null) * - limit: limit the error count (default: null)
* *
* @return this * @return this
*/ */
Base.prototype.configure = function (options) { Base.prototype.configure = function (options) {
Expand All @@ -247,7 +247,7 @@ Base.prototype.configure = function (options) {
if (options.eol !== undefined) { if (options.eol !== undefined) {
this.eol = options.eol; this.eol = options.eol;
} }

if (options.limit !== undefined) { if (options.limit !== undefined) {
this.limit = options.limit; this.limit = options.limit;
} }
Expand All @@ -257,7 +257,7 @@ Base.prototype.configure = function (options) {


/** /**
* Return formatted data * Return formatted data
* *
* @param {Object} data * @param {Object} data
* @param {string} mode * @param {string} mode
* @return {string} * @return {string}
Expand All @@ -266,7 +266,7 @@ Base.prototype.format = function (report, mode) {
if (report === undefined) { if (report === undefined) {
throw new Error('`report` should not be undefined'); throw new Error('`report` should not be undefined');
} }

if (!(report instanceof Report)) { if (!(report instanceof Report)) {
throw new Error('`report` should be an instance of Report.'); throw new Error('`report` should be an instance of Report.');
} }
Expand All @@ -288,7 +288,7 @@ Base.prototype.format = function (report, mode) {


/** /**
* Return simple formatted content (can be overriden) * Return simple formatted content (can be overriden)
* *
* @return {string} * @return {string}
*/ */
Base.prototype._formatSimple = function (report) { Base.prototype._formatSimple = function (report) {
Expand All @@ -297,7 +297,7 @@ Base.prototype._formatSimple = function (report) {


/** /**
* Return normal formatted content (can be overriden) * Return normal formatted content (can be overriden)
* *
* @return {string} * @return {string}
*/ */
Base.prototype._formatNormal = function (report) { Base.prototype._formatNormal = function (report) {
Expand All @@ -306,7 +306,7 @@ Base.prototype._formatNormal = function (report) {


/** /**
* Return full formatted content (can be overriden) * Return full formatted content (can be overriden)
* *
* @return {string} * @return {string}
*/ */
Base.prototype._formatFull = function (report) { Base.prototype._formatFull = function (report) {
Expand Down
Loading

0 comments on commit 74e30c7

Please sign in to comment.