Skip to content

Commit

Permalink
build: enable more strict ESLint ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 authored Aug 28, 2024
1 parent 09e8675 commit f12d90f
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 22 deletions.
19 changes: 18 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import eslintPluginPrettier from "eslint-plugin-prettier/recommended";

export default tseslint.config({
files: ["**/*.ts"],
extends: [eslint.configs.recommended, ...tseslint.configs.strict, ...tseslint.configs.stylistic, eslintPluginPrettier],
extends: [
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
eslintPluginPrettier,
],
rules: {
"@typescript-eslint/no-unused-vars": [
"error",
Expand All @@ -20,11 +25,23 @@ export default tseslint.config({
ignoreRestSiblings: true,
},
],
"@typescript-eslint/restrict-template-expressions": [
"error",
{
allowNumber: true,
},
],
"prettier/prettier": [
"error",
{
endOfLine: "auto",
},
],
},
languageOptions: {
parserOptions: {
projectService: true,
tsconfigDirName: import.meta.dirname,
},
},
});
8 changes: 4 additions & 4 deletions src/cookies/basket-adder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ export class BasketAdder {
status: addProductResponse.status,
body: data,
}))
.catch((_) => ({
.catch((_: unknown) => ({
success: false,
status: addProductResponse.status,
body: null,
retryAfterHeader: addProductResponse.headers.get("Retry-After"),
})),
)
.catch((_) => ({ success: false, status: -2, body: null })),
.catch((_: unknown) => ({ success: false, status: -2, body: null })),
this.store,
id,
v4(),
Expand All @@ -168,8 +168,8 @@ export class BasketAdder {

if (res.success) {
try {
const basketCookie = (await this.browserManager.page.cookies()).filter((cookie) => cookie.name === "r")[0];
if (basketCookie.value) {
const basketCookie = (await this.browserManager.page.cookies()).find((cookie) => cookie.name === "r");
if (basketCookie) {
cookies.push(basketCookie.value);
this.logger.info(
`Made cookie ${basketCookie.value} for product ${id}: ${this.store.baseUrl}?cookie=${basketCookie.value}`,
Expand Down
11 changes: 6 additions & 5 deletions src/core/browser-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ export class BrowserManager {
loginResponse
.json()
.then((data: LoginResponse) => ({ status: loginResponse.status, body: data }))
.catch((_) => ({
.catch((_: unknown) => ({
status: loginResponse.status,
body: null,
retryAfterHeader: loginResponse.headers.get("Retry-After"),
})),
)
.catch((_) => ({ status: -2, body: null })),
.catch((_: unknown) => ({ status: -2, body: null })),
this.store,
email,
password,
Expand Down Expand Up @@ -235,13 +235,13 @@ export class BrowserManager {
loginResponse
.json()
.then((data: LoginResponse) => ({ status: loginResponse.status, body: data }))
.catch((_) => ({
.catch((_: unknown) => ({
status: loginResponse.status,
body: null,
retryAfterHeader: loginResponse.headers.get("Retry-After"),
})),
)
.catch((_) => ({ status: -2, body: null })),
.catch((_: unknown) => ({ status: -2, body: null })),
this.store,
email,
password,
Expand Down Expand Up @@ -423,10 +423,11 @@ export class BrowserManager {
Object.defineProperty(HTMLDivElement.prototype, "offsetHeight", {
...elementDescriptor,
get: function () {
if (this.id === "modernizr") {
if ((this as HTMLElement).id === "modernizr") {
return 1;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return elementDescriptor?.get?.apply(this);
},
});
Expand Down
8 changes: 6 additions & 2 deletions src/core/cooldown-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ export class CooldownManager {
constructor(storeConfig: StoreConfiguration) {
if (existsSync("basket-cooldowns.json")) {
try {
this.basketCooldowns = new Map(JSON.parse(readFileSync("basket-cooldowns.json", "utf-8")));
this.basketCooldowns = new Map(
JSON.parse(readFileSync("basket-cooldowns.json", "utf-8")) as Iterable<readonly [string, NotificationCooldown]>,
);
} catch {
this.basketCooldowns = new Map<string, NotificationCooldown>();
}
}

if (existsSync("cooldowns.json")) {
try {
this.cooldowns = new Map(JSON.parse(readFileSync("cooldowns.json", "utf-8")));
this.cooldowns = new Map(
JSON.parse(readFileSync("cooldowns.json", "utf-8")) as Iterable<readonly [string, NotificationCooldown]>,
);
} catch {
this.cooldowns = new Map<string, NotificationCooldown>();
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ void (async function () {
const wishlistRaceTimeout = 60000;
const loginRaceTimeout = 30000;

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (shouldRun) {
try {
logger.info("🤖 Beep, I'm alive and well checking your stock");
Expand Down
6 changes: 2 additions & 4 deletions src/notifiers/discord-notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,11 @@ export class DiscordNotifier implements Notifier {
},
]);
if (this.showMagicianLink) {
embed.addFields([
{ name: "Magician", value: `${this.productHelper.getProductURL(item, this.store, this.replacements, true)}` },
]);
embed.addFields([{ name: "Magician", value: this.productHelper.getProductURL(item, this.store, this.replacements, true) }]);
}
if (this.showCookiesAmount) {
embed.addFields([
{ name: "Cookies", value: cookiesAmount ? `${cookiesAmount} 🍪` : `${this.noCookieEmoji ?? "👎"}`, inline: true },
{ name: "Cookies", value: cookiesAmount ? `${cookiesAmount} 🍪` : (this.noCookieEmoji ?? "👎"), inline: true },
]);
}
embed.addFields([{ name: "Availability State", value: item.availability.delivery?.availabilityType ?? "UNKNOWN", inline: true }]);
Expand Down
8 changes: 6 additions & 2 deletions src/stock-checkers/category-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ export class CategoryChecker {
res
.json()
.then((data: CategoryResponse) => ({ status: res.status, body: data }))
.catch((_) => ({ status: res.status, body: null, retryAfterHeader: res.headers.get("Retry-After") })),
.catch((_: unknown) => ({
status: res.status,
body: null,
retryAfterHeader: res.headers.get("Retry-After"),
})),
)
.catch((_) => ({ status: -2, body: null })),
.catch((_: unknown) => ({ status: -2, body: null })),
this.store,
page,
category,
Expand Down
8 changes: 6 additions & 2 deletions src/stock-checkers/search-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,13 @@ export class SearchChecker {
res
.json()
.then((data: SearchResponse) => ({ status: res.status, body: data }))
.catch((_) => ({ status: res.status, body: null, retryAfterHeader: res.headers.get("Retry-After") })),
.catch((_: unknown) => ({
status: res.status,
body: null,
retryAfterHeader: res.headers.get("Retry-After"),
})),
)
.catch((_) => ({ status: -2, body: null })),
.catch((_: unknown) => ({ status: -2, body: null })),
this.store,
page,
searchQuery,
Expand Down
8 changes: 6 additions & 2 deletions src/stock-checkers/wishlist-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@ export class WishlistChecker {
res
.json()
.then((data: WishlistResponse) => ({ status: res.status, body: data }))
.catch((_) => ({ status: res.status, body: null, retryAfterHeader: res.headers.get("Retry-After") })),
.catch((_: unknown) => ({
status: res.status,
body: null,
retryAfterHeader: res.headers.get("Retry-After"),
})),
)
.catch((_) => ({ status: -2, body: null })),
.catch((_: unknown) => ({ status: -2, body: null })),
this.store,
offset,
v4(),
Expand Down

0 comments on commit f12d90f

Please sign in to comment.