Skip to content

Commit

Permalink
Dev update from JSHint to ESLint (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkarex authored Jan 24, 2022
1 parent e55c406 commit f06efb3
Show file tree
Hide file tree
Showing 6 changed files with 3,686 additions and 387 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.html]
indent_style = tab
Expand Down
32 changes: 32 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"env": {
"node": true
},
"extends": [
"eslint:recommended",
"standard"
],
"rules": {
"comma-dangle": ["warn", "always-multiline"],
"eqeqeq": "off",
"indent": ["warn", "tab", { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"max-len": ["warn", 160],
"no-tabs": "off",
"semi": ["warn", "always"],
"space-before-function-paren": ["warn", {
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}]
},
"plugins": [
"html"
],
"settings": {
"html/html-extensions": [".html"],
"html/indent": "tab",
"html/report-bad-indent": "warn"
},
"root": true
}
13 changes: 7 additions & 6 deletions chunks-to-lines.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
</script>

<script>
/* global RED:false */
RED.nodes.registerType('chunks-to-lines', {
category: 'sequence',
color: '#E2D96E',
defaults: {
name: {value: ''},
nbLines: {value: 1},
linesFormat: {value: 'text'},
decoder: {value: 'UTF-8'},
name: { value: '' },
nbLines: { value: 1 },
linesFormat: { value: 'text' },
decoder: { value: 'UTF-8' },
},
inputs: 1,
outputs: 1,
Expand All @@ -47,8 +48,8 @@
labelStyle: function () {
return this.name ? 'node_label_italic' : '';
},
oneditprepare: function() {
}
oneditprepare: function () {
},
});
</script>

Expand Down
42 changes: 21 additions & 21 deletions chunks-to-lines.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict";
'use strict';

/**
* Return an incoming node ID if the node has any input wired to it, false otherwise.
Expand Down Expand Up @@ -31,16 +31,16 @@ module.exports = function (RED) {
const node = this; // jshint ignore:line
RED.nodes.createNode(node, config);

//Declare the ability of this node to provide ticks upstream for back-pressure
// Declare the ability of this node to provide ticks upstream for back-pressure
node.tickProvider = true;
let tickUpstreamId;
let tickUpstreamNode;

//Declare the ability of this node to consume ticks from downstream for back-pressure
// Declare the ability of this node to consume ticks from downstream for back-pressure
node.tickConsumer = true;

const textDecoder = new util.TextDecoder(config.decoder || 'UTF-8');
//Special case for multi-byte new line in little-endian
// Special case for multi-byte new line in little-endian
const nlOffset = textDecoder.encoding === 'utf-16le' ? 2 : 1;

const fifo = [];
Expand All @@ -65,7 +65,7 @@ module.exports = function (RED) {
} else if (typeof msg.payload === 'string' || ArrayBuffer.isView(msg.payload)) {
upstreamTickSent = false;
if (msg.parts && msg.parts.abort) {
//Upstream abort
// Upstream abort
stringBuffer = '';
byteBuffer = new Int8Array(0);
byteBufferEnd = 0;
Expand All @@ -80,7 +80,7 @@ module.exports = function (RED) {
};

while (fifo.length > 0 && fifo[fifo.length - 1].parts.id === upstreamPartsId) {
//Clear parts from the former sequence in our FIFO
// Clear parts from the former sequence in our FIFO
fifo.pop();
}

Expand All @@ -90,10 +90,10 @@ module.exports = function (RED) {
partsIndexMultiline = -1;
csvFirstLine = '';
downstreamReady = true;
fifo.push(msg); //Inform downstream
fifo.push(msg); // Inform downstream
} else {
if (msg.parts && msg.parts.id && msg.parts.id !== upstreamPartsId) {
//Prepare system for a new set of upstream parts
// Prepare system for a new set of upstream parts
stringBuffer = '';
byteBuffer = new Int8Array((msg.payload.length + 1) * 2);
byteBufferEnd = 0;
Expand All @@ -104,8 +104,8 @@ module.exports = function (RED) {
downstreamReady = true;
}

const isLastPacket = msg.complete || (msg.parts && msg.parts.hasOwnProperty('count') &&
msg.parts.hasOwnProperty('index') && msg.parts.index > msg.parts.count);
const isLastPacket = msg.complete || (msg.parts && Object.prototype.hasOwnProperty.call(msg.parts, 'count') &&
Object.prototype.hasOwnProperty.call(msg.parts, 'index') && msg.parts.index > msg.parts.count);
delete msg.complete;

if (typeof msg.payload === 'string') {
Expand All @@ -115,7 +115,7 @@ module.exports = function (RED) {
}
} else {
if (byteBuffer.length <= byteBufferEnd + msg.payload.length) {
//Auto-increase buffer length
// Auto-increase buffer length
let byteBuffer2 = new Int8Array((byteBufferEnd + msg.payload.length + 1) * 2);
byteBuffer2.set(byteBuffer);
byteBuffer = byteBuffer2;
Expand All @@ -137,8 +137,8 @@ module.exports = function (RED) {
while (stringBuffer.length > 0 || byteBufferStart < byteBufferEnd) {
const msg2 = RED.util.cloneMessage(msg);

if (stringBuffer.length > 0) { //ASCII
const i = stringBuffer.indexOf("\n");
if (stringBuffer.length > 0) { // ASCII
const i = stringBuffer.indexOf('\n');
if (i >= 0) {
msg2.payload = stringBuffer.substring(0, i + 1);
stringBuffer = stringBuffer.substring(i + 1);
Expand All @@ -148,7 +148,7 @@ module.exports = function (RED) {
} else {
break;
}
} else { //Binary, fine for ASCII, ISO-8859-X, UTF-8, UTF-16, UTF-32
} else { // Binary, fine for ASCII, ISO-8859-X, UTF-8, UTF-16, UTF-32
const i = byteBuffer.subarray(byteBufferStart, byteBufferEnd).findIndex((element, index, array) => element === 0x0A);
if (i >= 0) {
msg2.payload = textDecoder.decode(byteBuffer.subarray(byteBufferStart, byteBufferStart + i + nlOffset));
Expand All @@ -172,27 +172,27 @@ module.exports = function (RED) {
nbLinesInChunk++;
msg2.parts.index = ++partsIndex;
if (partsIndex === 0) {
//First line from upstream
// First line from upstream
csvFirstLine = msg2.payload;
}
if (isLastPacket && stringBuffer.length === 0 && byteBufferStart >= byteBufferEnd) {
//Last line from upstream
// Last line from upstream
msg2.parts.count = partsIndex + 1;
msg2.complete = true;
}
fifo.push(msg2);
}
}
} else {
//Forward unknown type of message
// Forward unknown type of message
node.send(msg);
}

if (downstreamReady) {
let response = fifo.shift();
if (response) {
if (config.linesFormat === 'json') {
const payloads = [ response.payload ];
const payloads = [response.payload];
for (let i = config.nbLines - 2; i >= 0; i--) {
const next = fifo.shift();
if (next) {
Expand Down Expand Up @@ -222,17 +222,17 @@ module.exports = function (RED) {
response.parts.count = response.parts.index + 1;
}
if (config.linesFormat === 'csv') {
if (partsIndexMultiline > 0) { //Not for first message
if (partsIndexMultiline > 0) { // Not for first message
response.payload = csvFirstLine + response.payload;
}
response._parts = response.parts;
delete response.parts; //Confusing for the default Node-RED CSV node
delete response.parts; // Confusing for the default Node-RED CSV node
}
downstreamReady = false;
node.send(response);
}
if (tickUpstreamNode && (!upstreamTickSent) && ((fifo.length < nbLinesInChunk) || (fifo.length < 10 * config.nbLines))) {
//If the FIFO length is low enough, ask upstream to send more data
// If the FIFO length is low enough, ask upstream to send more data
upstreamTickSent = true;
tickUpstreamNode.receive({ tick: true });
}
Expand Down
Loading

0 comments on commit f06efb3

Please sign in to comment.