mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 18:25:30 +00:00
Add/enforce return types for implemented Maki methods
This commit is contained in:
parent
1868047e1a
commit
0d9c05882c
6 changed files with 75 additions and 33 deletions
|
|
@ -16,6 +16,11 @@ for (const value of Object.values(objects)) {
|
|||
}
|
||||
|
||||
const TYPE_MAP = {
|
||||
// This might be wrong. Maybe it really is an empty string? Or Null?
|
||||
"": {
|
||||
typeScriptName: "TSVoidKeyword",
|
||||
stringRepresentation: "void",
|
||||
},
|
||||
string: {
|
||||
typeScriptName: "TSStringKeyword",
|
||||
stringRepresentation: "string",
|
||||
|
|
@ -164,7 +169,42 @@ module.exports = {
|
|||
return;
|
||||
}
|
||||
|
||||
const { params } = node.value;
|
||||
const { params, returnType, body } = node.value;
|
||||
const sourceCode = context.getSourceCode();
|
||||
|
||||
if (returnType == null) {
|
||||
const expectedTypeData = TYPE_MAP[func.result];
|
||||
if (
|
||||
expectedTypeData != null &&
|
||||
!sourceCode.getText(node).includes("unimplementedWarning")
|
||||
) {
|
||||
context.report({
|
||||
node: body,
|
||||
message: `Missing return type for Maki method. Expected \`${
|
||||
expectedTypeData.stringRepresentation
|
||||
}\`.`,
|
||||
fix: fixer => {
|
||||
return fixer.insertTextBefore(
|
||||
body,
|
||||
`: ${expectedTypeData.stringRepresentation}`
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const expectedTypeData = TYPE_MAP[func.result];
|
||||
if (
|
||||
expectedTypeData != null &&
|
||||
expectedTypeData.typeScriptName !== returnType.typeAnnotation.type
|
||||
) {
|
||||
context.report({
|
||||
node: returnType,
|
||||
message: `Incorrect return type for Maki method. Expected \`${
|
||||
expectedTypeData.stringRepresentation
|
||||
}\`.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
func.parameters.forEach(([type, name], i) => {
|
||||
const actual = params[i];
|
||||
|
|
@ -179,7 +219,7 @@ module.exports = {
|
|||
}
|
||||
const expectedTypeData = TYPE_MAP[type.toLowerCase()];
|
||||
if (expectedTypeData == null) {
|
||||
console.warn(`Missing type data for ${type}.`);
|
||||
// console.warn(`Missing type data for ${type}.`);
|
||||
return;
|
||||
}
|
||||
const fix = fixer => {
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ class Button extends GuiObject {
|
|||
return "Button";
|
||||
}
|
||||
|
||||
leftclick() {
|
||||
leftclick(): void {
|
||||
this.js_trigger("onLeftClick");
|
||||
}
|
||||
|
||||
rightclick() {
|
||||
rightclick(): void {
|
||||
this.js_trigger("onRightClick");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,20 +19,19 @@ class Container extends MakiObject {
|
|||
return "Container";
|
||||
}
|
||||
|
||||
show() {
|
||||
show(): void {
|
||||
this.visible = true;
|
||||
this.parent.js_trigger("js_update");
|
||||
}
|
||||
|
||||
hide() {
|
||||
hide(): void {
|
||||
this.visible = false;
|
||||
this.parent.js_trigger("js_update");
|
||||
}
|
||||
|
||||
setxmlparam(param: string, value: string) {
|
||||
setxmlparam(param: string, value: string): void {
|
||||
this.attributes[param] = value;
|
||||
this.js_trigger("js_update");
|
||||
return value;
|
||||
}
|
||||
|
||||
getlayout(id: string) {
|
||||
|
|
|
|||
|
|
@ -47,16 +47,14 @@ class GuiObject extends MakiObject {
|
|||
return findDescendantByTypeAndId(this, null, id);
|
||||
}
|
||||
|
||||
init(newRoot) {
|
||||
init(newRoot): void {
|
||||
this.parent = newRoot;
|
||||
newRoot.js_addChild(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
setxmlparam(param: string, value: string) {
|
||||
setxmlparam(param: string, value: string): void {
|
||||
this.attributes[param] = value;
|
||||
this.js_trigger("js_update");
|
||||
return value;
|
||||
}
|
||||
|
||||
getxmlparam(param: string) {
|
||||
|
|
@ -71,42 +69,42 @@ class GuiObject extends MakiObject {
|
|||
return findParentNodeOfType(this, new Set(["layout"]));
|
||||
}
|
||||
|
||||
show() {
|
||||
show(): void {
|
||||
this.visible = true;
|
||||
this.parent.js_trigger("js_update");
|
||||
}
|
||||
|
||||
hide() {
|
||||
hide(): void {
|
||||
this.visible = false;
|
||||
this.parent.js_trigger("js_update");
|
||||
}
|
||||
|
||||
gettop() {
|
||||
gettop(): number {
|
||||
return this._compareToUidSelector(
|
||||
Number(this.attributes.y) || 0,
|
||||
MakiSelectors.getTop
|
||||
);
|
||||
}
|
||||
|
||||
getleft() {
|
||||
getleft(): number {
|
||||
return Number(this.attributes.x) || 0;
|
||||
}
|
||||
|
||||
getheight() {
|
||||
getheight(): number {
|
||||
// TODO
|
||||
// I don't know how it gets calculated exactly, but if a node has a minimum
|
||||
// and maximum h, but no h, getwidth still returns a value, return min for now
|
||||
return Number(this.attributes.h) || Number(this.attributes.minimum_h) || 0;
|
||||
}
|
||||
|
||||
getwidth() {
|
||||
getwidth(): number {
|
||||
// TODO
|
||||
// I don't know how it gets calculated exactly, but if a node has a minimum
|
||||
// and maximum w, but no w, getwidth still returns a value, return min for now
|
||||
return Number(this.attributes.w) || Number(this.attributes.minimum_w) || 0;
|
||||
}
|
||||
|
||||
resize(x: number, y: number, w: number, h: number) {
|
||||
resize(x: number, y: number, w: number, h: number): void {
|
||||
this.attributes.x = x;
|
||||
this.attributes.y = y;
|
||||
this.attributes.w = w;
|
||||
|
|
@ -119,13 +117,12 @@ class GuiObject extends MakiObject {
|
|||
}
|
||||
|
||||
// alpha range from 0-255
|
||||
setalpha(alpha: number) {
|
||||
setalpha(alpha: number): void {
|
||||
this.attributes.alpha = alpha;
|
||||
this.js_trigger("js_update");
|
||||
}
|
||||
|
||||
isvisible() {
|
||||
return this.visible;
|
||||
isvisible(): number {
|
||||
return this.visible ? 1 : 0;
|
||||
}
|
||||
|
||||
onsetvisible(onoff: boolean) {
|
||||
|
|
@ -229,7 +226,8 @@ class GuiObject extends MakiObject {
|
|||
}
|
||||
|
||||
// alpha range from 0-255
|
||||
settargeta(alpha: number) {
|
||||
settargeta(alpha: number): void {
|
||||
unimplementedWarning("settargeta");
|
||||
this.attributes.alpha = alpha;
|
||||
this.js_trigger("js_update");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,12 @@ class PopupMenu extends MakiObject {
|
|||
return "PopupMenu";
|
||||
}
|
||||
|
||||
addcommand(txt: string, id: number, checked: boolean, disabled: boolean) {
|
||||
addcommand(
|
||||
txt: string,
|
||||
id: number,
|
||||
checked: boolean,
|
||||
disabled: boolean
|
||||
): void {
|
||||
this.commands.push({
|
||||
name: txt,
|
||||
id,
|
||||
|
|
@ -28,7 +33,7 @@ class PopupMenu extends MakiObject {
|
|||
});
|
||||
}
|
||||
|
||||
addseparator() {
|
||||
addseparator(): void {
|
||||
this.commands.push({ id: "separator" });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ class System extends MakiObject {
|
|||
return Selectors.getVolume(this._store.getState());
|
||||
}
|
||||
|
||||
setvolume(volume: number) {
|
||||
setvolume(volume: number): void {
|
||||
return this._store.dispatch(Actions.setVolume(volume));
|
||||
}
|
||||
|
||||
|
|
@ -527,19 +527,19 @@ class System extends MakiObject {
|
|||
return Math.sin(value);
|
||||
}
|
||||
|
||||
cos(value: number) {
|
||||
cos(value: number): number {
|
||||
return Math.cos(value);
|
||||
}
|
||||
|
||||
tan(value: number) {
|
||||
tan(value: number): number {
|
||||
return Math.tan(value);
|
||||
}
|
||||
|
||||
asin(value: number) {
|
||||
asin(value: number): number {
|
||||
return Math.asin(value);
|
||||
}
|
||||
|
||||
acos(value: number) {
|
||||
acos(value: number): number {
|
||||
return Math.acos(value);
|
||||
}
|
||||
|
||||
|
|
@ -547,11 +547,11 @@ class System extends MakiObject {
|
|||
return Math.atan(value);
|
||||
}
|
||||
|
||||
atan2(y: number, x: number) {
|
||||
atan2(y: number, x: number): number {
|
||||
return Math.atan2(y, x);
|
||||
}
|
||||
|
||||
pow(value: number, pvalue: number) {
|
||||
pow(value: number, pvalue: number): number {
|
||||
return Math.pow(value, pvalue);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue