Skip to content

Commit

Permalink
Tighten up the graphics on level 4
Browse files Browse the repository at this point in the history
I mean the linter rules, whitespace only.
  • Loading branch information
reconbot committed May 14, 2016
1 parent bd959f2 commit 77b1cbc
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 157 deletions.
29 changes: 12 additions & 17 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
module.exports = {
extends: "standard",
env: {
node: true,
mocha: true,
},
plugins: [
"standard"
],
parserOptions: {
sourceType: "script"
},
rules: {
"brace-style": [2, "1tbs", {"allowSingleLine": true} ],
"complexity": [2, 32],
"curly": 2,
"eqeqeq": 2,
"no-use-before-define": 2,
"no-caller": 2,
"max-depth": 2,
"complexity": [2, 32],
"max-statements": [2, 41],
"no-else-return": 2, // maybe
"wrap-iife": [2, "inside"],
"new-cap": 2,
"strict": 2,
"curly": 2,
"quotes": [2, "single", "avoid-escape"],
"brace-style": 2,
"no-caller": 2,
"no-cond-assign": 2,
"no-else-return": 2,
"no-unused-vars": [2, { "args": "after-used" }],
"space-before-function-paren": 0,
"semi": [2, "always", {
"omitLastInOneLineBlock": true
}]
"no-use-before-define": 2,
"quotes": [2, "single", "avoid-escape"],
"semi": [2, "always", {"omitLastInOneLineBlock": true }],
"space-before-function-paren": [2, "never"],
"strict": 2,
"wrap-iife": [2, "inside"]
}
};
6 changes: 3 additions & 3 deletions bin/serialport-terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var port = new serialport.SerialPort(args.port, openOptions);

process.stdin.resume();
process.stdin.setRawMode(true);
process.stdin.on('data', function (s) {
process.stdin.on('data', function(s) {
if (s[0] === 0x03) {
port.close();
process.exit(0);
Expand All @@ -68,11 +68,11 @@ process.stdin.on('data', function (s) {
port.write(s);
});

port.on('data', function (data) {
port.on('data', function(data) {
process.stdout.write(data.toString());
});

port.on('error', function (err) {
port.on('error', function(err) {
console.log('Error', err);
process.exit(1);
});
12 changes: 6 additions & 6 deletions lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
// Copyright 2011 Chris Williams <[email protected]>

module.exports = {
raw: function (emitter, buffer) {
raw: function(emitter, buffer) {
emitter.emit('data', buffer);
},

// encoding: ascii utf8 utf16le ucs2 base64 binary hex
// More: http://nodejs.org/api/buffer.html#buffer_buffer
readline: function (delimiter, encoding) {
readline: function(delimiter, encoding) {
if (typeof delimiter === 'undefined' || delimiter === null) { delimiter = '\r' }
if (typeof encoding === 'undefined' || encoding === null) { encoding = 'utf8' }
// Delimiter buffer saved in closure
var data = '';
return function (emitter, buffer) {
return function(emitter, buffer) {
// Collect data
data += buffer.toString(encoding);
// Split collected data by delimiter
var parts = data.split(delimiter);
data = parts.pop();
parts.forEach(function (part) {
parts.forEach(function(part) {
emitter.emit('data', part);
});
};
Expand All @@ -41,13 +41,13 @@ module.exports = {

// Emit a data event each time a byte sequence (delimiter is an array of byte) is found
// Sample usage : byteDelimiter([10, 13])
byteDelimiter: function (delimiter) {
byteDelimiter: function(delimiter) {
if (Object.prototype.toString.call(delimiter) !== '[object Array]') {
delimiter = [ delimiter ];
}
var buf = [];
var nextDelimIndex = 0;
return function (emitter, buffer) {
return function(emitter, buffer) {
for (var i = 0; i < buffer.length; i++) {
buf[buf.length] = buffer[i];
if (buf[buf.length - 1] === delimiter[nextDelimIndex]) {
Expand Down
52 changes: 26 additions & 26 deletions lib/serialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function SerialPort(path, options, openImmediately, callback) {
}

stream.Stream.call(this);
callback = callback || function (err) {
callback = callback || function(err) {
if (err) {
if (this._events.error) {
this.emit('error', err);
Expand Down Expand Up @@ -143,12 +143,12 @@ function SerialPort(path, options, openImmediately, callback) {
}

// TODO remove this option
settings.dataCallback = options.dataCallback || function (data) {
settings.dataCallback = options.dataCallback || function(data) {
settings.parser(this, data);
}.bind(this);

// TODO remove this option
settings.disconnectedCallback = options.disconnectedCallback || function (err) {
settings.disconnectedCallback = options.disconnectedCallback || function(err) {
if (this.closing) {
return;
}
Expand All @@ -172,7 +172,7 @@ function SerialPort(path, options, openImmediately, callback) {
this.options = settings;

if (openImmediately) {
process.nextTick(function () {
process.nextTick(function() {
this.open(callback);
}.bind(this));
}
Expand All @@ -189,7 +189,7 @@ SerialPort.prototype._error = function(error, callback) {
}
};

SerialPort.prototype.open = function (callback) {
SerialPort.prototype.open = function(callback) {
if (this.isOpen()) {
return this._error(new Error('Port is already open'), callback);
}
Expand All @@ -203,7 +203,7 @@ SerialPort.prototype.open = function (callback) {
this.reading = false;
this.opening = true;

SerialPortBinding.open(this.path, this.options, function (err, fd) {
SerialPortBinding.open(this.path, this.options, function(err, fd) {
if (err) {
debug('SerialPortBinding.open had an error', err);
return this._error(err, callback);
Expand All @@ -213,7 +213,7 @@ SerialPort.prototype.open = function (callback) {
this.opening = false;

if (process.platform !== 'win32') {
this.serialPoller = new SerialPortBinding.SerialportPoller(this.fd, function (err) {
this.serialPoller = new SerialPortBinding.SerialportPoller(this.fd, function(err) {
if (!err) {
this._read();
} else {
Expand All @@ -231,7 +231,7 @@ SerialPort.prototype.open = function (callback) {
// underlying code is written to update all options, but for now
// only baud is respected as I don't want to duplicate all the option
// verification code above
SerialPort.prototype.update = function (options, callback) {
SerialPort.prototype.update = function(options, callback) {
if (!this.isOpen()) {
debug('update attempted, but port is not open');
return this._error(new Error('Port is not open'), callback);
Expand All @@ -241,7 +241,7 @@ SerialPort.prototype.update = function (options, callback) {
var settings = assign({}, defaultSettings, correctedOptions);
this.options.baudRate = settings.baudRate;

SerialPortBinding.update(this.fd, this.options, function (err) {
SerialPortBinding.update(this.fd, this.options, function(err) {
if (err) {
return this._error(err, callback);
}
Expand All @@ -253,7 +253,7 @@ SerialPort.prototype.isOpen = function() {
return this.fd !== null && !this.closing;
};

SerialPort.prototype.write = function (buffer, callback) {
SerialPort.prototype.write = function(buffer, callback) {
if (!this.isOpen()) {
debug('write attempted, but port is not open');
return this._error(new Error('Port is not open'), callback);
Expand All @@ -263,7 +263,7 @@ SerialPort.prototype.write = function (buffer, callback) {
buffer = new Buffer(buffer);
}
debug('write data: ' + JSON.stringify(buffer));
SerialPortBinding.write(this.fd, buffer, function (err, result) {
SerialPortBinding.write(this.fd, buffer, function(err, result) {
if (err) {
debug('SerialPortBinding.write had an error', err);
return this._error(err, callback);
Expand All @@ -273,7 +273,7 @@ SerialPort.prototype.write = function (buffer, callback) {
};

if (process.platform !== 'win32') {
SerialPort.prototype._read = function () {
SerialPort.prototype._read = function() {
if (!this.readable || this.paused || this.reading || this.closing) {
return;
}
Expand Down Expand Up @@ -337,7 +337,7 @@ if (process.platform !== 'win32') {
}
}.bind(this);

fs.read(this.fd, this.pool, this.pool.used, toRead, null, function (err, bytesRead) {
fs.read(this.fd, this.pool, this.pool.used, toRead, null, function(err, bytesRead) {
var readPool = this.pool;
var bytesRequested = toRead;
_afterRead(err, bytesRead, readPool, bytesRequested);
Expand All @@ -346,15 +346,15 @@ if (process.platform !== 'win32') {
this.pool.used += toRead;
};

SerialPort.prototype._emitData = function (data) {
SerialPort.prototype._emitData = function(data) {
this.options.dataCallback(data);
};

SerialPort.prototype.pause = function () {
SerialPort.prototype.pause = function() {
this.paused = true;
};

SerialPort.prototype.resume = function () {
SerialPort.prototype.resume = function() {
this.paused = false;

if (this.buffer) {
Expand All @@ -372,7 +372,7 @@ if (process.platform !== 'win32') {
};
} // if !'win32'

SerialPort.prototype.disconnected = function (err) {
SerialPort.prototype.disconnected = function(err) {
// send notification of disconnect
if (this.options.disconnectedCallback) {
this.options.disconnectedCallback(err);
Expand All @@ -387,7 +387,7 @@ SerialPort.prototype.disconnected = function (err) {
// clean up all other items
var fd = this.fd;
try {
SerialPortBinding.close(fd, function (err) {
SerialPortBinding.close(fd, function(err) {
if (err) {
debug('Disconnect completed with error: ' + JSON.stringify(err));
} else {
Expand All @@ -407,7 +407,7 @@ SerialPort.prototype.disconnected = function (err) {
}
};

SerialPort.prototype.close = function (callback) {
SerialPort.prototype.close = function(callback) {
var fd = this.fd;

if (this.closing) {
Expand All @@ -427,7 +427,7 @@ SerialPort.prototype.close = function (callback) {
this.readable = false;
this.serialPoller.close();
}
SerialPortBinding.close(fd, function (err) {
SerialPortBinding.close(fd, function(err) {
this.closing = false;
if (err) {
debug('SerialPortBinding.close had an error', err);
Expand All @@ -440,13 +440,13 @@ SerialPort.prototype.close = function (callback) {
}.bind(this));
};

SerialPort.prototype.flush = function (callback) {
SerialPort.prototype.flush = function(callback) {
if (!this.isOpen()) {
debug('flush attempted, but port is not open');
return this._error(new Error('Port is not open'), callback);
}

SerialPortBinding.flush(this.fd, function (err, result) {
SerialPortBinding.flush(this.fd, function(err, result) {
if (err) {
debug('SerialPortBinding.flush had an error', err);
return this._error(err, callback);
Expand All @@ -455,7 +455,7 @@ SerialPort.prototype.flush = function (callback) {
}.bind(this));
};

SerialPort.prototype.set = function (options, callback) {
SerialPort.prototype.set = function(options, callback) {
if (!this.isOpen()) {
debug('set attempted, but port is not open');
return this._error(new Error('Port is not open'), callback);
Expand All @@ -477,7 +477,7 @@ SerialPort.prototype.set = function (options, callback) {
}
}

SerialPortBinding.set(this.fd, settings, function (err, result) {
SerialPortBinding.set(this.fd, settings, function(err, result) {
if (err) {
debug('SerialPortBinding.set had an error', err);
return this._error(err, callback);
Expand All @@ -486,15 +486,15 @@ SerialPort.prototype.set = function (options, callback) {
}.bind(this));
};

SerialPort.prototype.drain = function (callback) {
SerialPort.prototype.drain = function(callback) {
var fd = this.fd;

if (!this.isOpen()) {
debug('drain attempted, but port is not open');
return this._error(new Error('Port is not open'), callback);
}

SerialPortBinding.drain(fd, function (err, result) {
SerialPortBinding.drain(fd, function(err, result) {
if (err) {
debug('SerialPortBinding.drain had an error', err);
return this._error(err, callback);
Expand Down
4 changes: 2 additions & 2 deletions test/arduinoTest/stress.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('the stress', function() {
return;
}

it("doesn't leak memory", function (done) {
it("doesn't leak memory", function(done) {
var data = new Buffer(1024);
var hd = new memwatch.HeapDiff();
var port = new serialPort.SerialPort(testPort, {}, false);
Expand All @@ -53,7 +53,7 @@ describe('the stress', function() {
done();
});

port.on('data', function () {});
port.on('data', function() {});

var writing = true;
var write = function() {
Expand Down
2 changes: 1 addition & 1 deletion test/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var defaultPortOpenOptions = {

var testPort = process.env.TEST_PORT;

describe('SerialPortBinding', function () {
describe('SerialPortBinding', function() {
describe('#open', function() {
it('errors when providing a bad port', function(done) {
SerialPortBinding.open('COMBAD', defaultPortOpenOptions, function(err, fd) {
Expand Down
2 changes: 1 addition & 1 deletion test/list-unix.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var portOutput = [
}
];

describe('listUnix', function () {
describe('listUnix', function() {
beforeEach(function() {
listUnix.reset();
});
Expand Down
Loading

0 comments on commit 77b1cbc

Please sign in to comment.