Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added linting checks to the JS files to the repo #169

Merged
merged 12 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage/*
firmware/src/libs/firmata/*
58 changes: 58 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module"
},
"rules": {
"eqeqeq": 0,
"no-var": 2,
"prefer-const": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-use-before-define": 2,
"comma-dangle": [2, "never"],
"no-cond-assign": [2, "always"],
"no-constant-condition": 1,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-ex-assign": 2,
"no-extra-boolean-cast": 1,
"no-extra-semi": 2,
"no-func-assign": 2,
"no-irregular-whitespace": 2,
"default-case": 2,
"guard-for-in": 2,
"no-floating-decimal": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-throw-literal": 2,
"radix": 2,
"quotes": [2, "single", "avoid-escape"],
"indent": [2, 2, { "SwitchCase": 1 }],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-style": [2, "last"],
"no-multiple-empty-lines": 2,
"no-nested-ternary": 2,
"one-var": [2, "never"],
"padded-blocks": [2, "never"],
"keyword-spacing": 2,
"no-console": 0,
"space-before-blocks": 2,
"space-before-function-paren": [2, "never"],
"spaced-comment": 2,
"valid-jsdoc": [2, { "requireReturn": false }],
"no-unreachable": 2,
"no-unexpected-multiline": 2,
"no-else-return": 2,
"constructor-super": 2,
"no-this-before-super": 2,
"object-shorthand": [2, "always"],
"no-loop-func": 0,
"no-param-reassign": 0,
"no-empty": 0
}
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ install: clean
npm install

lint:
@echo "Not implemented"
npm run lint

test:
npm run test
Expand Down
143 changes: 71 additions & 72 deletions examples/channel_fade.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,85 @@
// This example shows how to use node-pixel using Johnny Five as the
// hook for the board.

var five = require("johnny-five");
var pixel = require("../lib/pixel.js");
const five = require('johnny-five');
const pixel = require('../lib/pixel.js');

var opts = {};
opts.port = process.argv[2] || "";
const opts = {};
opts.port = process.argv[2] || '';

var board = new five.Board(opts);
var strip = null;
const board = new five.Board(opts);
let strip = null;

var fps = 40; // how many frames per second do you want to try?
const fps = 40; // how many frames per second do you want to try?

board.on("ready", function() {
board.on('ready', function() {
console.log('Board ready, lets add light');

console.log("Board ready, lets add light");
strip = new pixel.Strip({
board: this,
controller: 'FIRMATA',
strips: [ {pin: 6, length: 8}, {pin: 8, length: 8}],
gamma: 2.8
});

strip = new pixel.Strip({
board: this,
controller: "FIRMATA",
strips: [ {pin: 6, length: 8}, {pin: 8, length: 8},],
gamma: 2.8,
});
strip.on('ready', function() {
console.log("Strip ready, let's go");

strip.on("ready", function() {
strip.color('#000000');
strip.show();
const colors = ['red', 'green', 'blue', 'yellow', 'cyan', 'magenta'];
let current_color = 0;
let fade_level = 0;
let fade_up = true;
const fader = setInterval(function() {
if (fade_up) {
// fading upwards, if we hit the top then turn around
// and go back down again.
if (++fade_level > 255) {
fade_up = false;
}
} else {
if (--fade_level < 0) {
fade_up = true;
fade_level = 0;
if (++current_color >= colors.length) current_color = 0;
}
}

console.log("Strip ready, let's go");
let hc = '';
switch (colors[current_color]) {
case 'red':
hc = `rgb(${fade_level}, 0, 0)`;
break;
case 'green':
hc = `rgb(0, ${fade_level}, 0)`;
break;
case 'blue':
hc = `rgb(0, 0, ${fade_level})`;
break;
case 'white':
hc = `rgb(${fade_level}, ${fade_level}, ${fade_level})`;
break;
case 'yellow':
hc = `rgb(${fade_level}, ${fade_level}, 0)`;
break;
case 'magenta':
hc = `rgb(${fade_level}, 0, ${fade_level})`;
break;
case 'cyan':
hc = `rgb(0, ${fade_level}, ${fade_level})`;
break;
default:
break;
}

strip.color('#000000');
strip.show();
let colors = ["red", "green", "blue", "yellow", "cyan", "magenta"];
let current_color = 0;
let fade_level = 0;
let fade_up = true;
var fader = setInterval(function() {

if (fade_up) {
// fading upwards, if we hit the top then turn around
// and go back down again.
if (++fade_level > 255) {
fade_up = false;
}
} else {
if (--fade_level < 0) {
fade_up = true;
fade_level = 0;
if (++current_color >= colors.length) current_color = 0;
}
}

let hc = "";
switch (colors[current_color]) {
case "red":
hc = `rgb(${fade_level}, 0, 0)`;
break;
case "green":
hc = `rgb(0, ${fade_level}, 0)`;
break;
case "blue":
hc = `rgb(0, 0, ${fade_level})`;
break;
case "white":
hc = `rgb(${fade_level}, ${fade_level}, ${fade_level})`;
break;
case "yellow":
hc = `rgb(${fade_level}, ${fade_level}, 0)`;
break;
case "magenta":
hc = `rgb(${fade_level}, 0, ${fade_level})`;
break;
case "cyan":
hc = `rgb(0, ${fade_level}, ${fade_level})`;
break;
}

// need to do this by pixel
for (let i = 0; i < strip.length; i++) {
strip.pixel(i).color(hc);
}
//strip.color(hc);
strip.show();
}, 1000/fps);
});
// need to do this by pixel
for (let i = 0; i < strip.length; i++) {
strip.pixel(i).color(hc);
}
// strip.color(hc);
strip.show();
}, 1000/fps);
});
});

52 changes: 25 additions & 27 deletions examples/firmata.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
// This example shows how to use node-pixel using firmata as the
// hook for the board.

var firmata = require("firmata");
var pixel = require("../lib/pixel.js");
const firmata = require('firmata');
const pixel = require('../lib/pixel.js');

var opts = {};
const opts = {};
if (process.argv[2] == undefined) {
console.log("Please supply a device port to connect to");
process.exit();
console.log('Please supply a device port to connect to');
process.exit();
}

opts.port = process.argv[2];

var strip = null;
let strip = null;

var board = new firmata.Board(opts.port, function() {
const board = new firmata.Board(opts.port, function() {
console.log('Firmata ready, lets add light');

console.log("Firmata ready, lets add light");
strip = new pixel.Strip({
data: 6,
length: 4,
firmata: board
});

strip = new pixel.Strip({
data: 6,
length: 4,
firmata: board,
});
let pos = 0;
const colors = ['red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'white'];
let current_color = 0;

var pos = 0;
var colors = ["red", "green", "blue", "yellow", "cyan", "magenta", "white"];
var current_color = 0;
const blinker = setInterval(function() {
strip.color('#000'); // blanks it out

var blinker = setInterval(function() {
if (++pos >= strip.length) {
pos = 0;
if (++current_color>= colors.length) current_color = 0;
}
strip.pixel(pos).color(colors[current_color]);

strip.color("#000"); // blanks it out

if (++pos >= strip.length) {
pos = 0;
if (++current_color>= colors.length) current_color = 0;
}
strip.pixel(pos).color(colors[current_color]);

strip.show();
}, 1000/2);
strip.show();
}, 1000/2);
});
85 changes: 41 additions & 44 deletions examples/johnnyfive-i2c.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
// This example shows how to use node-pixel using Johnny Five as the
// hook for the board.
var five = require("johnny-five");
var pixel = require("../lib/pixel.js");

var opts = {};
opts.port = process.argv[2] || "";

var board = new five.Board(opts);
var strip = null;

var fps = 1; // how many frames per second do you want to try?

board.on("ready", function() {

console.log("Board ready, lets add light");

strip = new pixel.Strip({
color_order: pixel.COLOR_ORDER.GRB,
board: this,
controller: "I2CBACKPACK",
strips: [8],
});

strip.on("ready", function() {

console.log("Strip ready, let's go");

var colors = ["red", "green", "blue", "yellow", "cyan", "magenta", "white"];
var current_colors = [0,1,2,3,4];
var current_pos = [0,1,2,3,4];
var blinker = setInterval(function() {

strip.color("#000"); // blanks it out

for (var i=0; i< current_pos.length; i++) {
if (++current_pos[i] >= strip.length) {
current_pos[i] = 0;
if (++current_colors[i] >= colors.length) current_colors[i] = 0;
}
strip.pixel(current_pos[i]).color(colors[current_colors[i]]);
}

strip.show();
}, 1000/fps);
});
const five = require('johnny-five');
const pixel = require('../lib/pixel.js');

const opts = {};
opts.port = process.argv[2] || '';

const board = new five.Board(opts);
let strip = null;

const fps = 1; // how many frames per second do you want to try?

board.on('ready', function() {
console.log('Board ready, lets add light');

strip = new pixel.Strip({
color_order: pixel.COLOR_ORDER.GRB,
board: this,
controller: 'I2CBACKPACK',
strips: [8]
});

strip.on('ready', function() {
console.log("Strip ready, let's go");

const colors = ['red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'white'];
const current_colors = [0,1,2,3,4];
const current_pos = [0,1,2,3,4];
const blinker = setInterval(function() {
strip.color('#000'); // blanks it out

for (let i=0; i< current_pos.length; i++) {
if (++current_pos[i] >= strip.length) {
current_pos[i] = 0;
if (++current_colors[i] >= colors.length) current_colors[i] = 0;
}
strip.pixel(current_pos[i]).color(colors[current_colors[i]]);
}

strip.show();
}, 1000/fps);
});
});