Permalink
Browse files

Fix style

  • Loading branch information...
1 parent 959c9dc commit e46a0c56c9a18b601c10e1664f6da9d78983b5e4 @mixu committed Dec 1, 2014
Showing with 231 additions and 214 deletions.
  1. +1 −0 .jshintignore
  2. +9 −0 Makefile
  3. +37 −34 index.js
  4. +13 −13 lib/argparse.js
  5. +2 −2 lib/config.js
  6. +11 −11 lib/find-by-subdir.js
  7. +18 −18 lib/getitem.js
  8. +2 −2 lib/list-tasks/filter-regex.js
  9. +2 −2 lib/run.js
  10. +13 −13 lib/style.js
  11. +4 −0 package.json
  12. +12 −12 plugins/completion.js
  13. +8 −8 plugins/config.js
  14. +1 −1 plugins/list.js
  15. +4 −4 plugins/run.js
  16. +8 −8 plugins/status.js
  17. +29 −29 plugins/tag.js
  18. +4 −4 readme.md
  19. +18 −18 test/argparse.test.js
  20. +3 −3 test/get.test.js
  21. +32 −32 test/gr.test.js
View
@@ -0,0 +1 @@
+node_modules
View
@@ -8,3 +8,12 @@ test:
$(TESTS)
.PHONY: test
+
+GJSLINT := --nojsdoc --exclude_directories=node_modules --exclude_files=bin/gr --max_line_length=120 --disable=200,201,202,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,230,231,232,233,250,251,252
+
+lint:
+ fixjsstyle $(GJSLINT) -r .
+ gjslint $(GJSLINT) -r .
+ jshint .
+
+.PHONY: lint
View
@@ -8,7 +8,7 @@ var filterRegex = require('./lib/list-tasks/filter-regex.js');
function Gr() {
this.homePath = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
- this.config = new Config(this.homePath+'/.grconfig.json');
+ this.config = new Config(this.homePath + '/.grconfig.json');
this.stack = [];
this.format = 'human';
this.directories = [];
@@ -34,11 +34,11 @@ Gr.prototype.preprocess = function(argv) {
first;
do {
isExpandable = false;
- if(!argv[index]) {
+ if (!argv[index]) {
break;
}
first = argv[index].substr(0, 2);
- switch(first) {
+ switch (first) {
case '+@':
case '+#':
argv.splice(index, 1, 'tag', 'add', argv[index].substr(2));
@@ -53,15 +53,15 @@ Gr.prototype.preprocess = function(argv) {
break;
case '-t':
// replace -t foo with @foo
- if(argv[index].length == 2) {
- argv.splice(index, 2, '@' + argv[index+1]);
+ if (argv[index].length == 2) {
+ argv.splice(index, 2, '@' + argv[index + 1]);
isExpandable = true;
index += 2;
}
break;
case '--':
// ignore strings starting with -- but not --
- if(argv[index].length > 2) {
+ if (argv[index].length > 2) {
isExpandable = true;
index++;
} else {
@@ -70,7 +70,7 @@ Gr.prototype.preprocess = function(argv) {
}
break;
}
- } while(isExpandable && index < argv.length);
+ } while (isExpandable && index < argv.length);
return argv;
};
@@ -80,25 +80,28 @@ Gr.prototype.parseTargets = function(argv) {
processed = 0,
targetPath,
first;
+
+ function pushDir(path) {
+ self.directories.push(path);
+ }
+
do {
isTarget = false;
- if(!argv[0]) {
+ if (!argv[0]) {
break;
}
first = argv[0].charAt(0);
- switch(first) {
+ switch (first) {
case '@':
case '#':
// @tags
- var key = 'tags.'+argv[0].substr(1),
+ var key = 'tags.' + argv[0].substr(1),
value = this.config.get(key);
- if(typeof value !== 'undefined') {
- (Array.isArray(value) ? value : [ value]).forEach(function(path) {
- self.directories.push(path);
- });
- } else if(this.format == 'human') {
- log.error('Tag '+argv[0]+' is not associated with any paths.');
+ if (typeof value !== 'undefined') {
+ (Array.isArray(value) ? value : [value]).forEach(pushDir);
+ } else if (this.format == 'human') {
+ log.error('Tag ' + argv[0] + ' is not associated with any paths.');
}
processed++;
isTarget = true;
@@ -109,15 +112,15 @@ Gr.prototype.parseTargets = function(argv) {
case '.':
// paths
targetPath = path.resolve(process.cwd(), argv[0]);
- if(fs.existsSync(targetPath) && fs.statSync(targetPath).isDirectory()) {
+ if (fs.existsSync(targetPath) && fs.statSync(targetPath).isDirectory()) {
this.directories.push(targetPath);
processed++;
isTarget = true;
argv.shift();
}
break;
default:
- if(argv[0] == '--json') {
+ if (argv[0] == '--json') {
argv.shift();
this.format = 'json';
isTarget = true;
@@ -128,9 +131,9 @@ Gr.prototype.parseTargets = function(argv) {
}
break;
}
- } while(isTarget && argv.length > 0);
+ } while (isTarget && argv.length > 0);
- if(processed == 0) {
+ if (processed === 0) {
// default to using all paths
this.addAll();
}
@@ -150,7 +153,7 @@ Gr.prototype.use = function(route, fn) {
if (typeof route === 'function') {
this.stack.push({ route: '', handle: route });
} else {
- this.stack.push({ route: (Array.isArray(route) ? route : [ route ] ), handle: fn });
+ this.stack.push({ route: (Array.isArray(route) ? route : [route]), handle: fn });
}
};
@@ -160,7 +163,7 @@ Gr.prototype.exec = function(argv, exit) {
tasks = [];
// if no paths, just push one task
- if(this.directories.length == 0) {
+ if (this.directories.length === 0) {
tasks.push(function(onDone) {
self.handle('', argv, onDone, exit);
});
@@ -173,12 +176,12 @@ Gr.prototype.exec = function(argv, exit) {
}
function series(task) {
- if(task) {
+ if (task) {
task(function(result) {
return series(tasks.shift());
});
} else {
- if(typeof exit === 'function') {
+ if (typeof exit === 'function') {
exit();
}
}
@@ -200,19 +203,19 @@ Gr.prototype.handle = function(path, argv, done, exit) {
if (!layer) {
log.info('No command matched:', argv);
// if the list is empty, warn
- if(self.directories.length == 0 && self.format == 'human') {
+ if (self.directories.length === 0 && self.format == 'human') {
log.warn('No target paths matched. Perhaps no paths are associated with the tag you used?');
}
return;
}
isMatch = (layer.route === '');
// skip this layer if the route doesn't match.
- if(!isMatch) {
+ if (!isMatch) {
parts = layer.route;
isMatch = parts.every(function(part, i) {
return argv[i] == part;
});
- rest = argv.slice(layer.route.length ? layer.route.length : 1 );
+ rest = argv.slice(layer.route.length ? layer.route.length : 1);
} else {
rest = argv;
}
@@ -243,11 +246,11 @@ Gr.prototype.handle = function(path, argv, done, exit) {
Gr.prototype.getTagsByPath = function(cwd) {
var self = this,
tags = [];
- if(!cwd || !this.config || !this.config.items || !this.config.items.tags) {
+ if (!cwd || !this.config || !this.config.items || !this.config.items.tags) {
return tags;
}
- Object.keys(this.config.items.tags).forEach(function(tag){
- if(Array.isArray(self.config.items.tags[tag]) &&
+ Object.keys(this.config.items.tags).forEach(function(tag) {
+ if (Array.isArray(self.config.items.tags[tag]) &&
self.config.items.tags[tag].indexOf(cwd) > -1) {
tags.push(tag);
}
@@ -257,9 +260,9 @@ Gr.prototype.getTagsByPath = function(cwd) {
Gr.prototype.addAll = function() {
var self = this;
- if(this.config && this.config.items && this.config.items.tags) {
- Object.keys(this.config.items.tags).forEach(function(tag){
- if(Array.isArray(self.config.items.tags[tag])) {
+ if (this.config && this.config.items && this.config.items.tags) {
+ Object.keys(this.config.items.tags).forEach(function(tag) {
+ if (Array.isArray(self.config.items.tags[tag])) {
self.config.items.tags[tag].forEach(function(dirname) {
self.directories.push(dirname);
});
@@ -279,6 +282,6 @@ Gr.prototype.dirUnique = function() {
last = key;
return !isDuplicate;
});
-}
+};
module.exports = Gr;
View
@@ -7,43 +7,43 @@ module.exports = function(input, type) {
argv = {},
i = 0, key, parts,
mode = 'args', // args (parse arguments) or capture (capture the rest, ignore arguments)
- hasExplicit = (input.indexOf('--') > -1)
+ hasExplicit = (input.indexOf('--') > -1);
- if(arguments.length == 1) {
+ if (arguments.length == 1) {
type = {};
}
function set(key, value) {
- if(typeof argv[key] === 'undefined') {
+ if (typeof argv[key] === 'undefined') {
argv[key] = value;
} else {
- if(!Array.isArray(argv[key])) {
- argv[key] = [ argv[key] ];
+ if (!Array.isArray(argv[key])) {
+ argv[key] = [argv[key]];
}
argv[key].push(value);
}
}
- while(i < input.length) {
- if(input[i] == '--') {
+ while (i < input.length) {
+ if (input[i] == '--') {
mode = 'capture';
i++;
- } else if(mode == 'args' && (isArg(input[i]) && input[i] != '--')) {
+ } else if (mode == 'args' && (isArg(input[i]) && input[i] != '--')) {
key = input[i].replace(/^-+/, '');
- if(key.indexOf('=') > -1) {
+ if (key.indexOf('=') > -1) {
parts = key.split('=', 2);
set(parts[0], parts[1]);
i++;
continue;
} else {
i++;
// e.g. explicitly set to String
- if(input[i] && type[key] != Boolean) {
+ if (input[i] && type[key] != Boolean) {
set(key, input[i]);
i++;
- } else if(key.substr(0, 3) == 'no-') {
+ } else if (key.substr(0, 3) == 'no-') {
set(key.substr(3), false);
} else {
set(key, true);
@@ -52,15 +52,15 @@ module.exports = function(input, type) {
} else {
// the first non-argument changes to "capture mode"
// except when the -- is passed: when that option is passed, then everything up to that argument is ignored
- if(!hasExplicit || mode == 'capture') {
+ if (!hasExplicit || mode == 'capture') {
mode = 'capture';
task.push(input[i]);
}
i++;
}
}
- if(task.length > 0) {
+ if (task.length > 0) {
argv['_'] = task;
}
return argv;
View
@@ -1,4 +1,4 @@
-var fs = require('fs')
+var fs = require('fs'),
get = require('./getitem.js').get,
set = require('./getitem.js').set,
add = require('./getitem.js').add,
@@ -8,7 +8,7 @@ function Config(filename) {
this.filename = filename;
try {
this.items = JSON.parse(fs.readFileSync(filename));
- } catch(e) {
+ } catch (e) {
this.items = {};
}
}
View
@@ -2,7 +2,7 @@ var fs = require('fs'),
path = require('path');
function find(directories, dirpath, baseNameList) {
- if(!dirpath) return [];
+ if (!dirpath) return [];
var p = path.normalize(dirpath), // for windows
stat,
basename = path.basename(p),
@@ -12,25 +12,25 @@ function find(directories, dirpath, baseNameList) {
try {
stat = fs.statSync(p);
- } catch(e) {
+ } catch (e) {
// ENOENT can occur when stat'ing a symlink to a nonexistent location
// we want to traverse symlinks in general but ignore these issues
- if(e.code != 'ENOENT') {
+ if (e.code != 'ENOENT') {
throw e;
} else {
return;
}
}
// only directories are considered
- if(!stat.isDirectory()) {
+ if (!stat.isDirectory()) {
return;
}
// console.log(p);
// append trailing slash
- p += (p[p.length-1] !== path.sep ? path.sep : '');
+ p += (p[p.length - 1] !== path.sep ? path.sep : '');
// is this a .git | .hg directory?
- if(isMatch &&
+ if (isMatch &&
stat.isDirectory()) {
// go no further
directories.push(p);
@@ -43,31 +43,31 @@ function find(directories, dirpath, baseNameList) {
return baseNameList.some(function(name) {
// must be .git | .hg dir
var result = (basename == name && fs.statSync(p + basename).isDirectory());
- if(result) {
+ if (result) {
// console.log(p + basename);
directories.push(p + basename);
}
return result;
});
});
// is a direct subdir a match?
- if(isMatch) {
+ if (isMatch) {
// go no further
return;
}
// else, we must iterate into any directories
items.filter(function(path) {
// avoid recursing into directories that start with `.`
return path.charAt(0) != '.';
- }).map(function (f) {
+ }).map(function(f) {
return find(directories, p + f, baseNameList);
}).forEach(function(i) {
- if(!!i) {
+ if (!!i) {
directories.push(i);
}
});
return;
-};
+}
module.exports = function(dirpath, baseNameList) {
var directories = [];
Oops, something went wrong.

0 comments on commit e46a0c5

Please sign in to comment.