Skip to content

Visualize Your Ideas With Code

build: improve eslint configuration (#757)

Jacob927943f094f3
diff --git a/.eslintrc.json b/.eslintrc.json
index 777a6ad0..f2492f59 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -18,6 +18,9 @@
"plugins": ["@typescript-eslint", "eslint-plugin-tsdoc"],
"rules": {
"require-yield": "off",
+ "grouped-accessor-pairs": ["error", "getBeforeSet"],
+ "eqeqeq": ["error", "always", {"null": "ignore"}],
+ "curly": ["error", "multi-line"],
"@typescript-eslint/explicit-member-accessibility": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
diff --git a/packages/2d/src/curves/ArcSegment.ts b/packages/2d/src/curves/ArcSegment.ts
index ecb727e9..75e0eb43 100644
--- a/packages/2d/src/curves/ArcSegment.ts
+++ b/packages/2d/src/curves/ArcSegment.ts
@@ -73,10 +73,12 @@ export class ArcSegment extends Segment {
const s = pAccent.scale(-1).sub(cAccent).div(radius);
this.startAngle = q.radians;
this.deltaAngle = Vector2.angleBetween(q, s) % (Math.PI * 2);
- if (this.sweepFlag === 0 && this.deltaAngle > 0)
+ if (this.sweepFlag === 0 && this.deltaAngle > 0) {
this.deltaAngle -= Math.PI * 2;
- if (this.sweepFlag === 1 && this.deltaAngle < 0)
+ }
+ if (this.sweepFlag === 1 && this.deltaAngle < 0) {
this.deltaAngle += Math.PI * 2;
+ }
ArcSegment.el.setAttribute(
'd',
@@ -134,9 +136,9 @@ export class ArcSegment extends Segment {
const tangent = this.getAngleDerivative(angle).normalized;
return {
position:
- distance == 0
+ distance === 0
? this.startPoint
- : distance == 1
+ : distance === 1
? this.endPoint
: this.getAnglePosition(angle),
tangent,
diff --git a/packages/2d/src/curves/createCurveProfileLerp.ts b/packages/2d/src/curves/createCurveProfileLerp.ts
index 8e1c75fb..1daaa58c 100644
--- a/packages/2d/src/curves/createCurveProfileLerp.ts
+++ b/packages/2d/src/curves/createCurveProfileLerp.ts
@@ -119,7 +119,7 @@ function approximatePolygonPoints(
*/
function splitCurve(curve: CurveProfile) {
- if (curve.segments.length == 0) return [];
+ if (curve.segments.length === 0) return [];
let current: SubcurveProfile = {
arcLength: 0,
diff --git a/packages/2d/src/utils/CanvasUtils.ts b/packages/2d/src/utils/CanvasUtils.ts
index 1082064f..fa8ff541 100644
--- a/packages/2d/src/utils/CanvasUtils.ts
+++ b/packages/2d/src/utils/CanvasUtils.ts
@@ -172,7 +172,7 @@ export function drawPolygon(
const theta = (i * 2 * Math.PI) / sides;
const direction = Vector2.fromRadians(theta).perpendicular;
const vertex = direction.mul(size);
- if (i == 0) {
+ if (i === 0) {
moveTo(path, vertex);
} else {
lineTo(path, vertex);
diff --git a/packages/core/src/events/ValueDispatcher.ts b/packages/core/src/events/ValueDispatcher.ts
index 257a7f35..6a80b71e 100644
--- a/packages/core/src/events/ValueDispatcher.ts
+++ b/packages/core/src/events/ValueDispatcher.ts
@@ -34,6 +34,13 @@ export class ValueDispatcher<T> extends EventDispatcherBase<T> {
public readonly subscribable: SubscribableValueEvent<T> =
new SubscribableValueEvent(this);
+ /**
+ * {@inheritDoc SubscribableValueEvent.current}
+ */
+ public get current() {
+ return this.value;
+ }
+
/**
* Set the current value of this dispatcher.
*
@@ -47,13 +54,6 @@ export class ValueDispatcher<T> extends EventDispatcherBase<T> {
this.notifySubscribers(value);
}
- /**
- * {@inheritDoc SubscribableValueEvent.current}
- */
- public get current() {
- return this.value;
- }
-
/**
* @param value - The initial value.
*/
diff --git a/packages/core/src/tweening/interpolationFunctions.ts b/packages/core/src/tweening/interpolationFunctions.ts
index a4cfb091..39fc13a2 100644
--- a/packages/core/src/tweening/interpolationFunctions.ts
+++ b/packages/core/src/tweening/interpolationFunctions.ts
@@ -86,7 +86,7 @@ export function deepLerp(
if (value === 0) return from;
if (value === 1) return to;
- if (from == undefined || to == undefined) {
+ if (from == null || to == null) {
if (!suppressWarnings) {
useLogger().warn(
`Attempting to lerp ${from} -> ${to} may result in unexpected behavior.`,
diff --git a/packages/core/src/types/Matrix2D.ts b/packages/core/src/types/Matrix2D.ts
index f25b15aa..caa15969 100644
--- a/packages/core/src/types/Matrix2D.ts
+++ b/packages/core/src/types/Matrix2D.ts
@@ -43,13 +43,11 @@ export class Matrix2D implements Type {
return Matrix2D.identity.rotate(angle);
}
- public static fromTranslation(
- translation: PossibleVector2<number>,
- ): Matrix2D {
+ public static fromTranslation(translation: PossibleVector2): Matrix2D {
return Matrix2D.identity.translate(new Vector2(translation));
}
- public static fromScaling(scale: PossibleVector2<number>): Matrix2D {
+ public static fromScaling(scale: PossibleVector2): Matrix2D {
return Matrix2D.identity.scale(new Vector2(scale));
}
@@ -61,52 +59,56 @@ export class Matrix2D implements Type {
return new Vector2(this.values[2], this.values[3]);
}
+ public get scaleX(): number {
+ return this.values[0];
+ }
+
public set scaleX(value: number) {
this.values[0] = this.x.normalized.scale(value).x;
}
- public get scaleX(): number {
- return this.values[0];
+ public get skewX(): number {
+ return this.values[1];
}
public set skewX(value: number) {
this.values[1] = value;
}
- public get skewX(): number {
- return this.values[1];
+ public get scaleY(): number {
+ return this.values[3];
}
public set scaleY(value: number) {
this.values[3] = this.y.normalized.scale(value).y;
}
- public get scaleY(): number {
- return this.values[3];
+ public get skewY(): number {
+ return this.values[2];
}
public set skewY(value: number) {
this.values[2] = value;
}
- public get skewY(): number {
- return this.values[2];
+ public get translateX(): number {
+ return this.values[4];
}
public set translateX(value: number) {
this.values[4] = value;
}
- public get translateX(): number {
- return this.values[4];
+ public get translateY(): number {
+ return this.values[5];
}
public set translateY(value: number) {
this.values[5] = value;
}
- public get translateY(): number {
- return this.values[5];
+ public get rotation(): number {
+ return Vector2.degrees(this.values[0], this.values[1]);
}
public set rotation(angle: number) {
@@ -118,8 +120,8 @@ export class Matrix2D implements Type {
this.values[3] = result.values[3];
}
- public get rotation(): number {
- return Vector2.degrees(this.values[0], this.values[1]);
+ public get translation(): Vector2 {
+ return new Vector2(this.values[4], this.values[5]);
}
public set translation(translation: PossibleVector2) {
@@ -128,11 +130,11 @@ export class Matrix2D implements Type {
this.values[5] = vec.y;
}
- public get translation(): Vector2 {
- return new Vector2(this.values[4], this.values[5]);
+ public get scaling(): Vector2 {
+ return new Vector2(this.values[0], this.values[3]);
}
- public set scaling(value: PossibleVector2<number>) {
+ public set scaling(value: PossibleVector2) {
const scale = new Vector2(value);
const x = new Vector2(this.values[0], this.values[1]).normalized;
@@ -144,10 +146,6 @@ export class Matrix2D implements Type {
this.values[3] = y.y * scale.y;
}
- public get scaling(): Vector2 {
- return new Vector2(this.values[0], this.values[3]);
- }
-
/**
* Get the inverse of the matrix.
*
@@ -218,9 +216,9 @@ export class Matrix2D implements Type {
public constructor();
public constructor(matrix: PossibleMatrix2D);
public constructor(
- x: PossibleVector2<number>,
- y: PossibleVector2<number>,
- z: PossibleVector2<number>,
+ x: PossibleVector2,
+ y: PossibleVector2,
+ z: PossibleVector2,
);
public constructor(
a: number,
@@ -231,9 +229,9 @@ export class Matrix2D implements Type {
ty: number,
);
public constructor(
- a?: PossibleMatrix2D | PossibleVector2<number>,
- b?: PossibleVector2<number>,
- c?: PossibleVector2<number>,
+ a?: PossibleMatrix2D | PossibleVector2,
+ b?: PossibleVector2,
+ c?: PossibleVector2,
d?: number,
tx?: number,
ty?: number,
@@ -301,7 +299,7 @@ export class Matrix2D implements Type {
return;
}
- const x = new Vector2(a as PossibleVector2<number>);
+ const x = new Vector2(a as PossibleVector2);
const y = new Vector2(b);
const z = new Vector2(c);
this.values[0] = x.x;
diff --git a/packages/docs/src/components/Fiddle/autocomplete.ts b/packages/docs/src/components/Fiddle/autocomplete.ts
index 31043645..2b9417e7 100644
--- a/packages/docs/src/components/Fiddle/autocomplete.ts
+++ b/packages/docs/src/components/Fiddle/autocomplete.ts
@@ -41,7 +41,7 @@ export function autocomplete() {
if (nodeBefore.name === 'String') return;
const word = context.matchBefore(/\w*/);
- if (word.from == word.to && !context.explicit) return null;
+ if (word.from === word.to && !context.explicit) return null;
return {
from: word.from,
options: Options,
diff --git a/packages/ui/src/utils/withLoader.ts b/packages/ui/src/utils/withLoader.ts
index 06d09359..88aadaf3 100644
--- a/packages/ui/src/utils/withLoader.ts
+++ b/packages/ui/src/utils/withLoader.ts
@@ -12,7 +12,7 @@ export async function withLoader(callback: () => Promise<unknown>) {
await callback();
} finally {
LoaderCount--;
- if (LoaderCount == 0) {
+ if (LoaderCount === 0) {
document.body.classList.remove('wait');
}
}
diff --git a/packages/vite-plugin/src/proxy-middleware.ts b/packages/vite-plugin/src/proxy-middleware.ts
index e33ad84a..1f9b37ae 100644
--- a/packages/vite-plugin/src/proxy-middleware.ts
+++ b/packages/vite-plugin/src/proxy-middleware.ts
@@ -160,7 +160,7 @@ function isReceivedUrlInAllowedHosts(
hostname: string,
allowListHosts: string[] | undefined,
) {
- if (!allowListHosts || allowListHosts.length == 0) {
+ if (!allowListHosts || allowListHosts.length === 0) {
// if the allowListHosts is just the predefinedAllowlist, the user has not
// set any additional hosts. In this case, allow any hostname
return true;
@@ -236,7 +236,7 @@ async function tryGetResource(
res(data);
});
request.on('error', (err: any) => {
- if (err.code && err.code == 'ENOTFOUND') {
+ if (err.code && err.code === 'ENOTFOUND') {
// This is a bit hacky, but this basically returns as a
// 404 instead of crashing the Node Server with ENOTFOUND
res({statusCode: 404} as any);