web linting

This commit is contained in:
Devaev Maxim 2018-08-07 19:09:47 +03:00
parent 20f7e2cde6
commit a844e9d152
10 changed files with 85 additions and 34 deletions

40
kvmd/eslintrc.yaml Normal file
View File

@ -0,0 +1,40 @@
globals:
atx: true
hid: true
keyboard: true
mouse: true
msd: true
session: true
stream: true
tools: true
ui: true
"$": true
env:
browser: true
extends: "eslint:recommended"
parserOptions:
ecmaVersion: 6
rules:
indent:
- error
- tab
- SwitchCase: 1
linebreak-style:
- error
- unix
quotes:
- error
- double
semi:
- error
- always
comma-dangle:
- error
- always-multiline
no-unused-vars:
- error
- {vars: local, args: after-used}

View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = flake8, pylint, mypy, vulture envlist = flake8, pylint, mypy, vulture, eslint, htmlhint
skipsdist = True skipsdist = True
[testenv] [testenv]
@ -30,6 +30,14 @@ deps =
vulture vulture
-rtestenv/requirements.txt -rtestenv/requirements.txt
[testenv:eslint]
whitelist_externals = eslint
commands = eslint --config=eslintrc.yaml --color web/js
[testenv:htmlhint]
whitelist_externals = htmlhint
commands = htmlhint web/*.html
[flake8] [flake8]
max-line-length = 160 max-line-length = 160
# W503 line break before binary operator # W503 line break before binary operator

View File

@ -33,17 +33,17 @@ var atx = new function() {
switch (el_button.id) { switch (el_button.id) {
case "atx-power-button": case "atx-power-button":
var button = "power"; button = "power";
var confirm_msg = "Are you sure to click the power button?"; confirm_msg = "Are you sure to click the power button?";
break; break;
case "atx-power-button-long": case "atx-power-button-long":
var button = "power_long"; button = "power_long";
var confirm_msg = "Are you sure to perform the long press of the power button?"; confirm_msg = "Are you sure to perform the long press of the power button?";
var timeout = 15000; timeout = 15000;
break; break;
case "atx-reset-button": case "atx-reset-button":
var button = "reset"; button = "reset";
var confirm_msg = "Are you sure to reboot the server?"; confirm_msg = "Are you sure to reboot the server?";
break; break;
} }

View File

@ -34,4 +34,4 @@ var hid = new function() {
mouse.setSocket(null); mouse.setSocket(null);
keyboard.setSocket(null); keyboard.setSocket(null);
}; };
} };

View File

@ -50,7 +50,7 @@ var keyboard = new function() {
$("hid-keyboard-led").className = (focused ? "led-on" : "led-off"); $("hid-keyboard-led").className = (focused ? "led-on" : "led-off");
}; };
this.releaseAll = function(ws) { this.releaseAll = function() {
__keys.concat(__modifiers).forEach(function(el_key) { __keys.concat(__modifiers).forEach(function(el_key) {
if (__isActive(el_key)) { if (__isActive(el_key)) {
keyboard.fireEvent(el_key.id, false); keyboard.fireEvent(el_key.id, false);
@ -61,13 +61,13 @@ var keyboard = new function() {
this.fireEvent = function(code, state) { this.fireEvent = function(code, state) {
$("keyboard-window").dispatchEvent(new KeyboardEvent( $("keyboard-window").dispatchEvent(new KeyboardEvent(
(state ? "keydown" : "keyup"), (state ? "keydown" : "keyup"),
{code: code}, {code: code}
)); ));
}; };
var __keyboardHandler = function(event, state) { var __keyboardHandler = function(event, state) {
event.preventDefault(); event.preventDefault();
el_key = $(event.code); var el_key = $(event.code);
if (el_key && !event.repeat) { if (el_key && !event.repeat) {
__commonHandler(el_key, state, "pressed"); __commonHandler(el_key, state, "pressed");
if (__mac_cmd_hook) { if (__mac_cmd_hook) {

View File

@ -5,7 +5,7 @@ var mouse = new function() {
var __stream_hovered = false; var __stream_hovered = false;
this.init = function() { this.init = function() {
el_stream_box = $("stream-box"); var el_stream_box = $("stream-box");
el_stream_box.onmouseenter = __hoverStream; el_stream_box.onmouseenter = __hoverStream;
el_stream_box.onmouseleave = __leaveStream; el_stream_box.onmouseleave = __leaveStream;
el_stream_box.onmousedown = (event) => __buttonHandler(event, true); el_stream_box.onmousedown = (event) => __buttonHandler(event, true);
@ -41,10 +41,10 @@ var mouse = new function() {
var __buttonHandler = function(event, state) { var __buttonHandler = function(event, state) {
// https://www.w3schools.com/jsref/event_button.asp // https://www.w3schools.com/jsref/event_button.asp
var button = null;
switch (event.button) { switch (event.button) {
case 0: var button = "left"; break; case 0: button = "left"; break;
case 2: var button = "right"; break; case 2: button = "right"; break;
default: var button = null; break;
} }
if (button) { if (button) {
event.preventDefault(); event.preventDefault();
@ -71,7 +71,7 @@ var mouse = new function() {
var __sendMove = function() { var __sendMove = function() {
var pos = __current_pos; var pos = __current_pos;
if (pos.x !== __sent_pos.x || pos.y !== __sent_pos.y) { if (pos.x !== __sent_pos.x || pos.y !== __sent_pos.y) {
el_stream_image = $("stream-image"); var el_stream_image = $("stream-image");
var to = { var to = {
x: __translate(pos.x, 0, el_stream_image.clientWidth, -32768, 32767), x: __translate(pos.x, 0, el_stream_image.clientWidth, -32768, 32767),
y: __translate(pos.y, 0, el_stream_image.clientHeight, -32768, 32767), y: __translate(pos.y, 0, el_stream_image.clientHeight, -32768, 32767),
@ -96,7 +96,7 @@ var mouse = new function() {
if (event.preventDefault) { if (event.preventDefault) {
event.preventDefault(); event.preventDefault();
} }
delta = {x: event.deltaX, y: event.deltaY}; var delta = {x: event.deltaX, y: event.deltaY};
tools.debug("Mouse wheel:", delta); tools.debug("Mouse wheel:", delta);
if (__ws) { if (__ws) {
__ws.send(JSON.stringify({ __ws.send(JSON.stringify({

View File

@ -122,7 +122,7 @@ var msd = new function() {
} }
}; };
var __uploadStateChange = function(event) { var __uploadStateChange = function() {
if (__upload_http.readyState === 4) { if (__upload_http.readyState === 4) {
if (__upload_http.status !== 200) { if (__upload_http.status !== 200) {
alert("Can't upload image to the Mass Storage Device:", __upload_http.responseText); alert("Can't upload image to the Mass Storage Device:", __upload_http.responseText);

View File

@ -75,7 +75,7 @@ var session = new function() {
setTimeout(session.startPoller, 1000); setTimeout(session.startPoller, 1000);
}; };
var __pingServer = function(event) { var __pingServer = function() {
try { try {
__missed_heartbeats += 1; __missed_heartbeats += 1;
if (__missed_heartbeats >= 5) { if (__missed_heartbeats >= 5) {

View File

@ -1,23 +1,23 @@
var tools = new function() { var tools = new function() {
var __debug = (new URL(window.location.href)).searchParams.get("debug");
this.makeRequest = function(method, url, callback, timeout=null) { this.makeRequest = function(method, url, callback, timeout=null) {
var http = new XMLHttpRequest(); var http = new XMLHttpRequest();
http.open(method, url, true) http.open(method, url, true);
http.onreadystatechange = callback; http.onreadystatechange = callback;
http.timeout = timeout ? timeout : 5000; http.timeout = (timeout ? timeout : 5000);
http.send(); http.send();
return http; return http;
}; };
var __debug = (new URL(window.location.href)).searchParams.get("debug");
this.debug = function(...args) { this.debug = function(...args) {
if (__debug) { if (__debug) {
console.log("LOG/DEBUG", ...args); console.log("LOG/DEBUG", ...args); // eslint-disable-line no-console
} }
}; };
this.info = (...args) => console.log("LOG/INFO", ...args); this.info = (...args) => console.log("LOG/INFO", ...args); // eslint-disable-line no-console
this.error = (...args) => console.error("LOG/ERROR", ...args); this.error = (...args) => console.error("LOG/ERROR", ...args); // eslint-disable-line no-console
}; };
var $ = function(id) { return document.getElementById(id); }; var $ = (id) => document.getElementById(id);

View File

@ -24,6 +24,9 @@ var ui = new function() {
} }
}); });
var __hidden_attr = null;
var __visibility_change_attr = null;
if (typeof document.hidden !== "undefined") { if (typeof document.hidden !== "undefined") {
__hidden_attr = "hidden"; __hidden_attr = "hidden";
__visibility_change_attr = "visibilitychange"; __visibility_change_attr = "visibilitychange";
@ -43,7 +46,7 @@ var ui = new function() {
hid.releaseAll(); hid.releaseAll();
} }
}, },
false, false
); );
} }
@ -115,7 +118,7 @@ var ui = new function() {
__closeAllMenues(); __closeAllMenues();
__raiseLastWindow(); __raiseLastWindow();
} }
} };
} }
}; };
@ -131,7 +134,7 @@ var ui = new function() {
var __globalMouseButtonHandler = function(event) { var __globalMouseButtonHandler = function(event) {
hid.updateLeds(); hid.updateLeds();
if (!event.target.matches(".ctl-item")) { if (!event.target.matches(".ctl-item")) {
for (el_item = event.target; el_item && el_item !== document; el_item = el_item.parentNode) { for (var el_item = event.target; el_item && el_item !== document; el_item = el_item.parentNode) {
if (el_item.hasAttribute("data-force-hide-menu")) { if (el_item.hasAttribute("data-force-hide-menu")) {
break; break;
} }
@ -163,8 +166,8 @@ var ui = new function() {
el_window.removeAttribute("data-centered"); el_window.removeAttribute("data-centered");
event = (event || window.event); event = (event || window.event);
event.preventDefault(); event.preventDefault();
x = prev_x - event.clientX; var x = prev_x - event.clientX;
y = prev_y - event.clientY; var y = prev_y - event.clientY;
prev_x = event.clientX; prev_x = event.clientX;
prev_y = event.clientY; prev_y = event.clientY;
el_window.style.top = (el_window.offsetTop - y) + "px"; el_window.style.top = (el_window.offsetTop - y) + "px";
@ -185,7 +188,7 @@ var ui = new function() {
var last_el_window = null; var last_el_window = null;
var max_z_index = 0; var max_z_index = 0;
__windows.forEach(function(el_window) { __windows.forEach(function(el_window) {
z_index = parseInt(window.getComputedStyle(el_window, null).zIndex); var z_index = parseInt(window.getComputedStyle(el_window, null).zIndex);
if (max_z_index < z_index && window.getComputedStyle(el_window, null).visibility !== "hidden") { if (max_z_index < z_index && window.getComputedStyle(el_window, null).visibility !== "hidden") {
last_el_window = el_window; last_el_window = el_window;
max_z_index = z_index; max_z_index = z_index;