Skip to content
Browse files

* console color automatic detection

* vows tests suffix
* auto jslint validation
  • Loading branch information...
1 parent 9e5f1a8 commit 56919b1101f71cd2de14a507d21b2899e6177c7d Julien Polo committed Feb 15, 2011
View
5 bin/node-lint
@@ -37,7 +37,7 @@ options = {
parser: {
}
};
-configFile = process.env.NODELINT_CONFIG_FILE;
+configFile = process.env.NODELINT_CONFIG_FILE || path.join(__dirname, '..', 'etc', 'config.json');
launcher = new Launcher();
while (args.length !== 0) {
@@ -107,7 +107,6 @@ if (configFile) {
launcher.printError('Parse Error in "' + configFile + '"');
}
-
try {
launcher.configure(source);
} catch (e) {
@@ -116,6 +115,8 @@ if (configFile) {
}
}
+
+
try {
launcher.configure(options);
} catch (e) {
View
6 etc/config.json
@@ -6,13 +6,11 @@
"formatter": {
"type": "cli", //xml, json, vim, textmate
"pretty": false,
- "colors": true
+ "colors": "auto" //'auto', true, false
},
-
//===========Parser============
"parser": {
- //"maxerr": 10000,
//"adsafe": false, // if ADsafe should be enforced
//"bitwise": true, // if bitwise operators should not be allowed
//"browser": false, // if the standard browser globals should be predefined
@@ -47,6 +45,6 @@
// the names of predefined global variables: the following are defined by nodejs itself
//"predef": ["exports", "module", "require", "process", "__filename", "__dirname", "global", "console", "setInterval", "setTimeout", "clearInterval", "clearTimeout"],
- //"node": false
+ //"nodejs": true
}
}
View
2 lib/assert/extension.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
var assert = require('assert');
var fs = require('fs');
var lint = require('../lint/parser');
View
2 lib/lint/formatter.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
/**
* Imports
*/
View
2 lib/lint/formatter/callback.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
/**
* Import
*/
View
2 lib/lint/formatter/cli.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
/**
* Import
*/
View
2 lib/lint/formatter/json.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
/**
* Import
*/
View
2 lib/lint/formatter/textmate.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
/**
* Import
*/
View
2 lib/lint/formatter/vim.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
/**
* Import
*/
View
2 lib/lint/formatter/xml.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
/**
* Import
*/
View
2 lib/lint/index.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
/**
* Imports
*/
View
28 lib/lint/jslint.js
@@ -230,7 +230,7 @@ SOFTWARE.
preferences, print, progress, prompt, prototype, pt, purple, push, px,
q, quit, quotes, random, range, raw, reach, readFile, readUrl, reason,
red, regexp, reloadWidget, removeEventListener, replace, report,
- reserved, resizeBy, resizeTo, resolvePath, resumeUpdates, rhino, right,
+ reserved, resizeBy, resizeTo, resolvePath, resumeUpdates, rhino, nodejs, right,
rosybrown, royalblue, rp, rt, ruby, runCommand, runCommandInBg,
saddlebrown, safe, salmon, samp, sandybrown, saveAs, savePreferences,
screen, script, scroll, scrollBy, scrollTo, seagreen, seal, search,
@@ -248,7 +248,8 @@ SOFTWARE.
"vertical-align", video, violet, visibility, watch, wheat, white,
"white-space", whitesmoke, widget, width, windows, "word-spacing",
"word-wrap", yahooCheckLogin, yahooLogin, yahooLogout, yellow,
- yellowgreen, "z-index"
+ yellowgreen, "z-index",
+ exports, module, require, process, __filename, __dirname, console
*/
// We build the application inside a function so that we produce only a single
@@ -329,6 +330,7 @@ var JSLINT = (function () {
plusplus : true, // if increment/decrement should not be allowed
regexp : true, // if the . should not be allowed in regexp literals
rhino : true, // if the Rhino environment globals should be predefined
+ nodejs : true, // if the nodejs environment globals should be predefined
undef : true, // if variables should be declared before used
safe : true, // if use of some browser features should be restricted
windows : true, // if MS Windows-specigic globals should be predefined
@@ -734,6 +736,21 @@ var JSLINT = (function () {
version : false
},
+ nodejs = {
+ exports: true,
+ module: true,
+ require: true,
+ process: true,
+ __filename: true,
+ __dirname: true,
+ global: true,
+ console: true,
+ setInterval: true,
+ setTimeout: true,
+ clearInterval: true,
+ clearTimeout: true
+ },
+
scope, // The current scope
windows = {
@@ -1007,10 +1024,16 @@ var JSLINT = (function () {
function assume() {
+
if (!option.safe) {
if (option.rhino) {
combine(predefined, rhino);
}
+ if (option.nodejs) {
+ option.devel = false;
+ option.es5 = true;
+ combine(predefined, nodejs);
+ }
if (option.devel) {
combine(predefined, devel);
}
@@ -5334,6 +5357,7 @@ loop: for (;;) {
o.forin =
o.on =
o.rhino =
+ o.nodejs =
o.windows =
o.sub =
o.widget = false;
View
14 lib/lint/launcher.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs:true, indent:4 */
/**
* Imports
*/
@@ -11,6 +11,16 @@ var fs = require('fs');
var parser = require('./parser');
var formatter = require('./formatter');
+//Is a tty function
+var isAtty;
+try {
+ isAtty = require('tty').isatty;
+} catch (e) {
+ isAtty = function () {
+ return false;
+ };
+}
+
var __readDirectory = function (path, callback, filter) {
if (filter) {
@@ -248,7 +258,7 @@ Launcher.prototype.run = function (args) {
};
Launcher.prototype._guessColors = function (args) {
- return (process.env.LS_COLORS !== undefined);
+ return isAtty(this._stdout) && (!fs.fstatSync(process.stdout.fd).isFile());
};
Launcher.prototype._findFiles = function (searchRoot, searchFilter, callback) {
View
95 lib/lint/parser.js
@@ -1,5 +1,5 @@
/*global JSLINT */
-/*jslint evil: true, regexp: false, indent:4 */
+/*jslint nodejs:true, indent:4 */
/**
* Imports
@@ -16,50 +16,15 @@ var JSLINT_PATH = path.join(path.dirname(fs.realpathSync(__filename)), 'jslint.j
compile(fs.readFileSync(JSLINT_PATH, 'utf8'), JSLINT_PATH);
-var NODE_CONFIG = {
- maxerr: 10000,
- adsafe: false, // if ADsafe should be enforced
- bitwise: true, // if bitwise operators should not be allowed
- browser: false, // if the standard browser globals should be predefined
- cap: false, // if upper case HTML should be allowed
- css: false, // if CSS workarounds should be tolerated
- debug: false, // if debugger statements should be allowed
- devel: false, // if logging should be allowed (console, alert, etc.)
- eqeqeq: true, // if === should be required
- es5: true, // if ES5 syntax should be allowed
- evil: false, // if eval should be allowed
- forin: false, // if for in statements must filter
- fragment: false, // if HTML fragments should be allowed
- immed: true, // if immediate invocations must be wrapped in parens
- laxbreak: false, // if line breaks should not be checked
- newcap: true, // if constructor names must be capitalized
- nomen: false, // if names should be checked
- on: false, // if HTML event handlers should be allowed
- onevar: true, // if only one var statement per function should be allowed
- passfail: false, // if the scan should stop on first error
- plusplus: true, // if increment/decrement should not be allowed
- regexp: true, // if the . should not be allowed in regexp literals
- rhino: false, // if the Rhino environment globals should be predefined
- undef: true, // if variables should be declared before used
- safe: false, // if use of some browser features should be restricted
- windows: false, // if MS Windows-specific globals should be predefined
- strict: false, // require the "use strict"; pragma
- sub: false, // if all forms of subscript notation are tolerated
- white: true, // if strict whitespace rules apply
- widget: false, // if the Yahoo Widgets globals should be predefined
- indent: 2, // set the expected indentation level
- // the names of predefined global variables: the following are defined by nodejs itself
- predef: ['exports', 'module', 'require', 'process', '__filename', '__dirname', 'global', 'console', 'setInterval', 'setTimeout', 'clearInterval', 'clearTimeout']
-};
-
/*******************************************************************************
* Parser class
*
* Usage:
*
* <pre>
* var parser = new Parser({
- * rhino : true
+ * rhino : false,
+ * nodejs: true
* })
* parser.update('var local = 1;');
* parser.update('\n');
@@ -80,10 +45,6 @@ var NODE_CONFIG = {
*/
function Parser(options) {
options = options || {};
- if (options.node === undefined) {
- options.node = true;
- }
-
this._config = {};
this._report = null;
this._isValid = null;
@@ -92,6 +53,44 @@ function Parser(options) {
this.configure(options);
}
+Parser.CONFIG = {
+ "adsafe": false, // if ADsafe should be enforced
+ "browser": false, // if the standard browser globals should be predefined
+ //"bitwise": true, // if bitwise operators should not be allowed
+ //"cap": false, // if upper case HTML should be allowed
+ //"css": false, // if CSS workarounds should be tolerated
+ "debug": false, // if debugger statements should be allowed
+ //"devel": false, // if logging should be allowed (console, alert, etc.)
+ "eqeqeq": true, // if === should be required
+ //"es5": true, // if ES5 syntax should be allowed
+ "evil": false, // if eval should be allowed
+ //"forin": false, // if for in statements must filter
+ //"fragment": false, // if HTML fragments should be allowed
+ "immed": true, // if immediate invocations must be wrapped in parens
+ //"laxbreak": false, // if line breaks should not be checked
+ //"newcap": true, // if constructor names must be capitalized
+ "nomen": false, // if names should be checked
+ //"on": false, // if HTML event handlers should be allowed
+ //"onevar": true, // if only one var statement per function should be allowed
+ //"passfail": false, // if the scan should stop on first error
+ "plusplus": true, // if increment/decrement should not be allowed
+ "regexp": true, // if the . should not be allowed in regexp literals
+ //"rhino": false, // if the Rhino environment globals should be predefined
+ //"nodejs": false, // if the NodeJS environment globals should be predefined
+ "undef": true, // if variables should be declared before used
+ "safe": false, // if use of some browser features should be restricted
+ "windows": false, // if MS Windows-specific globals should be predefined
+ "strict": false, // require the "use strict"; pragma
+ //"sub": false, // if all forms of subscript notation are tolerated
+ //"white": true, // if strict whitespace rules apply
+ //"widget": false, // if the Yahoo Widgets globals should be predefined
+
+ // the names of predefined global variables: the following are defined by nodejs itself
+ //"predef": [],
+
+
+};
+
/**
* Configure the parser
*
@@ -151,13 +150,12 @@ Parser.prototype.validate = function (force) {
if (this._report === null || force) {
config = {};
+ config.maxerr = config.maxerr || 10000;
- //Import default node preferences
- if (this._config.node) {
- for (property in NODE_CONFIG) {
- if (NODE_CONFIG.hasOwnProperty(property)) {
- config[property] = NODE_CONFIG[property];
- }
+ //Import configured preferences
+ for (property in Parser.CONFIG) {
+ if (Parser.CONFIG.hasOwnProperty(property)) {
+ config[property] = Parser.CONFIG[property];
}
}
@@ -168,7 +166,6 @@ Parser.prototype.validate = function (force) {
}
}
-
result = JSLINT(this._source, config);
this._report = [];
View
2 lib/lint/vows.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
/**
* Imports
*/
View
2 package.json
@@ -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.13",
+ "version": "0.2.0",
"homepage": "https://github.com/as-jpolo/node-lint",
"author": "tav <tav@espians.com> (http://tav.espians.com)",
"contributors": [
View
0 resource/fixture/invalid_test.js → resource/fixture/invalid-test.js
File renamed without changes.
View
0 resource/fixture/valid_test.js → resource/fixture/valid-test.js
File renamed without changes.
View
6 test/assert/extension-test.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
var vows = require('vows');
require('../../lib/assert/extension');
@@ -40,7 +40,7 @@ var AssertExtensionTest = vows.describe('assert module').addBatch({
});
},
'should throw an error if file does not contains valid javascript' : function (topic) {
- var fixtureFile = path.join(FIXTURE_PATH, 'invalid_test.js');
+ var fixtureFile = path.join(FIXTURE_PATH, 'invalid-test.js');
assert.doesNotThrow(function () {
fs.realpathSync(fixtureFile);
@@ -50,7 +50,7 @@ var AssertExtensionTest = vows.describe('assert module').addBatch({
});
},
'should not throw an error if wrong javascript is passed' : function (topic) {
- var fixtureFile = path.join(FIXTURE_PATH, 'valid_test.js');
+ var fixtureFile = path.join(FIXTURE_PATH, 'valid-test.js');
assert.doesNotThrow(function () {
topic(fixtureFile);
});
View
2 test/lint/formatter-test.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
var vows = require('vows');
var assert = require('assert');
var formatter = require('../../lib/lint/formatter');
View
2 test/lint/formatter/callback-test.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
var vows = require('vows');
var assert = require('assert');
View
2 test/lint/formatter/cli-test.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
var vows = require('vows');
var assert = require('assert');
var formatter = require('../../../lib/lint/formatter/cli');
View
2 test/lint/formatter/json-test.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
var vows = require('vows');
var assert = require('assert');
View
2 test/lint/formatter/textmate-test.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
var vows = require('vows');
var assert = require('assert');
View
2 test/lint/formatter/vim-test.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
var vows = require('vows');
var assert = require('assert');
View
2 test/lint/formatter/xml-test.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
var vows = require('vows');
var assert = require('assert');
var formatter = require('../../../lib/lint/formatter/xml');
View
10 test/lint/parser-test.js
@@ -1,4 +1,4 @@
-/*jslint indent:4 */
+/*jslint nodejs: true, indent:4 */
var vows = require('vows');
var assert = require('assert');
var fs = require('fs');
@@ -124,14 +124,14 @@ var ParserModuleTest = vows.describe('parser module').addBatch({
result : result
};
- var validFile = path.join(FIXTURE_PATH, 'valid_test.js');
+ var validFile = path.join(FIXTURE_PATH, 'valid-test.js');
parser.isValidFile(validFile, null, function (error, result) {
report.validFile = {
error : error,
result : result
};
- var invalidFile = path.join(FIXTURE_PATH, 'invalid_test.js');
+ var invalidFile = path.join(FIXTURE_PATH, 'invalid-test.js');
parser.isValidFile(invalidFile, null, function (error, result) {
report.invalidFile = {
error : error,
@@ -166,12 +166,12 @@ var ParserModuleTest = vows.describe('parser module').addBatch({
});
},
'should return true if valid javascript file' : function (topic) {
- var fixtureFile = path.join(FIXTURE_PATH, 'valid_test.js');
+ var fixtureFile = path.join(FIXTURE_PATH, 'valid-test.js');
assert.equal(topic(fixtureFile), true);
assert.equal(topic(fixtureFile), true);
},
'should return false if invalid javascript file' : function (topic) {
- var fixtureFile = path.join(FIXTURE_PATH, 'invalid_test.js');
+ var fixtureFile = path.join(FIXTURE_PATH, 'invalid-test.js');
assert.equal(topic(fixtureFile), false);
}
}

0 comments on commit 56919b1

Please sign in to comment.
Something went wrong with that request. Please try again.