Skip to content

Commit

Permalink
Set eslint to strict, include entire repository in lint checks, fix v…
Browse files Browse the repository at this point in the history
…arious eslint issues
  • Loading branch information
Basssiiie committed Nov 23, 2024
1 parent 6042c5a commit 64c8be9
Show file tree
Hide file tree
Showing 38 changed files with 435 additions and 424 deletions.
28 changes: 20 additions & 8 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
Expand All @@ -15,22 +15,34 @@ export default tseslint.config(
rules: {
"@typescript-eslint/consistent-type-assertions": ["error", { assertionStyle: "angle-bracket" }],
"@typescript-eslint/prefer-includes": "off", // not in es5
"@typescript-eslint/prefer-nullish-coalescing": "off", // verbose in es5
"@typescript-eslint/prefer-optional-chain": "off", // verbose in es5
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/prefer-literal-enum-member": "off", // enums are used as bit flags for clean efficiency
"@typescript-eslint/prefer-nullish-coalescing": "off", // too verbose in es5
"@typescript-eslint/prefer-optional-chain": "off", // too verbose in es5
"@typescript-eslint/no-confusing-void-expression": ["error", { ignoreArrowShorthand: true }],
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/no-unnecessary-condition": "warn",
"@typescript-eslint/no-unsafe-enum-comparison": "off", // enums are only used as labelled numbers
"@typescript-eslint/restrict-template-expressions": ["warn", { allowArray: true, allowBoolean: true, allowNullish: true, allowNumber: true }],
"@typescript-eslint/restrict-plus-operands": ["error", { allowNumberAndString: true }],
"@typescript-eslint/restrict-template-expressions": ["error", { allowArray: true, allowBoolean: true, allowNullish: true, allowNumber: true }],
"@typescript-eslint/triple-slash-reference": "off", // needed for openrct2 symbols
"@typescript-eslint/unified-signatures": "off", // signatures are split for easier readability
}
},
{
files: [
"**/tests/**/*.ts"
],
rules: {
"@typescript-eslint/dot-notation": "off", // by-passes allowed in tests
"@typescript-eslint/no-non-null-assertion": "off" // allowed in tests
}
},
{
ignores: [
"**/dist/**",
"**/lib/**",
"**/tests/**",
"**/rollup.config.js",
"eslint.config.mjs"
"**/*.config.{js,mjs}",
"**/_setup.cjs"
]
}
);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
"scripts": {
"start": "npm run watch",
"watch": "nodemon --watch ./src --ext js,ts --exec \"npm run build:dev\"",
"build": "npm run clean && npm run lint && rollup --config rollup.config.js --environment BUILD:production",
"build": "npm run clean && rollup --config rollup.config.js --environment BUILD:production && npm run lint",
"build:dev": "npm run clean && rollup --config rollup.config.js",
"build:examples": "npm run for:examples --action=\"run build\"",
"install:examples": "npm run for:examples --action=\"install --prefer-offline\"",
"install:test-setup": "npm install --prefix ./tests/package/project --prefer-offline --no-audit --no-save",
"install:all": "npm run for:all --action=\"install --prefer-offline\"",
"lint": "eslint ./src",
"lint": "eslint",
"test": "nyc ava",
"version:prerelease": "npm version prerelease --preid=prerelease",
"publish:local": "npm run build && npm install --global",
Expand Down
12 changes: 8 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ const config = [
...(isDev ? {} : { "Log.debug": "//" })
}
}),
typescript(),
typescript({
include: [
"./lib/**/*.ts",
"./src/**/*.ts",
]
}),
precache(cache.props.props),
terser({
compress: {
Expand Down Expand Up @@ -125,9 +130,8 @@ const config = [
plugins: [
dts({
tsconfig: "./tsconfig.json",
exclude: [
"./src/**/*.d.ts",
"./tests/**/*"
include: [
"./src/**/*.ts"
]
})
]
Expand Down
5 changes: 3 additions & 2 deletions src/bindings/binder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-parameters */
import { AnyBindable } from "./anyBindable";
import { TwoWayBindable } from "./twoway/twowayBindable";

Expand Down Expand Up @@ -29,8 +30,8 @@ export interface Binder<TTarget>
* @param value A store that can be written to for updates.
* @param callback An optional callback to be invoked after the callback specified by `key` was invoked.
*/
callback<T extends TTarget, K extends keyof T, V>(target: T, key: K, value: TwoWayBindable<V> | undefined, callback: ((arg: V) => void) | undefined): void;
callback<T extends TTarget, K extends keyof T, V, P extends unknown[]>(target: T, key: K, value: TwoWayBindable<V> | undefined, callback: ((arg: V) => void) | undefined, converter: (...args: P) => V): void;
callback<T extends TTarget, V>(target: T, key: keyof T, value: TwoWayBindable<V> | undefined, callback: ((arg: V) => void) | undefined): void;
callback<T extends TTarget, V, P extends unknown[]>(target: T, key: keyof T, value: TwoWayBindable<V> | undefined, callback: ((arg: V) => void) | undefined, converter: (...args: P) => V): void;

/**
* Reads the specified value and writes it to the target. If the value is a store, a binding
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/stores/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function compute<U>(): Store<U>
subscribe(stores[idx++], () =>
{
const newComputedValue = getComputedValue<U>(stores, callback);
return dependant.set(newComputedValue);
dependant.set(newComputedValue);
});
}
return dependant;
Expand Down
4 changes: 3 additions & 1 deletion src/windows/frames/frameContext.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-parameters */

/**
* Defines a context for window or tab events so they can get their widgets by name.
*/
Expand All @@ -18,4 +20,4 @@ export interface FrameContext
* Trigger a redraw check for the window or tab to be relayouted in the next tick.
*/
redraw(): void;
}
}
1 change: 1 addition & 0 deletions src/windows/frames/frameControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class FrameControl implements FrameContext, ParentControl<FramePosition,
};
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
getWidget<T extends Widget>(name: string): T | null
{
const activeWidgets = this._activeWidgets;
Expand Down
4 changes: 2 additions & 2 deletions src/windows/tabs/tabWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ export interface TabWindowParams extends BaseWindowParams


/**
* Create a new flexiblely designed window that has tabs. An arrow function can be used to create windows to fit a specific viewmodel.
* Create a new flexiblely designed window that has tabs.
*
* @example
* const template = tabwindow({ title: "Hello world!" })
*
* template.open()
*/
export function tabwindow(params: TabWindowParams): WindowTemplate<void>;
export function tabwindow(params: TabWindowParams): WindowTemplate;
/**
* Create a new flexiblely designed window that has tabs. An arrow function can be used to create windows to fit a specific viewmodel.
* *
Expand Down
4 changes: 2 additions & 2 deletions src/windows/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export interface WindowParams extends BaseWindowParams, FlexibleDirectionalLayou
*
* template.open()
*/
export function window(params: WindowParams): WindowTemplate<void>;
export function window(params: WindowParams): WindowTemplate;
/**
* Create a new flexiblely designed window with a viewmodel.
* Create a new flexiblely designed window with a viewmodel. An arrow function can be used to create windows to fit a specific viewmodel.
*
* @example
* class MyModel
Expand Down
2 changes: 1 addition & 1 deletion src/windows/windowTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { OpenWindow } from "./openWindow";
/**
* A fully created and compressed window template that can now be used.
*/
export interface WindowTemplate<TModel>
export interface WindowTemplate<TModel = void>
{
/**
* Opens this window on-screen with the specified details.
Expand Down
1 change: 0 additions & 1 deletion tests/bindings/isStore.tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/// <reference path="../../lib/openrct2.d.ts" />
import { compute } from "@src/bindings/stores/compute";
import { arrayStore } from "@src/bindings/stores/createArrayStore";
Expand Down
38 changes: 19 additions & 19 deletions tests/elements/controls/box.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ test("Standard properties are set", t =>
});
template.open();

const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget;
const widget1 = <GroupBoxWidget>mock.createdWindows[0].widgets[0];
t.is(widget1.type, "groupbox");
t.is(widget1.x, 4 + 7);
t.is(widget1.y, 4 + 7 + 15 - 4); // - 4px default top pad
t.is(widget1.width, 50 - 22);
t.is(widget1.height, (40 - 22) + 4); // + 4px default top pad

const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget;
const widget2 = <ButtonWidget>mock.createdWindows[0].widgets[1];
t.is(widget2.type, "button");
t.is(widget2.text, "inside a box!");
t.is(widget2.x, 4 + 7 + 6); // incl. 6px default padding
Expand Down Expand Up @@ -66,15 +66,15 @@ test("Title changes size and position", t =>
});
template.open();

const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget;
const widget1 = <GroupBoxWidget>mock.createdWindows[0].widgets[0];
t.is(widget1.type, "groupbox");
t.is(widget1.text, "title");
t.is(widget1.x, 4 + 7);
t.is(widget1.y, 4 + 7 + 15);
t.is(widget1.width, 50 - 22);
t.is(widget1.height, 80 - 22);

const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget;
const widget2 = <ButtonWidget>mock.createdWindows[0].widgets[1];
t.is(widget2.type, "button");
t.is(widget2.text, "inside a box!");
t.is(widget2.x, 4 + 7 + 6); // incl. 6px default padding
Expand Down Expand Up @@ -103,14 +103,14 @@ test("Applies padding", t =>
});
template.open();

const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget;
const widget1 = <GroupBoxWidget>mock.createdWindows[0].widgets[0];
t.is(widget1.type, "groupbox");
t.is(widget1.x, 10 + 3);
t.is(widget1.y, 10 + 3 + 15 - 4); // - 4px default top pad
t.is(widget1.width, 74);
t.is(widget1.height, 34 + 4); // + 4px default top pad

const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget;
const widget2 = <ButtonWidget>mock.createdWindows[0].widgets[1];
t.is(widget2.type, "button");
t.is(widget2.text, "inside a box!");
t.is(widget2.x, 10 + 3 + 6);
Expand Down Expand Up @@ -139,14 +139,14 @@ test("Box takes size of absolute child", t =>
});
template.open();

const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget;
const widget1 = <GroupBoxWidget>mock.createdWindows[0].widgets[0];
t.is(widget1.type, "groupbox");
t.is(widget1.x, 10);
t.is(widget1.y, 10 + 15 - 4); // - 4px default top pad
t.is(widget1.width, 120 + 24);
t.is(widget1.height, 70 + 24 + 4); // + 4px default top pad

const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget;
const widget2 = <ButtonWidget>mock.createdWindows[0].widgets[1];
t.is(widget2.type, "button");
t.is(widget2.text, "inside a box!");
t.is(widget2.x, 10 + 12);
Expand Down Expand Up @@ -174,14 +174,14 @@ test("Box can center child", t =>
});
template.open();

const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget;
const widget1 = <GroupBoxWidget>mock.createdWindows[0].widgets[0];
t.is(widget1.type, "groupbox");
t.is(widget1.x, 40);
t.is(widget1.y, 40 + 15 - 4);
t.is(widget1.width, 100);
t.is(widget1.height, 320 + 4);

const widget2 = mock.createdWindows[0].widgets[1] as ButtonWidget;
const widget2 = <ButtonWidget>mock.createdWindows[0].widgets[1];
t.is(widget2.type, "button");
t.is(widget2.text, "inside a box!");
t.is(widget2.x, 40);
Expand Down Expand Up @@ -212,15 +212,15 @@ test("Box reacts correctly to child size changes", t =>
});
template.open();

const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget;
const widget1 = <GroupBoxWidget>mock.createdWindows[0].widgets[0];
t.is(widget1.type, "groupbox");
t.is(widget1.x, 4);
t.is(widget1.y, 4 + 15 - 4); // - 4px default top pad
t.is(widget1.width, 100 - (2 * 4));
t.is(widget1.height, 14 + (2 * 6) + 4); // + 4px default top pad
t.not(false, widget1.isVisible);

const widget2 = mock.createdWindows[0].widgets[1] as LabelWidget;
const widget2 = <LabelWidget>mock.createdWindows[0].widgets[1];
t.is(widget2.type, "label");
t.is(widget2.text, "managing themes");
t.is(widget2.x, 4 + 6);
Expand Down Expand Up @@ -279,15 +279,15 @@ test("Box reacts correctly to nested child size changes", t =>
});
template.open();

const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget;
const widget1 = <GroupBoxWidget>mock.createdWindows[0].widgets[0];
t.is(widget1.type, "groupbox");
t.is(widget1.x, 20);
t.is(widget1.y, 20 + 15 - 4); // - 4px default top pad
t.is(widget1.width, 300 - (2 * 20));
t.is(widget1.height, 14 + (2 * 6) + 4); // + 4px default top pad
t.true(widget1.isVisible);

const widget2 = mock.createdWindows[0].widgets[1] as LabelWidget;
const widget2 = <LabelWidget>mock.createdWindows[0].widgets[1];
t.is(widget2.type, "label");
t.is(widget2.text, "managing themes");
t.is(widget2.x, 20 + 6);
Expand All @@ -296,7 +296,7 @@ test("Box reacts correctly to nested child size changes", t =>
t.is(widget2.height, 14);
t.true(widget2.isVisible);

const widget3 = mock.createdWindows[0].widgets[2] as ButtonWidget;
const widget3 = <ButtonWidget>mock.createdWindows[0].widgets[2];
t.is(widget3.type, "button");
t.is(widget3.x, 20);
t.is(widget3.y, 20 + (2 * 6) + 4 + 14 + 15);
Expand Down Expand Up @@ -363,9 +363,9 @@ test("Box does not take space if it starts hidden", t =>
});
template.open();

const widget1 = mock.createdWindows[0].widgets[0] as GroupBoxWidget;
const widget2 = mock.createdWindows[0].widgets[1] as LabelWidget;
const widget3 = mock.createdWindows[0].widgets[2] as ButtonWidget;
const widget1 = <GroupBoxWidget>mock.createdWindows[0].widgets[0];
const widget2 = <LabelWidget>mock.createdWindows[0].widgets[1];
const widget3 = <ButtonWidget>mock.createdWindows[0].widgets[2];

t.false(widget1.isVisible);
t.false(widget2.isVisible);
Expand Down Expand Up @@ -398,4 +398,4 @@ test("Box does not take space if it starts hidden", t =>
t.is(widget3.y, 20 + (2 * 6) + 4 + 14 + 15);
t.is(widget3.width, 300 - (2 * 20));
t.is(widget3.height, 25);
});
});
12 changes: 6 additions & 6 deletions tests/elements/controls/button.tests.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// <reference path="../../../lib/openrct2.d.ts" />

import { store } from "@src/bindings/stores/createStore";
import { window } from "@src/windows/window";
import { button } from "@src/elements/controls/button";
import { window } from "@src/windows/window";
import test from "ava";
import Mock from "openrct2-mocks";
import { call } from "tests/helpers";
Expand All @@ -21,7 +21,7 @@ test("Standard properties are set", t =>
});
template.open();

const widget = mock.createdWindows[0].widgets[0] as ButtonWidget;
const widget = <ButtonWidget>mock.createdWindows[0].widgets[0];
t.is(widget.type, "button");
t.is(widget.text, "Click me!");
t.true(widget.isPressed);
Expand All @@ -43,7 +43,7 @@ test("Text is bindable", t =>
});
template.open();

const widget = mock.createdWindows[0].widgets[0] as ButtonWidget;
const widget = <ButtonWidget>mock.createdWindows[0].widgets[0];
t.is(widget.text, "bonjour");

text.set("annyeong");
Expand All @@ -65,7 +65,7 @@ test("Image is bindable", t =>
});
template.open();

const widget = mock.createdWindows[0].widgets[0] as ButtonWidget;
const widget = <ButtonWidget>mock.createdWindows[0].widgets[0];
t.is(widget.image, 334);

image.set(543);
Expand All @@ -87,7 +87,7 @@ test("Is pressed is bindable", t =>
});
template.open();

const widget = mock.createdWindows[0].widgets[0] as ButtonWidget;
const widget = <ButtonWidget>mock.createdWindows[0].widgets[0];
t.false(widget.isPressed);

pressed.set(true);
Expand All @@ -109,7 +109,7 @@ test("Click event gets called", t =>
});
template.open();

const widget = mock.createdWindows[0].widgets[0] as ButtonDesc;
const widget = <ButtonDesc>mock.createdWindows[0].widgets[0];
t.is(count, 0);

call(widget.onClick);
Expand Down
Loading

0 comments on commit 64c8be9

Please sign in to comment.