Skip to content

Commit

Permalink
Update code linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtree committed Apr 15, 2015
1 parent da0b2ce commit d3f5e13
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 40 deletions.
6 changes: 4 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rules:
eqeqeq: 2
use-isnan: 2
no-eq-null: 2
brace-style: 2
// brace-style: 2
spaced-line-comment: 2
valid-jsdoc: 2
space-infix-ops: 2
Expand All @@ -37,7 +37,9 @@ rules:
camelcase: 2
new-cap: 2
consistent-this: [1, "_this"]
func-names: 2
//func-names: 2
key-spacing: 2
no-dupe-keys: 2
strict: 2
no-process-exit: 0
no-underscore-dangle: 0
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NPM = npm
PEGJS = node_modules/.bin/pegjs
BROWSERIFY = node_modules/.bin/browserify
UGLIFY = node_modules/.bin/uglifyjs
LINTER = node_modules/.bin/jshint
LINTER = node_modules/.bin/eslint
MOCHA = node_modules/.bin/mocha

all: build browser
Expand All @@ -30,7 +30,7 @@ bench: benchmark/benchmark.js
$(NODE) $<

lint:
$(LINTER) index.js bin/cli.js test/index.js test/cli.js
$(LINTER) index.js bin/cli.js

test: test/*
$(MOCHA)
Expand Down
42 changes: 21 additions & 21 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ program
.option(' --hex', 'Output in hex encoding')
.option(' --base64', 'Output in base64 encoding');

function Runtime(program) {
this.program = program;
function Runtime(cli) {
this.program = cli;
this.availablePlugins = {
yaml: 'js-yaml',
msgpack: 'msgpack',
Expand All @@ -42,15 +42,15 @@ Runtime.prototype.error = function(str) {
};

Runtime.prototype.loadPlugins = function() {
var rt = this;
var _this = this;
var plugins = {};
var config = this.availablePlugins;
Object.keys(config).forEach(function(k) {
if(rt.program[k]) {
if(_this.program[k]) {
try { plugins[k] = require(config[k]); }
catch (e) {
rt.error('Cannot load package: '+config[k]+' ('+k+' mode)\n'+
'Installation instruction: npm install -g '+config[k]);
_this.error('Cannot load package: ' + config[k] + ' (' + k + ' mode)\n' +
'Installation instruction: npm install -g ' + config[k]);
}
}
});
Expand All @@ -67,7 +67,7 @@ Runtime.prototype.loadRc = function() {
if(fs.existsSync(fn)) {
return require(fn);
}
return this.error('rc file not exists: '+this.program.usonrc);
return this.error('rc file not exists: ' + this.program.usonrc);
}
fn = path.resolve(home, RCFILE);
if(fs.existsSync(fn)) {
Expand All @@ -91,35 +91,35 @@ Runtime.prototype.parse = function(input) {
if(this.program.form) {
return this.plugins.form.stringify(output);
}
return JSON.stringify(output, null, space)+'\n';
return JSON.stringify(output, null, space) + '\n';
};


Runtime.prototype.listenStdin = function() {
var rt = this;
process.stdin.on('data', function (buf) {
var _this = this;
process.stdin.on('data', function(buf) {
var str = buf.toString().trim();
if(!str) { return; }
rt.process(str);
_this.process(str);
});
process.stdin.on('end', function () {
process.stdin.on('end', function() {
process.exit();
});
};

Runtime.prototype.writeData = function(data) {
if(this.program.output) {
if(fs.existsSync(this.program.output)) {
return this.error('File exists: '+this.program.output+', exiting ..');
return this.error('File exists: ' + this.program.output + ', exiting ..');
}
fs.writeFileSync(this.program.output, data);
console.log('File saved: '+this.program.output);
return;
console.log('File saved: ' + this.program.output);
return true;
}
if(this.program.hex) {
data = new Buffer(data).toString('hex')+'\n';
data = new Buffer(data).toString('hex') + '\n';
} else if(this.program.base64) {
data = new Buffer(data).toString('base64')+'\n';
data = new Buffer(data).toString('base64') + '\n';
}
process.stdout.write(data);
};
Expand All @@ -128,15 +128,15 @@ Runtime.prototype.process = function(data) {
this.writeData(this.parse(data));
};

(function runProgram(program) {

var runtime = new Runtime(program);
(function runProgram(cli) {
var runtime = new Runtime(cli);
var data;

if(program.input) {
if(!fs.existsSync(program.input)) {
runtime.error('File not exists: ' + program.input);
}
var data = fs.readFileSync(program.input).toString();
data = fs.readFileSync(program.input).toString();
runtime.process(data);
}

Expand Down
Loading

0 comments on commit d3f5e13

Please sign in to comment.