refactor: migrate to common eslint+prettier configs (#4168)

* refactor: migrate to common eslint+prettier configs

* fix: prettier frontend

* feat: config changes

* fix: lint issues

* fix: lint

* fix: type imports

* fix: cyclical import issue

* fix: lockfile

* fix: missing dep

* fix: switch to tabs

* fix: continue switch to tabs

* fix: rustfmt parity

* fix: moderation lint issue

* fix: lint issues

* fix: ui intl

* fix: lint issues

* Revert "fix: rustfmt parity"

This reverts commit cb99d2376c321d813d4b7fc7e2a213bb30a54711.

* feat: revert last rs
This commit is contained in:
Cal H.
2025-08-14 21:48:38 +01:00
committed by GitHub
parent 82697278dc
commit 2aabcf36ee
702 changed files with 101360 additions and 102020 deletions

View File

@@ -1,13 +1,13 @@
import { createGlobalState } from "@vueuse/core";
import { type Ref, shallowRef } from "vue";
import { createGlobalState } from '@vueuse/core'
import { type Ref, shallowRef } from 'vue'
/**
* Maximum number of console output lines to store
* @type {number}
*/
const maxLines = 10000;
const batchTimeout = 300; // ms
const initialBatchSize = 256;
const maxLines = 10000
const batchTimeout = 300 // ms
const initialBatchSize = 256
/**
* Provides a global console output state management system
@@ -19,146 +19,146 @@ const initialBatchSize = 256;
* @property {function(): void} clear - Method to clear all console output
*/
export const useModrinthServersConsole = createGlobalState(() => {
/**
* Reactive array storing console output lines
* @type {Ref<string[]>}
*/
const output: Ref<string[]> = shallowRef<string[]>([]);
const searchQuery: Ref<string> = shallowRef("");
const filteredOutput: Ref<string[]> = shallowRef([]);
let searchRegex: RegExp | null = null;
/**
* Reactive array storing console output lines
* @type {Ref<string[]>}
*/
const output: Ref<string[]> = shallowRef<string[]>([])
const searchQuery: Ref<string> = shallowRef('')
const filteredOutput: Ref<string[]> = shallowRef([])
let searchRegex: RegExp | null = null
let lineBuffer: string[] = [];
let batchTimer: NodeJS.Timeout | null = null;
let isProcessingInitialBatch = false;
let lineBuffer: string[] = []
let batchTimer: NodeJS.Timeout | null = null
let isProcessingInitialBatch = false
let refilterTimer: NodeJS.Timeout | null = null;
const refilterTimeout = 100; // ms
let refilterTimer: NodeJS.Timeout | null = null
const refilterTimeout = 100 // ms
const updateFilter = () => {
if (!searchQuery.value) {
filteredOutput.value = [];
return;
}
const updateFilter = () => {
if (!searchQuery.value) {
filteredOutput.value = []
return
}
if (!searchRegex) {
searchRegex = new RegExp(searchQuery.value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
}
if (!searchRegex) {
searchRegex = new RegExp(searchQuery.value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i')
}
filteredOutput.value = output.value.filter((line) => searchRegex?.test(line) ?? false);
};
filteredOutput.value = output.value.filter((line) => searchRegex?.test(line) ?? false)
}
const scheduleRefilter = () => {
if (refilterTimer) clearTimeout(refilterTimer);
refilterTimer = setTimeout(updateFilter, refilterTimeout);
};
const scheduleRefilter = () => {
if (refilterTimer) clearTimeout(refilterTimer)
refilterTimer = setTimeout(updateFilter, refilterTimeout)
}
const flushBuffer = () => {
if (lineBuffer.length === 0) return;
const flushBuffer = () => {
if (lineBuffer.length === 0) return
const processedLines = lineBuffer.flatMap((line) => line.split("\n").filter(Boolean));
const processedLines = lineBuffer.flatMap((line) => line.split('\n').filter(Boolean))
if (isProcessingInitialBatch && processedLines.length >= initialBatchSize) {
isProcessingInitialBatch = false;
output.value = processedLines.slice(-maxLines);
} else {
const newOutput = [...output.value, ...processedLines];
output.value = newOutput.slice(-maxLines);
}
if (isProcessingInitialBatch && processedLines.length >= initialBatchSize) {
isProcessingInitialBatch = false
output.value = processedLines.slice(-maxLines)
} else {
const newOutput = [...output.value, ...processedLines]
output.value = newOutput.slice(-maxLines)
}
lineBuffer = [];
batchTimer = null;
lineBuffer = []
batchTimer = null
if (searchQuery.value) {
scheduleRefilter();
}
};
if (searchQuery.value) {
scheduleRefilter()
}
}
/**
* Adds a new output line to the console output
* Automatically removes the oldest line if max output is exceeded
*
* @param {string} line - The console output line to add
*/
const addLine = (line: string): void => {
lineBuffer.push(line);
/**
* Adds a new output line to the console output
* Automatically removes the oldest line if max output is exceeded
*
* @param {string} line - The console output line to add
*/
const addLine = (line: string): void => {
lineBuffer.push(line)
if (!batchTimer) {
batchTimer = setTimeout(flushBuffer, batchTimeout);
}
};
if (!batchTimer) {
batchTimer = setTimeout(flushBuffer, batchTimeout)
}
}
/**
* Adds multiple output lines to the console output
* Automatically removes the oldest lines if max output is exceeded
*
* @param {string[]} lines - The console output lines to add
* @returns {void}
*/
const addLines = (lines: string[]): void => {
if (output.value.length === 0 && lines.length >= initialBatchSize) {
isProcessingInitialBatch = true;
lineBuffer = lines;
flushBuffer();
return;
}
/**
* Adds multiple output lines to the console output
* Automatically removes the oldest lines if max output is exceeded
*
* @param {string[]} lines - The console output lines to add
* @returns {void}
*/
const addLines = (lines: string[]): void => {
if (output.value.length === 0 && lines.length >= initialBatchSize) {
isProcessingInitialBatch = true
lineBuffer = lines
flushBuffer()
return
}
lineBuffer.push(...lines);
lineBuffer.push(...lines)
if (!batchTimer) {
batchTimer = setTimeout(flushBuffer, batchTimeout);
}
};
if (!batchTimer) {
batchTimer = setTimeout(flushBuffer, batchTimeout)
}
}
/**
* Sets the search query and filters the output based on the query
*
* @param {string} query - The search query
*/
const setSearchQuery = (query: string): void => {
searchQuery.value = query;
searchRegex = null;
updateFilter();
};
/**
* Sets the search query and filters the output based on the query
*
* @param {string} query - The search query
*/
const setSearchQuery = (query: string): void => {
searchQuery.value = query
searchRegex = null
updateFilter()
}
/**
* Clears all console output lines
*/
const clear = (): void => {
output.value = [];
filteredOutput.value = [];
searchQuery.value = "";
lineBuffer = [];
isProcessingInitialBatch = false;
if (batchTimer) {
clearTimeout(batchTimer);
batchTimer = null;
}
if (refilterTimer) {
clearTimeout(refilterTimer);
refilterTimer = null;
}
searchRegex = null;
};
/**
* Clears all console output lines
*/
const clear = (): void => {
output.value = []
filteredOutput.value = []
searchQuery.value = ''
lineBuffer = []
isProcessingInitialBatch = false
if (batchTimer) {
clearTimeout(batchTimer)
batchTimer = null
}
if (refilterTimer) {
clearTimeout(refilterTimer)
refilterTimer = null
}
searchRegex = null
}
/**
* Finds the index of a line in the main output
*
* @param {string} line - The line to find
* @returns {number} The index of the line, or -1 if not found
*/
const findLineIndex = (line: string): number => {
return output.value.findIndex((l) => l === line);
};
/**
* Finds the index of a line in the main output
*
* @param {string} line - The line to find
* @returns {number} The index of the line, or -1 if not found
*/
const findLineIndex = (line: string): number => {
return output.value.findIndex((l) => l === line)
}
return {
output,
searchQuery,
filteredOutput,
addLine,
addLines,
setSearchQuery,
clear,
findLineIndex,
};
});
return {
output,
searchQuery,
filteredOutput,
addLine,
addLines,
setSearchQuery,
clear,
findLineIndex,
}
})

View File

@@ -1,98 +1,98 @@
import { defineStore, createPinia } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
import { createPinia, defineStore } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
export interface ModerationQueue {
items: string[];
total: number;
completed: number;
skipped: number;
lastUpdated: Date;
items: string[]
total: number
completed: number
skipped: number
lastUpdated: Date
}
const EMPTY_QUEUE: Partial<ModerationQueue> = {
items: [],
items: [],
// TODO: Consider some form of displaying this in the checklist, maybe at the end
total: 0,
completed: 0,
skipped: 0,
};
function createEmptyQueue(): ModerationQueue {
return { ...EMPTY_QUEUE, lastUpdated: new Date() } as ModerationQueue;
// TODO: Consider some form of displaying this in the checklist, maybe at the end
total: 0,
completed: 0,
skipped: 0,
}
const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);
function createEmptyQueue(): ModerationQueue {
return { ...EMPTY_QUEUE, lastUpdated: new Date() } as ModerationQueue
}
export const useModerationStore = defineStore("moderation", {
state: () => ({
currentQueue: createEmptyQueue(),
}),
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
getters: {
queueLength: (state) => state.currentQueue.items.length,
hasItems: (state) => state.currentQueue.items.length > 0,
progress: (state) => {
if (state.currentQueue.total === 0) return 0;
return (state.currentQueue.completed + state.currentQueue.skipped) / state.currentQueue.total;
},
},
export const useModerationStore = defineStore('moderation', {
state: () => ({
currentQueue: createEmptyQueue(),
}),
actions: {
setQueue(projectIDs: string[]) {
this.currentQueue = {
items: [...projectIDs],
total: projectIDs.length,
completed: 0,
skipped: 0,
lastUpdated: new Date(),
};
},
getters: {
queueLength: (state) => state.currentQueue.items.length,
hasItems: (state) => state.currentQueue.items.length > 0,
progress: (state) => {
if (state.currentQueue.total === 0) return 0
return (state.currentQueue.completed + state.currentQueue.skipped) / state.currentQueue.total
},
},
setSingleProject(projectId: string) {
this.currentQueue = {
items: [projectId],
total: 1,
completed: 0,
skipped: 0,
lastUpdated: new Date(),
};
},
actions: {
setQueue(projectIDs: string[]) {
this.currentQueue = {
items: [...projectIDs],
total: projectIDs.length,
completed: 0,
skipped: 0,
lastUpdated: new Date(),
}
},
completeCurrentProject(projectId: string, status: "completed" | "skipped" = "completed") {
if (status === "completed") {
this.currentQueue.completed++;
} else {
this.currentQueue.skipped++;
}
setSingleProject(projectId: string) {
this.currentQueue = {
items: [projectId],
total: 1,
completed: 0,
skipped: 0,
lastUpdated: new Date(),
}
},
this.currentQueue.items = this.currentQueue.items.filter((id: string) => id !== projectId);
this.currentQueue.lastUpdated = new Date();
completeCurrentProject(projectId: string, status: 'completed' | 'skipped' = 'completed') {
if (status === 'completed') {
this.currentQueue.completed++
} else {
this.currentQueue.skipped++
}
return this.currentQueue.items.length > 0;
},
this.currentQueue.items = this.currentQueue.items.filter((id: string) => id !== projectId)
this.currentQueue.lastUpdated = new Date()
getCurrentProjectId(): string | null {
return this.currentQueue.items[0] || null;
},
return this.currentQueue.items.length > 0
},
resetQueue() {
this.currentQueue = createEmptyQueue();
},
},
getCurrentProjectId(): string | null {
return this.currentQueue.items[0] || null
},
persist: {
key: "moderation-store",
serializer: {
serialize: JSON.stringify,
deserialize: (value: string) => {
const parsed = JSON.parse(value);
if (parsed.currentQueue?.lastUpdated) {
parsed.currentQueue.lastUpdated = new Date(parsed.currentQueue.lastUpdated);
}
return parsed;
},
},
},
});
resetQueue() {
this.currentQueue = createEmptyQueue()
},
},
persist: {
key: 'moderation-store',
serializer: {
serialize: JSON.stringify,
deserialize: (value: string) => {
const parsed = JSON.parse(value)
if (parsed.currentQueue?.lastUpdated) {
parsed.currentQueue.lastUpdated = new Date(parsed.currentQueue.lastUpdated)
}
return parsed
},
},
},
})