Rework how the linting is done

This commit is contained in:
Taevas 2025-02-16 17:05:02 +01:00
parent 51091d6d59
commit 96911a8d95
30 changed files with 111 additions and 108 deletions

18
.github/workflows/lint.yml vendored Normal file
View file

@ -0,0 +1,18 @@
name: Lint the code
on:
push:
branches:
- "**"
pull_request:
branches:
- "**"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- name: Install modules
run: bun
- name: Run ESLint
run: bun lint

BIN
bun.lockb

Binary file not shown.

View file

@ -1,28 +1,29 @@
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import react from "eslint-plugin-react";
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import stylisticTs from "@stylistic/eslint-plugin-ts";
/**
* Rules to consider:
*
* "@typescript-eslint/no-unsafe-assignment": "off",
* "@typescript-eslint/dot-notation": "off",
*/
import stylistic from "@stylistic/eslint-plugin";
export default tseslint.config(
pluginReactConfig,
react.configs.flat.recommended,
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname
}
}
},
{
plugins: {
"@stylistic/ts": stylisticTs,
react,
"@stylistic": stylistic,
},
rules: {
"@stylistic/ts/quotes": ["error", "double"],
"@stylistic/ts/indent": ["error", 2],
"@stylistic/quotes": ["error", "double"],
"@stylistic/indent": ["error", 2],
"@stylistic/semi": ["error", "always"],
"react/no-unescaped-entities": "off",
}
},

View file

@ -6,7 +6,6 @@ const handler: Handler = async () => {
method: "POST",
headers: {
"Content-Type": "application/json",
// eslint-disable-next-line @typescript-eslint/naming-convention
"Accept": "application/json",
},
body: JSON.stringify({

View file

@ -7,12 +7,10 @@ const handler: Handler = async () => {
headers: {
"PRIVATE-TOKEN": process.env.API_GITLAB!,
"Content-Type": "application/json",
// eslint-disable-next-line @typescript-eslint/naming-convention
"Accept": "application/json",
},
});
// eslint-disable-next-line @typescript-eslint/naming-convention
const {created_at} = (await gitlab.json() as Record<string, any>)[0];
if (typeof created_at !== "string") {
return {

View file

@ -31,7 +31,7 @@ const handler: Handler = async () => {
emojis: details.user.emojis,
text: details.text,
date: details.createdAt
}
};
return {
statusCode: 200,

View file

@ -5,14 +5,14 @@ import {type LastfmInfo} from "../../src/components/Info/Music/Lastfm.js";
const handler: Handler = async () => {
const lastfm = await api<{
recenttracks: {
track: Array<{
track: {
artist: {
"#text": string;
};
image: Array<{
image: {
size: string;
"#text": string;
}>;
}[];
album: {
"#text": string;
};
@ -25,7 +25,7 @@ const handler: Handler = async () => {
uts: string;
"#text": string;
};
}>;
}[];
};
}>(`http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=TTTaevas&api_key=${process.env.API_LASTFM}&format=json&limit=1`);
const image = lastfm.recenttracks.track[0].image.find((i) => i.size == "large");

View file

@ -13,7 +13,6 @@ const handler: Handler = async () => {
const token = await collection.findOne();
void client.close();
// eslint-disable-next-line @typescript-eslint/naming-convention
const api = new osu.API({access_token: token?.access_token});
const profile = await api.getUser(7276846, osu.Ruleset.fruits);

View file

@ -13,7 +13,6 @@ const handler: Handler = async () => {
const token = await collection.findOne();
void client.close();
// eslint-disable-next-line @typescript-eslint/naming-convention
const api = new osu.API({access_token: token?.access_token});
const profile = await api.getUser(7276846, osu.Ruleset.mania);

View file

@ -13,7 +13,6 @@ const handler: Handler = async () => {
const token = await collection.findOne();
void client.close();
// eslint-disable-next-line @typescript-eslint/naming-convention
const api = new osu.API({access_token: token?.access_token});
const profile = await api.getUser(7276846, osu.Ruleset.osu);

View file

@ -13,7 +13,6 @@ const handler: Handler = async () => {
const token = await collection.findOne();
void client.close();
// eslint-disable-next-line @typescript-eslint/naming-convention
const api = new osu.API({access_token: token?.access_token});
const profile = await api.getUser(7276846, osu.Ruleset.taiko);

View file

@ -1,12 +1,13 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint no-async-promise-executor: 0 */ // Doing promises is needed in order to make multiple requests at once, lowering wait time
import {type Handler} from "@netlify/functions";
import {API} from "osu-api-v2-js";
import {MongoClient} from "mongodb";
export type Token = {
export interface Token {
access_token: API["access_token"];
expires: API["expires"];
};
}
const handler: Handler = async () => {
const client = new MongoClient(process.env.URL_MONGODB!);
@ -20,7 +21,7 @@ const handler: Handler = async () => {
const token = tokens.find((t) => t.expires > now);
const expiredTokens = tokens.filter((t) => now > t.expires);
const promises: Array<Promise<void>> = [];
const promises: Promise<void>[] = [];
if (!token) {
promises.push(new Promise(async (resolve) => {

View file

@ -1,5 +1,5 @@
export async function api<T>(url: string, restful_token?: string): Promise<T> {
// eslint-disable-next-line @typescript-eslint/naming-convention
return (restful_token ? fetch(url, {headers: {"Authorization": `Bearer ${restful_token}`}}) : fetch(url))
.then(async response => {
if (!response.ok) {

View file

@ -5,7 +5,7 @@ import {type SpeedruncomInfo} from "../../src/components/Info/Speedrunning/Speed
const handler: Handler = async () => {
// using the API's embedding would be stupid here, as that'd create lag due to irrelevant runs
const speedruncom = await api<{
data: Array<{
data: {
place: number;
run: {
weblink: string;
@ -14,7 +14,7 @@ const handler: Handler = async () => {
category: string | undefined;
date: string;
};
}>;
}[];
}>("https://www.speedrun.com/api/v1/users/j03v45mj/personal-bests");
const detailsToRequest = [new Promise((resolve) => {

View file

@ -2,30 +2,30 @@ import {type Handler} from "@netlify/functions";
import {api} from "./shared/api.js";
import {type WanikaniInfo} from "../../src/components/Info/Japanese/Wanikani.js";
type Subject = {
interface Subject {
id: number;
object: string;
data: {
characters: string;
slug: string;
document_url: string;
meanings: Array<{
meanings: {
meaning: string;
}>;
}[];
};
};
}
type StuffToLearn = {
interface StuffToLearn {
available_at: string;
type: string;
writing: string;
meanings: Array<{
meanings: {
meaning: string;
}>;
}[];
url: string;
};
}
function addStuffToLearn(ids: number[], data: Array<{available_at: string; subject_ids: number[]}>, subjects: Subject[]): StuffToLearn[] {
function addStuffToLearn(ids: number[], data: {available_at: string; subject_ids: number[]}[], subjects: Subject[]): StuffToLearn[] {
const arr: StuffToLearn[] = [];
for (const id of ids) {
@ -37,7 +37,6 @@ function addStuffToLearn(ids: number[], data: Array<{available_at: string; subje
}
arr.push({
// eslint-disable-next-line @typescript-eslint/naming-convention
available_at: summaryData.available_at,
type: subject.object,
writing: subject.data.characters || subject.data.slug || subject.data.meanings[0].meaning,
@ -64,14 +63,14 @@ const handler: Handler = async () => {
const progression: {
total_count: number;
data: Array<{
data: {
data: {
level: number;
unlocked_at: undefined | string;
completed_at: undefined | string;
abandoned_at: undefined | string;
};
}>;
}[];
} = data[0];
const resets: {
@ -86,14 +85,14 @@ const handler: Handler = async () => {
const summary: {
data: {
lessons: Array<{
lessons: {
available_at: string;
subject_ids: number[];
}>;
reviews: Array<{
}[];
reviews: {
available_at: string;
subject_ids: number[];
}>;
}[];
next_reviews_at: undefined | string;
};
} = data[2];
@ -113,14 +112,15 @@ const handler: Handler = async () => {
}
const now = new Date();
// next_reviews checks what reviews will be available in the next 23 hours
// summary.data.next_reviews_at checks beyond that, but will be the current time if a review is already available
// next_reviews | Checks what reviews will be available in the next 23 hours
// summary.data.next_reviews_at | Checks beyond that, but will be the current time if a review is already available
const nextReviews = summary.data.reviews
.map((r: {subject_ids: number[]; available_at: Date | string}) => {
r.available_at = new Date(r.available_at); return r;
})
.filter((r) => r.available_at > now && r.subject_ids.length) as Array<{subject_ids: number[]; available_at: Date}>;
const moreThingsToReviewAt = nextReviews[0] ? nextReviews[0].available_at.toISOString() : summary.data.next_reviews_at ? summary.data.next_reviews_at : undefined;
.filter((r) => r.available_at > now && r.subject_ids.length) as {subject_ids: number[]; available_at: Date}[];
const moreThingsToReviewAt = nextReviews.at(0)?.available_at.toISOString() ?? summary.data.next_reviews_at;
const subjectIdsAll = subjectIdsLessons.concat(subjectIdsReviews);
const subjects = await api<{data: Subject[]}>(`https://api.wanikani.com/v2/subjects?ids=${subjectIdsAll.toString()}`, process.env.API_WANIKANI);

View file

@ -3,14 +3,13 @@
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
"lint": "bunx eslint .",
"lint:fix": "bunx eslint . --fix"
"lint": "bunx eslint ."
},
"dependencies": {
"@carbon/icons-react": "^11.53.0",
"@carbon/icons-react": "^11.55.0",
"@netlify/functions": "^2.8.2",
"@octokit/rest": "^20.1.1",
"mongodb": "^6.12.0",
"mongodb": "^6.13.0",
"osu-api-v2-js": "^1.1.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
@ -18,23 +17,26 @@
},
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.18.0",
"@stylistic/eslint-plugin-ts": "^2.13.0",
"@eslint/js": "^9.20.0",
"@stylistic/eslint-plugin": "^3.1.0",
"@tailwindcss/forms": "^0.5.10",
"@types/node": "^20.17.13",
"@types/react": "npm:types-react@beta",
"@types/react-dom": "npm:types-react-dom@beta",
"@types/bun": "latest",
"@types/node": "^20.17.19",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.20",
"eslint": "^9.18.0",
"eslint": "^9.20.1",
"eslint-config-xo-typescript": "^7.0.0",
"eslint-plugin-react": "^7.37.4",
"postcss": "^8.5.1",
"postcss": "^8.5.2",
"react-animate-height": "^3.2.3",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0",
"vite": "^5.4.11"
"typescript-eslint": "^8.24.0",
"vite": "^5.4.14"
},
"type": "module"
}
"type": "module",
"name": "taevas.xyz",
"module": "index.ts"
}

View file

@ -22,7 +22,6 @@ export default function Anilist() {
const [error, setError] = useState(false);
const getAnilist = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setAnilist(await fetch("/.netlify/functions/anilist").then(async r => r.json()));
};

View file

@ -2,7 +2,7 @@ import React, {useState, useEffect} from "react";
import Website from "../../Website.js";
import ButtonLink from "../../Link/ButtonLink.js";
export type GithubInfo = {
export interface GithubInfo {
public?: {
repo: string;
date: string;
@ -10,7 +10,7 @@ export type GithubInfo = {
private?: {
date: string;
};
};
}
export default function GitHub() {
const [github, setGithub]: [GithubInfo, React.Dispatch<React.SetStateAction<GithubInfo>>] = useState({});
@ -18,7 +18,6 @@ export default function GitHub() {
const [error, setError] = useState(false);
const getGithub = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setGithub(await fetch("/.netlify/functions/github").then(async r => r.json()));
};

View file

@ -11,7 +11,6 @@ export default function GitLab() {
const [error, setError] = useState(false);
const getGitlab = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setGitlab(await fetch("/.netlify/functions/gitlab").then(async r => r.json()));
};

View file

@ -16,7 +16,6 @@ export default function KitsuClub() {
const [error, setError] = useState(false);
const getKitsuclub = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setKitsuclub(await fetch("/.netlify/functions/kitsuclub").then(async r => r.json()));
};
@ -28,7 +27,7 @@ export default function KitsuClub() {
useEffect(() => {
if (kitsuclub) {
const date = new Date(kitsuclub.date).toISOString()
const date = new Date(kitsuclub.date).toISOString();
try {
setElements([
<div key={"kitsuclub-details"} className="text-left mb-2">
@ -38,9 +37,9 @@ export default function KitsuClub() {
<strong key={"kitsuclub-date"} className="inline-flex text-sm">{date.substring(0, date.indexOf("T"))}</strong>
</div>,
<p key={"kitsuclub-text"} className="text-left">{...emojify(kitsuclub.text, kitsuclub.emojis)}</p>, // emojis that are only in the post aren't in the response yet :(
])
]);
} catch {
setError(true)
setError(true);
}
}
}, [kitsuclub]);
@ -55,21 +54,21 @@ export default function KitsuClub() {
);
}
function emojify(text: string, all_emojis: Record<string, string>): Array<string | React.JSX.Element> {
const emoji_list: string[] = Object.keys(all_emojis)
const emoji_imgs: string[] = Object.values(all_emojis)
const to_return: Array<string | React.JSX.Element> = []
function emojify(text: string, all_emojis: Record<string, string>): (string | React.JSX.Element)[] {
const emoji_list: string[] = Object.keys(all_emojis);
const emoji_imgs: string[] = Object.values(all_emojis);
const to_return: (string | React.JSX.Element)[] = [];
for (let i = 0; i < emoji_list.length; i++) {
const emoji_name = emoji_list[i]
while (text.indexOf(emoji_name) !== -1) {
const index = text.indexOf(emoji_name)
to_return.push(text.substring(0, index - 1)) // push whatever text before the emoji
to_return.push(<img src={emoji_imgs[i]} alt={emoji_name} className="h-6 w-6 mx-1"/>) // push the emoji
text = text.substring(index + emoji_name.length + 1) // remove whatever text before the emoji and the emoji name
const emoji_name = emoji_list[i];
while (text.includes(emoji_name)) {
const index = text.indexOf(emoji_name);
to_return.push(text.substring(0, index - 1)); // push whatever text before the emoji
to_return.push(<img src={emoji_imgs[i]} alt={emoji_name} className="h-6 w-6 mx-1"/>); // push the emoji
text = text.substring(index + emoji_name.length + 1); // remove whatever text before the emoji and the emoji name
}
}
to_return.push(text) // push whatever text AFTER the last emoji (so all the text if no emoji)
to_return.push(text); // push whatever text AFTER the last emoji (so all the text if no emoji)
return to_return
return to_return;
}

View file

@ -18,7 +18,6 @@ export default function Hackthebox() {
const [error, setError] = useState(false);
const getHackthebox = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setHackthebox(await fetch("/.netlify/functions/hackthebox").then(async r => r.json()));
};

View file

@ -4,36 +4,36 @@ import Website from "../../Website.js";
export type WanikaniInfo = {
progression: {
total_count: number;
data: Array<{
data: {
data: {
level: number;
unlocked_at: undefined | string;
completed_at: undefined | string;
abandoned_at: undefined | string;
};
}>;
}[];
};
resets: Array<{
resets: {
data: {
created_at: string;
original_level: number;
target_level: number;
};
}>;
}[];
lessons: Item[];
reviews: Item[];
moreThingsToReviewAt: string | undefined;
} | undefined;
type Item = {
interface Item {
available_at: string;
type: string;
writing: string;
meanings: Array<{
meanings: {
meaning: string;
}>;
}[];
url: string;
};
}
function Button(item: Item) {
const colour = item.type === "radical" ? "bg-sky-600" : item.type === "kanji" ? "bg-pink-500" : "bg-fuchsia-700";
@ -53,7 +53,6 @@ export default function Wanikani() {
const [error, setError] = useState(false);
const getWanikani = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setWanikani(await fetch("/.netlify/functions/wanikani").then(async r => r.json()));
};

View file

@ -19,7 +19,6 @@ export default function Lastfm() {
const [error, setError] = useState(false);
const getLastfm = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setLastfm(await fetch("/.netlify/functions/lastfm").then(async r => r.json()));
};

View file

@ -15,7 +15,6 @@ export default function Osu() {
const [error, setError] = useState(false);
const getOsu = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setOsu(await fetch("/.netlify/functions/osu_osu").then(async r => r.json()));
};

View file

@ -15,7 +15,6 @@ export default function Fruits() {
const [error, setError] = useState(false);
const getFruits = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setFruits(await fetch("/.netlify/functions/osu_fruits").then(async r => r.json()));
};

View file

@ -15,7 +15,6 @@ export default function Mania() {
const [error, setError] = useState(false);
const getMania = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setMania(await fetch("/.netlify/functions/osu_mania").then(async r => r.json()));
};

View file

@ -15,7 +15,6 @@ export default function Taiko() {
const [error, setError] = useState(false);
const getTaiko = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setTaiko(await fetch("/.netlify/functions/osu_taiko").then(async r => r.json()));
};

View file

@ -17,7 +17,6 @@ export default function Speedruncom() {
const [error, setError] = useState(false);
const getSpeedruncom = async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setSpeedruncom(await fetch("/.netlify/functions/speedruncom").then(async r => r.json()));
};

View file

@ -1,9 +1,9 @@
import React from "react";
export type TabDetails = {
export interface TabDetails {
id: string;
priority: string;
};
}
export const LanguageContext = React.createContext<string>("en");
export const TabContext = React.createContext<TabDetails[]>([]);

View file

@ -6,7 +6,7 @@ import Coding from "../components/Info/Coding.js";
import RhythmGames from "../components/Info/RhythmGames.js";
import Anime from "../components/Info/Anime.js";
// import Japanese from "../components/Info/Japanese.js";
import Fediverse from "../components/Info/Fediverse.js"
import Fediverse from "../components/Info/Fediverse.js";
export default class Infos extends Component {
private readonly dragbar = React.createRef<HTMLDivElement>();