From 88abd53faffb9731998b762651f5327d7fe52768 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Mon, 18 Mar 2024 00:27:57 -0500 Subject: [PATCH] Update eslint and prettier --- .eslintignore | 1 + .eslintrc.cjs | 23 +++++++----- package.json | 11 +++--- src/data/projInfo.json | 2 +- src/features/achievements/achievement.tsx | 5 ++- src/features/action.tsx | 3 +- src/features/challenges/challenge.tsx | 3 +- src/features/repeatable.tsx | 3 +- src/features/upgrades/upgrade.ts | 3 +- src/game/formulas/formulas.ts | 1 + src/game/persistence.ts | 3 +- src/game/player.ts | 12 +++---- src/game/requirements.tsx | 11 +++--- src/util/break_eternity.ts | 4 +-- src/util/common.ts | 6 ++-- src/util/computed.ts | 8 ++--- src/util/proxies.ts | 44 ++++++++++++----------- src/util/vue.tsx | 11 +++--- 18 files changed, 81 insertions(+), 73 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..cf64a52 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +.eslintrc.cjs diff --git a/.eslintrc.cjs b/.eslintrc.cjs index f7aac50..49ae23d 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -5,15 +5,22 @@ module.exports = { env: { node: true }, - extends: [ - "plugin:vue/vue3-essential", - "@vue/eslint-config-typescript/recommended", - "@vue/eslint-config-prettier" + parser: '@typescript-eslint/parser', + plugins: ["@typescript-eslint"], + overrides: [ + { + files: ['*.ts', '*.tsx'], + extends: [ + "plugin:vue/vue3-essential", + "@vue/eslint-config-typescript/recommended", + "@vue/eslint-config-prettier" + ], + parserOptions: { + ecmaVersion: 2020, + project: "./tsconfig.json" + }, + } ], - parserOptions: { - ecmaVersion: 2020, - project: "tsconfig.json" - }, ignorePatterns: ["src/lib"], rules: { "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", diff --git a/package.json b/package.json index 255db77..03a952d 100644 --- a/package.json +++ b/package.json @@ -43,13 +43,14 @@ }, "devDependencies": { "@ivanv/vue-collapse-transition": "^1.0.2", - "@rushstack/eslint-patch": "^1.1.0", + "@rushstack/eslint-patch": "^1.7.2", "@types/lz-string": "^1.5.0", - "@vue/eslint-config-prettier": "^7.0.0", - "@vue/eslint-config-typescript": "^10.0.0", - "eslint": "^8.6.0", + "@typescript-eslint/parser": "^7.2.0", + "@vue/eslint-config-prettier": "^9.0.0", + "@vue/eslint-config-typescript": "^13.0.0", + "eslint": "^8.57.0", "jsdom": "^24.0.0", - "prettier": "^2.5.1", + "prettier": "^3.2.5", "typescript": "^5.4.2", "vitest": "^1.4.0", "vue-tsc": "^2.0.6" diff --git a/src/data/projInfo.json b/src/data/projInfo.json index 6618d79..9b2df97 100644 --- a/src/data/projInfo.json +++ b/src/data/projInfo.json @@ -3,7 +3,7 @@ "title": "Profectus", "description": "A project made in Profectus", - "id": "", + "id": "321", "author": "", "discordName": "", "discordLink": "", diff --git a/src/features/achievements/achievement.tsx b/src/features/achievements/achievement.tsx index 1efdc9b..b298aa5 100644 --- a/src/features/achievements/achievement.tsx +++ b/src/features/achievements/achievement.tsx @@ -1,5 +1,4 @@ -import { computed } from "@vue/reactivity"; -import { isArray } from "@vue/shared"; +import { computed } from "vue"; import Select from "components/fields/Select.vue"; import AchievementComponent from "features/achievements/Achievement.vue"; import { GenericDecorator } from "features/decorators/common"; @@ -275,7 +274,7 @@ export function createAchievement( const requirements = [ createVisibilityRequirement(genericAchievement), createBooleanRequirement(() => !genericAchievement.earned.value), - ...(isArray(achievement.requirements) + ...(Array.isArray(achievement.requirements) ? achievement.requirements : [achievement.requirements]) ]; diff --git a/src/features/action.tsx b/src/features/action.tsx index 2b08e08..c0e32bc 100644 --- a/src/features/action.tsx +++ b/src/features/action.tsx @@ -1,4 +1,3 @@ -import { isArray } from "@vue/shared"; import ClickableComponent from "features/clickables/Clickable.vue"; import { Component, @@ -157,7 +156,7 @@ export function createAction( } ]; const originalStyle = unref(style); - if (isArray(originalStyle)) { + if (Array.isArray(originalStyle)) { currStyle.push(...originalStyle); } else if (originalStyle != null) { currStyle.push(originalStyle); diff --git a/src/features/challenges/challenge.tsx b/src/features/challenges/challenge.tsx index 8d4d881..c04c93c 100644 --- a/src/features/challenges/challenge.tsx +++ b/src/features/challenges/challenge.tsx @@ -1,4 +1,3 @@ -import { isArray } from "@vue/shared"; import Toggle from "components/fields/Toggle.vue"; import ChallengeComponent from "features/challenges/Challenge.vue"; import { GenericDecorator } from "features/decorators/common"; @@ -348,7 +347,7 @@ export function createActiveChallenge( export function isAnyChallengeActive( challenges: GenericChallenge[] | Ref ): Ref { - if (isArray(challenges)) { + if (Array.isArray(challenges)) { challenges = createActiveChallenge(challenges); } return computed(() => (challenges as Ref).value != null); diff --git a/src/features/repeatable.tsx b/src/features/repeatable.tsx index e82f8eb..2c9e73b 100644 --- a/src/features/repeatable.tsx +++ b/src/features/repeatable.tsx @@ -1,4 +1,3 @@ -import { isArray } from "@vue/shared"; import ClickableComponent from "features/clickables/Clickable.vue"; import type { CoercableComponent, @@ -162,7 +161,7 @@ export function createRepeatable( canMaximize: true } as const; const visibilityRequirement = createVisibilityRequirement(repeatable as GenericRepeatable); - if (isArray(repeatable.requirements)) { + if (Array.isArray(repeatable.requirements)) { repeatable.requirements.unshift(visibilityRequirement); repeatable.requirements.push(limitRequirement); } else { diff --git a/src/features/upgrades/upgrade.ts b/src/features/upgrades/upgrade.ts index 9ff9b28..a3075e7 100644 --- a/src/features/upgrades/upgrade.ts +++ b/src/features/upgrades/upgrade.ts @@ -1,4 +1,3 @@ -import { isArray } from "@vue/shared"; import { GenericDecorator } from "features/decorators/common"; import type { CoercableComponent, @@ -151,7 +150,7 @@ export function createUpgrade( }; const visibilityRequirement = createVisibilityRequirement(upgrade as GenericUpgrade); - if (isArray(upgrade.requirements)) { + if (Array.isArray(upgrade.requirements)) { upgrade.requirements.unshift(visibilityRequirement); } else { upgrade.requirements = [visibilityRequirement, upgrade.requirements]; diff --git a/src/game/formulas/formulas.ts b/src/game/formulas/formulas.ts index ac1145f..d9b0a78 100644 --- a/src/game/formulas/formulas.ts +++ b/src/game/formulas/formulas.ts @@ -48,6 +48,7 @@ export interface InternalFormula { invertIntegral?(value: DecimalSource): DecimalSource; } +// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging export abstract class InternalFormula { readonly inputs: T; diff --git a/src/game/persistence.ts b/src/game/persistence.ts index 4e7704d..253481e 100644 --- a/src/game/persistence.ts +++ b/src/game/persistence.ts @@ -1,4 +1,3 @@ -import { isArray } from "@vue/shared"; import { globalBus } from "game/events"; import type { GenericLayer } from "game/layers"; import { addingLayers, persistentRefs } from "game/layers"; @@ -341,7 +340,7 @@ globalBus.on("addLayer", (layer: GenericLayer, saveData: Record // Show warning for persistent values inside arrays // TODO handle arrays better if (foundPersistentInChild) { - if (isArray(value) && !isArray(obj)) { + if (Array.isArray(value) && !Array.isArray(obj)) { console.warn( "Found array that contains persistent values when adding layer. Keep in mind changing the order of elements in the array will mess with existing player saves.", ProxyState in obj diff --git a/src/game/player.ts b/src/game/player.ts index 322e4db..e447656 100644 --- a/src/game/player.ts +++ b/src/game/player.ts @@ -36,12 +36,12 @@ export type LayerData = { [P in keyof T]?: T[P] extends (infer U)[] ? Record> : T[P] extends Record - ? never - : T[P] extends Ref - ? S - : T[P] extends object - ? LayerData - : T[P]; + ? never + : T[P] extends Ref + ? S + : T[P] extends object + ? LayerData + : T[P]; }; const player = reactive({ diff --git a/src/game/requirements.tsx b/src/game/requirements.tsx index 14cec2b..195efa8 100644 --- a/src/game/requirements.tsx +++ b/src/game/requirements.tsx @@ -1,4 +1,3 @@ -import { isArray } from "@vue/shared"; import { CoercableComponent, isVisible, @@ -270,7 +269,7 @@ export function createBooleanRequirement( * @param requirements The 1+ requirements to check */ export function requirementsMet(requirements: Requirements): boolean { - if (isArray(requirements)) { + if (Array.isArray(requirements)) { return requirements.every(requirementsMet); } const reqsMet = unref(requirements.requirementMet); @@ -282,7 +281,7 @@ export function requirementsMet(requirements: Requirements): boolean { * @param requirements The 1+ requirements to check */ export function maxRequirementsMet(requirements: Requirements): DecimalSource { - if (isArray(requirements)) { + if (Array.isArray(requirements)) { return requirements.map(maxRequirementsMet).reduce(Decimal.min); } const reqsMet = unref(requirements.requirementMet); @@ -300,13 +299,13 @@ export function maxRequirementsMet(requirements: Requirements): DecimalSource { * @param amount The amount of levels earned to be displayed */ export function displayRequirements(requirements: Requirements, amount: DecimalSource = 1) { - if (isArray(requirements)) { + if (Array.isArray(requirements)) { requirements = requirements.filter(r => isVisible(r.visibility)); if (requirements.length === 1) { requirements = requirements[0]; } } - if (isArray(requirements)) { + if (Array.isArray(requirements)) { requirements = requirements.filter(r => "partialDisplay" in r); const withCosts = requirements.filter(r => unref(r.requiresPay)); const withoutCosts = requirements.filter(r => !unref(r.requiresPay)); @@ -344,7 +343,7 @@ export function displayRequirements(requirements: Requirements, amount: DecimalS * @param amount How many levels to pay for */ export function payRequirements(requirements: Requirements, amount: DecimalSource = 1) { - if (isArray(requirements)) { + if (Array.isArray(requirements)) { requirements.filter(r => unref(r.requiresPay)).forEach(r => r.pay?.(amount)); } else if (unref(requirements.requiresPay)) { requirements.pay?.(amount); diff --git a/src/util/break_eternity.ts b/src/util/break_eternity.ts index 6734ece..75cfc4d 100644 --- a/src/util/break_eternity.ts +++ b/src/util/break_eternity.ts @@ -16,8 +16,8 @@ export function exponentialFormat(num: DecimalSource, precision: number, mantiss const eString = e.gte(1e9) ? format(e, Math.max(Math.max(precision, 3), projInfo.defaultDecimalsShown)) : e.gte(10000) - ? commaFormat(e, 0) - : e.toStringWithDecimalPlaces(0); + ? commaFormat(e, 0) + : e.toStringWithDecimalPlaces(0); if (mantissa) { return m.toStringWithDecimalPlaces(precision) + "e" + eString; } else { diff --git a/src/util/common.ts b/src/util/common.ts index 00847e6..ede303a 100644 --- a/src/util/common.ts +++ b/src/util/common.ts @@ -8,9 +8,8 @@ export type OptionalKeys = { export type OmitOptional = Pick>; export type WithRequired = T & { [P in K]-?: T[P] }; -export type ArrayElements> = T extends ReadonlyArray - ? S - : never; +export type ArrayElements> = + T extends ReadonlyArray ? S : never; // Reference: // https://stackoverflow.com/questions/7225407/convert-camelcasetext-to-sentence-case-text @@ -36,5 +35,6 @@ export enum Direction { Down = "Down", Left = "Left", Right = "Right", + // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values Default = "Up" } diff --git a/src/util/computed.ts b/src/util/computed.ts index 8a9ad62..ff11103 100644 --- a/src/util/computed.ts +++ b/src/util/computed.ts @@ -10,10 +10,10 @@ export type ProcessedComputable = T | Ref; export type GetComputableType = T extends { [DoNotCache]: true } ? T : T extends () => infer S - ? Ref - : undefined extends T - ? undefined - : T; + ? Ref + : undefined extends T + ? undefined + : T; export type GetComputableTypeWithDefault = undefined extends T ? S : GetComputableType>; diff --git a/src/util/proxies.ts b/src/util/proxies.ts index ed5d4ac..7476ba1 100644 --- a/src/util/proxies.ts +++ b/src/util/proxies.ts @@ -5,28 +5,30 @@ import Decimal from "util/bignum"; export const ProxyState = Symbol("ProxyState"); export const ProxyPath = Symbol("ProxyPath"); -export type ProxiedWithState = NonNullable extends Record - ? NonNullable extends Decimal - ? T - : { - [K in keyof T]: ProxiedWithState; - } & { - [ProxyState]: T; - [ProxyPath]: string[]; - } - : T; +export type ProxiedWithState = + NonNullable extends Record + ? NonNullable extends Decimal + ? T + : { + [K in keyof T]: ProxiedWithState; + } & { + [ProxyState]: T; + [ProxyPath]: string[]; + } + : T; -export type Proxied = NonNullable extends Record - ? NonNullable extends Persistent - ? NonPersistent - : NonNullable extends Decimal - ? T - : { - [K in keyof T]: Proxied; - } & { - [ProxyState]: T; - } - : T; +export type Proxied = + NonNullable extends Record + ? NonNullable extends Persistent + ? NonPersistent + : NonNullable extends Decimal + ? T + : { + [K in keyof T]: Proxied; + } & { + [ProxyState]: T; + } + : T; // Takes a function that returns an object and pretends to be that object // Note that the object is lazily calculated diff --git a/src/util/vue.tsx b/src/util/vue.tsx index 767ba52..e19eb31 100644 --- a/src/util/vue.tsx +++ b/src/util/vue.tsx @@ -245,8 +245,11 @@ export function trackHover(element: VueFeature): Ref { } export function kebabifyObject(object: Record) { - return Object.keys(object).reduce((acc, curr) => { - acc[camelToKebab(curr)] = object[curr]; - return acc; - }, {} as Record); + return Object.keys(object).reduce( + (acc, curr) => { + acc[camelToKebab(curr)] = object[curr]; + return acc; + }, + {} as Record + ); }