fixing various lint violations
This commit is contained in:
parent
29b28e7f0d
commit
04a60a5b47
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"tslint.enable": true,
|
||||
"tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib"
|
||||
}
|
@ -4,12 +4,12 @@
|
||||
|
||||
namespace pxsim {
|
||||
pxsim.initCurrentRuntime = () => {
|
||||
U.assert(!runtime.board)
|
||||
runtime.board = new Board()
|
||||
U.assert(!runtime.board);
|
||||
runtime.board = new Board();
|
||||
}
|
||||
|
||||
export function board() {
|
||||
return runtime.board as Board
|
||||
return runtime.board as Board;
|
||||
}
|
||||
|
||||
export interface AnimationOptions {
|
||||
@ -125,9 +125,9 @@ namespace pxsim {
|
||||
|
||||
|
||||
export namespace AudioContextManager {
|
||||
var _context: any; // AudioContext
|
||||
var _vco: any; //OscillatorNode;
|
||||
var _vca: any; // GainNode;
|
||||
let _context: any; // AudioContext
|
||||
let _vco: any; // OscillatorNode;
|
||||
let _vca: any; // GainNode;
|
||||
|
||||
function context(): any {
|
||||
if (!_context) _context = freshContext();
|
||||
@ -152,7 +152,7 @@ namespace pxsim {
|
||||
|
||||
export function tone(frequency: number, gain: number) {
|
||||
if (frequency <= 0) return;
|
||||
var ctx = context();
|
||||
let ctx = context();
|
||||
if (!ctx) return;
|
||||
|
||||
gain = Math.max(0, Math.min(1, gain));
|
||||
@ -198,7 +198,7 @@ namespace pxsim.basic {
|
||||
pause(interval * 5);
|
||||
} else {
|
||||
if (s.length == 1) showLeds(createImageFromString(s), interval * 5)
|
||||
else ImageMethods.scrollImage(createImageFromString(s + ' '), interval, 1);
|
||||
else ImageMethods.scrollImage(createImageFromString(s + " "), interval, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,14 +231,14 @@ namespace pxsim.control {
|
||||
let b = board();
|
||||
return b && b.id
|
||||
? b.id.slice(0, 4)
|
||||
: 'abcd';
|
||||
: "abcd";
|
||||
}
|
||||
|
||||
export function deviceSerialNumber(): number {
|
||||
let b = board();
|
||||
return parseInt(b && b.id
|
||||
? b.id.slice(1)
|
||||
: '42');
|
||||
: "42");
|
||||
}
|
||||
|
||||
export function onEvent(id: number, evid: number, handler: RefAction) {
|
||||
@ -306,7 +306,7 @@ namespace pxsim.input {
|
||||
|
||||
|
||||
export function compassHeading(): number {
|
||||
var b = board();
|
||||
let b = board();
|
||||
if (!b.usesHeading) {
|
||||
b.usesHeading = true;
|
||||
runtime.queueDisplayUpdate();
|
||||
@ -315,7 +315,7 @@ namespace pxsim.input {
|
||||
}
|
||||
|
||||
export function temperature(): number {
|
||||
var b = board();
|
||||
let b = board();
|
||||
if (!b.usesTemperature) {
|
||||
b.usesTemperature = true;
|
||||
runtime.queueDisplayUpdate();
|
||||
|
@ -35,7 +35,8 @@ namespace pxsim.micro_bit {
|
||||
virtualButtonUp: "#fff",
|
||||
lightLevelOn: "yellow",
|
||||
lightLevelOff: "#555"
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
export function randomTheme(): IBoardTheme {
|
||||
return themes[Math.floor(Math.random() * themes.length)];
|
||||
@ -59,8 +60,7 @@ namespace pxsim.micro_bit {
|
||||
leave: "mouseleave"
|
||||
};
|
||||
|
||||
export class MicrobitBoardSvg
|
||||
{
|
||||
export class MicrobitBoardSvg {
|
||||
public element: SVGSVGElement;
|
||||
private style: SVGStyleElement;
|
||||
private defs: SVGDefsElement;
|
||||
@ -127,10 +127,10 @@ namespace pxsim.micro_bit {
|
||||
Svg.fill(this.buttons[index], btn.pressed ? theme.buttonDown : theme.buttonUp);
|
||||
});
|
||||
|
||||
var bw = state.displayMode == pxsim.DisplayMode.bw
|
||||
var img = state.image;
|
||||
let bw = state.displayMode == pxsim.DisplayMode.bw
|
||||
let img = state.image;
|
||||
this.leds.forEach((led, i) => {
|
||||
var sel = (<SVGStylable><any>led)
|
||||
let sel = (<SVGStylable><any>led)
|
||||
sel.style.opacity = ((bw ? img.data[i] > 0 ? 255 : 0 : img.data[i]) / 255.0) + "";
|
||||
})
|
||||
this.updatePins();
|
||||
@ -163,7 +163,7 @@ namespace pxsim.micro_bit {
|
||||
Svg.fill(this.shakeButton, this.props.theme.virtualButtonUp);
|
||||
this.board.bus.queue(DAL.MICROBIT_ID_GESTURE, 11); // GESTURE_SHAKE
|
||||
})
|
||||
this.shakeText = Svg.child(this.g, "text", {x:400, y:110, class:'sim-text'}) as SVGTextElement;
|
||||
this.shakeText = Svg.child(this.g, "text", { x: 400, y: 110, class: "sim-text" }) as SVGTextElement;
|
||||
this.shakeText.textContent = "SHAKE"
|
||||
}
|
||||
}
|
||||
@ -171,9 +171,9 @@ namespace pxsim.micro_bit {
|
||||
private updateButtonAB() {
|
||||
let state = this.board;
|
||||
if (state.usesButtonAB && !this.buttonABText) {
|
||||
(<any>this.buttonsOuter[2]).style.visibility = 'visible';
|
||||
(<any>this.buttons[2]).style.visibility = 'visible';
|
||||
this.buttonABText = Svg.child(this.g, "text", {class: 'sim-text', x:370, y:272 }) as SVGTextElement;
|
||||
(<any>this.buttonsOuter[2]).style.visibility = "visible";
|
||||
(<any>this.buttons[2]).style.visibility = "visible";
|
||||
this.buttonABText = Svg.child(this.g, "text", { class: "sim-text", x: 370, y: 272 }) as SVGTextElement;
|
||||
this.buttonABText.textContent = "A+B";
|
||||
this.updateTheme();
|
||||
}
|
||||
@ -182,9 +182,9 @@ namespace pxsim.micro_bit {
|
||||
private updatePin(pin: Pin, index: number) {
|
||||
if (!pin) return;
|
||||
let text = this.pinTexts[index];
|
||||
let v = '';
|
||||
let v = "";
|
||||
if (pin.mode & PinMode.Analog) {
|
||||
v = Math.floor(100 - (pin.value || 0) / 1023 * 100) + '%';
|
||||
v = Math.floor(100 - (pin.value || 0) / 1023 * 100) + "%";
|
||||
if (text) text.textContent = (pin.period ? "~" : "") + (pin.value || 0) + "";
|
||||
}
|
||||
else if (pin.mode & PinMode.Digital) {
|
||||
@ -312,7 +312,8 @@ namespace pxsim.micro_bit {
|
||||
this.lightLevelButton = Svg.child(this.g, "circle", {
|
||||
cx: `50px`, cy: `${cy}px`, r: `${r}px`,
|
||||
class: 'sim-light-level-button',
|
||||
fill: `url(#${gid})` }) as SVGCircleElement;
|
||||
fill: `url(#${gid})`
|
||||
}) as SVGCircleElement;
|
||||
let pt = this.element.createSVGPoint();
|
||||
Svg.buttonEvents(this.lightLevelButton,
|
||||
(ev) => {
|
||||
@ -361,7 +362,8 @@ namespace pxsim.micro_bit {
|
||||
"enable-background": "new 0 0 498 406",
|
||||
"class": "sim",
|
||||
"x": "0px",
|
||||
"y": "0px"});
|
||||
"y": "0px"
|
||||
});
|
||||
this.style = <SVGStyleElement>Svg.child(this.element, "style", {});
|
||||
this.style.textContent = `
|
||||
svg.sim {
|
||||
@ -485,12 +487,12 @@ svg.sim.grayscale {
|
||||
// leds
|
||||
this.leds = [];
|
||||
this.ledsOuter = [];
|
||||
var left = 154, top = 113, ledoffw = 46, ledoffh = 44;
|
||||
for (var i = 0; i < 5; ++i) {
|
||||
var ledtop = i * ledoffh + top;
|
||||
for (var j = 0; j < 5; ++j) {
|
||||
var ledleft = j * ledoffw + left;
|
||||
var k = i * 5 + j;
|
||||
let left = 154, top = 113, ledoffw = 46, ledoffh = 44;
|
||||
for (let i = 0; i < 5; ++i) {
|
||||
let ledtop = i * ledoffh + top;
|
||||
for (let j = 0; j < 5; ++j) {
|
||||
let ledleft = j * ledoffw + left;
|
||||
let k = i * 5 + j;
|
||||
this.ledsOuter.push(Svg.child(this.g, "rect", { class: "sim-led-back", x: ledleft, y: ledtop, width: 10, height: 20, rx: 2, ry: 2 }));
|
||||
this.leds.push(Svg.child(this.g, "rect", { class: "sim-led", x: ledleft - 2, y: ledtop - 2, width: 14, height: 24, rx: 3, ry: 3, title: `(${j},${i})` }));
|
||||
}
|
||||
@ -498,11 +500,11 @@ svg.sim.grayscale {
|
||||
|
||||
// head
|
||||
this.head = <SVGGElement>Svg.child(this.g, "g", {});
|
||||
Svg.child(this.head, "circle", { cx: 258, cy: 75, r: 100, fill:'transparent'})
|
||||
Svg.child(this.head, "circle", { cx: 258, cy: 75, r: 100, fill: "transparent" })
|
||||
this.logos.push(Svg.path(this.head, "sim-theme", "M269.9,50.2L269.9,50.2l-39.5,0v0c-14.1,0.1-24.6,10.7-24.6,24.8c0,13.9,10.4,24.4,24.3,24.7v0h39.6c14.2,0,24.8-10.6,24.8-24.7C294.5,61,284,50.3,269.9,50.2 M269.7,89.2L269.7,89.2l-39.3,0c-7.7-0.1-14-6.4-14-14.2c0-7.8,6.4-14.2,14.2-14.2h39.1c7.8,0,14.2,6.4,14.2,14.2C283.9,82.9,277.5,89.2,269.7,89.2"));
|
||||
this.logos.push(Svg.path(this.head, "sim-theme", "M230.6,69.7c-2.9,0-5.3,2.4-5.3,5.3c0,2.9,2.4,5.3,5.3,5.3c2.9,0,5.3-2.4,5.3-5.3C235.9,72.1,233.5,69.7,230.6,69.7"));
|
||||
this.logos.push(Svg.path(this.head, "sim-theme", "M269.7,80.3c2.9,0,5.3-2.4,5.3-5.3c0-2.9-2.4-5.3-5.3-5.3c-2.9,0-5.3,2.4-5.3,5.3C264.4,77.9,266.8,80.3,269.7,80.3"));
|
||||
this.headText = <SVGTextElement>Svg.child(this.g, "text", { x: 310, y: 100, class:'sim-text' })
|
||||
this.headText = <SVGTextElement>Svg.child(this.g, "text", { x: 310, y: 100, class: "sim-text" })
|
||||
|
||||
// https://www.microbit.co.uk/device/pins
|
||||
// P0, P1, P2
|
||||
@ -648,7 +650,7 @@ svg.sim.grayscale {
|
||||
let state = this.board;
|
||||
let pin = state.pins[index];
|
||||
let svgpin = this.pins[index];
|
||||
Svg.addClass(svgpin, 'touched');
|
||||
Svg.addClass(svgpin, "touched");
|
||||
if (pin.mode & PinMode.Input) {
|
||||
let cursor = Svg.cursorPoint(pt, this.element, ev);
|
||||
let v = (400 - cursor.y) / 40 * 1023
|
||||
@ -661,7 +663,7 @@ svg.sim.grayscale {
|
||||
let state = this.board;
|
||||
let pin = state.pins[index];
|
||||
let svgpin = this.pins[index];
|
||||
Svg.removeClass(svgpin, 'touched');
|
||||
Svg.removeClass(svgpin, "touched");
|
||||
this.updatePin(pin, index);
|
||||
return false;
|
||||
});
|
||||
|
56
tslint.json
Normal file
56
tslint.json
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"rules": {
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true
|
||||
],
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"no-duplicate-variable": true,
|
||||
"no-eval": true,
|
||||
"no-internal-module": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-var-keyword": true,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": [
|
||||
true,
|
||||
"double"
|
||||
],
|
||||
"semicolon": [
|
||||
false,
|
||||
"always"
|
||||
],
|
||||
"triple-equals": [
|
||||
false,
|
||||
"allow-null-check"
|
||||
],
|
||||
"typedef-whitespace": [
|
||||
true,
|
||||
{
|
||||
"call-signature": "nospace",
|
||||
"index-signature": "nospace",
|
||||
"parameter": "nospace",
|
||||
"property-declaration": "nospace",
|
||||
"variable-declaration": "nospace"
|
||||
}
|
||||
],
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords"
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user