Skip to content

Commit

Permalink
.csslitnrc lookup from cwd or basefolder CSSLint#449+
Browse files Browse the repository at this point in the history
cli folder reorganization to make things easier, unit tests for node,
manually tested for rhino and wsh.

there is no .csslintrc lookdown, ie. scoped options per one cli run
  • Loading branch information
dmi3y committed Apr 20, 2014
1 parent 1548f1e commit a2072b3
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 113 deletions.
15 changes: 9 additions & 6 deletions Gruntfile.js
Expand Up @@ -76,8 +76,9 @@ module.exports = function(grunt) {
rhino: {
src: [
"<%= concat.core.dest %>",
"src/cli/common.js",
"src/cli/rhino.js"
"src/cli/cli.js",
"src/cli/api-rhino.js",
"src/cli/api-common.js"
],
dest: "<%= build_dir %>/<%= pkg.name %>-rhino.js"
},
Expand All @@ -97,8 +98,9 @@ module.exports = function(grunt) {
banner: "#!/usr/bin/env node\n<%= banner.full %>"
},
src: [
"src/cli/common.js",
"src/cli/node.js"
"src/cli/cli.js",
"src/cli/api-node.js",
"src/cli/api-common.js"
],
dest: "<%= build_dir %>/npm/cli.js"
},
Expand All @@ -124,8 +126,9 @@ module.exports = function(grunt) {
wsh: {
src: [
"<%= concat.core.dest %>",
"src/cli/common.js",
"src/cli/wsh.js"
"src/cli/cli.js",
"src/cli/api-wsh.js",
"src/cli/api-common.js"
],
dest: "<%= build_dir %>/<%= pkg.name %>-wsh.js"
}
Expand Down
42 changes: 42 additions & 0 deletions src/cli/api-common.js
@@ -0,0 +1,42 @@
/*globals api, cli*/
/*exported commonApi*/

var commonApi = {
lookUpFile: function (filename, base) {
var lookupd = base? this.getFullPath(base): this.getWorkingDirectory(),
data,
self = this;

function isGoodToGoUp() {
var /*keep '==' because of rhino*/
isUserhome = (lookupd == self.userhome),
_lookupd = self.getFullPath(lookupd + "/../"),
isTop = (lookupd == _lookupd),
gtg;

gtg = (!data && !isUserhome && !isTop);
lookupd = _lookupd;
return gtg;
}

(function traverseUp() {
var
fullpath = self.getFullPath(lookupd + "/" + filename);

data = self.readFile(fullpath);

if ( isGoodToGoUp() ) {
traverseUp();
}
}());

return data;
}
};

/*api = */
CSSLint.Util.mix(api, commonApi);

if (typeof cli === "function") {
cli(api);
}
34 changes: 0 additions & 34 deletions src/cli/node.js → src/cli/api-node.js
Expand Up @@ -3,7 +3,6 @@
*/

/* jshint node:true */
/* global cli */
/* exported CSSLint */

var fs = require("fs"),
Expand Down Expand Up @@ -33,37 +32,6 @@ api = {
}
},

lookUpFile: function (filename, base) {
var lookupd = base? this.getFullPath(base): this.getWorkingDirectory(),
data,
self = this;

function isGoodToGoUp() {
var
isUserhome = (lookupd == self.userhome),
_lookupd = self.getFullPath(lookupd + "/../"),
isTop = (lookupd == _lookupd),
gtg;

gtg = (!data && !isUserhome && !isTop);
lookupd = _lookupd;
return gtg;
}

(function traverseUp() {
var
fullpath = self.getFullPath(lookupd + "/" + filename);

data = self.readFile(fullpath);

if ( isGoodToGoUp() ) {
traverseUp();
}
}());

return data;
},

getFiles: function(dir) {
var files = [];

Expand Down Expand Up @@ -111,5 +79,3 @@ api = {
}
}
};

cli(api);
36 changes: 2 additions & 34 deletions src/cli/rhino.js → src/cli/api-rhino.js
Expand Up @@ -3,7 +3,8 @@
*/

/* jshint rhino:true */
/* global cli, File */
/* global File*/
/* exported api*/

importPackage(java.io);

Expand All @@ -18,37 +19,6 @@ var api = {
return dir.isDirectory();
},

lookUpFile: function (filename, base) {
var lookupd = base? this.getFullPath(base): this.getWorkingDirectory(),
data,
self = this;

function isGoodToGoUp() {
var
isUserhome = (lookupd == self.userhome),
_lookupd = self.getFullPath(lookupd + "/../"),
isTop = (lookupd == _lookupd),
gtg;

gtg = (!data && !isUserhome && !isTop);
lookupd = _lookupd;
return gtg;
}

(function traverseUp() {
var
fullpath = self.getFullPath(lookupd + "/" + filename);

data = self.readFile(fullpath);

if ( isGoodToGoUp() ) {
traverseUp();
}
}());

return data;
},

getFiles: function(dir){
var files = [];

Expand Down Expand Up @@ -84,5 +54,3 @@ var api = {
}
}
};

cli(api);
37 changes: 2 additions & 35 deletions src/cli/wsh.js → src/cli/api-wsh.js
Expand Up @@ -5,9 +5,9 @@
//TODO: This file needs major cleanup!!!

/* jshint wsh:true */
/* global cli */
/* exported api */

var wshapi = (function(){
var api = (function(){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = WScript.CreateObject("WScript.Shell");
var finalArgs = [], i, args = WScript.Arguments;
Expand Down Expand Up @@ -142,37 +142,6 @@ var wshapi = (function(){
return fso.FolderExists(name);
},

lookUpFile: function (filename, base) {
var lookupd = base? this.getFullPath(base): this.getWorkingDirectory(),
data,
self = this;

function isGoodToGoUp() {
var
isUserhome = (lookupd == self.userhome),
_lookupd = self.getFullPath(lookupd + "/../"),
isTop = (lookupd == _lookupd),
gtg;

gtg = (!data && !isUserhome && !isTop);
lookupd = _lookupd;
return gtg;
}

(function traverseUp() {
var
fullpath = self.getFullPath(lookupd + "/" + filename);

data = self.readFile(fullpath);

if ( isGoodToGoUp() ) {
traverseUp();
}
}());

return data;
},

getFiles: function(dir){
var files = [];
traverseDir(files, dir);
Expand Down Expand Up @@ -206,5 +175,3 @@ var wshapi = (function(){
};

}());

cli(wshapi);
File renamed without changes.
9 changes: 5 additions & 4 deletions tests/api/api-node.js
Expand Up @@ -14,11 +14,11 @@ function include(path, sandbox) {
(function(){
var Assert = YUITest.Assert,
sandbox = {
cli: function() {/*dummy cli to run from node.js api*/},
CSSLint: CSSLint,
require: function(req) {
// monkey patched require
if (req === "./lib/csslint-node") {
return {CSSLint: null};
return {CSSLint: sandbox.CSSLint};
}
return require(req);
},
Expand All @@ -29,9 +29,10 @@ function include(path, sandbox) {
ncwd,
userhomeBackup;

include(__dirname + "/src/cli/node.js", sandbox); /* expose sandbox.api */
include(__dirname + "/src/cli/api-node.js", sandbox); /* expose sandbox.api */
include(__dirname + "/src/cli/api-common.js", sandbox); /* expose sandbox.commonApi */

userhomeBackup = sandbox.api.userhome; // have no good idea hot to test if it was resolved or not
userhomeBackup = sandbox.api.userhome; // have no good idea how to test if it was resolved or not

YUITest.TestRunner.add(new YUITest.TestCase({
name: "Node api helper",
Expand Down

0 comments on commit a2072b3

Please sign in to comment.