mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2026-01-15 12:15:02 +00:00
Linting/sonar tweaks
This commit is contained in:
@@ -38,8 +38,7 @@ const getLanguageParser = async (
|
||||
if (language === "xml") {
|
||||
return {
|
||||
parser: "xml",
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
plugins: [await import("@prettier/plugin-xml")],
|
||||
plugins: [(await import("@prettier/plugin-xml")) as Plugin],
|
||||
};
|
||||
}
|
||||
if (language === "markdown") {
|
||||
|
||||
@@ -2,7 +2,8 @@ import { loadFiles } from "utils/functions";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Demo: new (canvas: HTMLCanvasElement) => void;
|
||||
Demo: new (canvas: HTMLCanvasElement) => unknown;
|
||||
Hexells: unknown;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +25,7 @@ const hexells = async (el?: HTMLElement | null): Promise<void> => {
|
||||
canvas.height = window.innerHeight;
|
||||
canvas.width = window.innerWidth;
|
||||
|
||||
// eslint-disable-next-line no-new
|
||||
new window.Demo(canvas);
|
||||
window.Hexells = new window.Demo(canvas);
|
||||
|
||||
el.appendChild(canvas);
|
||||
};
|
||||
|
||||
@@ -3,7 +3,8 @@ import type { OffscreenRenderProps } from "components/system/Desktop/Wallpapers/
|
||||
|
||||
/* eslint-disable vars-on-top, no-var */
|
||||
declare global {
|
||||
var Demo: new (canvas: OffscreenCanvas) => void;
|
||||
var Demo: new (canvas: OffscreenCanvas) => unknown;
|
||||
var Hexells: unknown;
|
||||
var demoCanvasRect: DOMRect;
|
||||
var devicePixelRatio: number;
|
||||
}
|
||||
@@ -22,9 +23,7 @@ globalThis.addEventListener(
|
||||
const { canvas, devicePixelRatio } = data as OffscreenRenderProps;
|
||||
|
||||
globalThis.devicePixelRatio = devicePixelRatio;
|
||||
|
||||
// eslint-disable-next-line no-new
|
||||
new globalThis.Demo(canvas);
|
||||
globalThis.Hexells = new globalThis.Demo(canvas);
|
||||
}
|
||||
},
|
||||
{ passive: true }
|
||||
|
||||
@@ -7,7 +7,7 @@ export type WallpaperConfig = Partial<typeof MatrixConfig> | VantaWavesConfig;
|
||||
export type WallpaperFunc = (
|
||||
el: HTMLElement | null,
|
||||
config?: WallpaperConfig
|
||||
) => Promise<void>;
|
||||
) => Promise<void> | void;
|
||||
|
||||
export type OffscreenRenderProps = {
|
||||
canvas: OffscreenCanvas;
|
||||
|
||||
@@ -60,8 +60,7 @@ const useWallpaper = (
|
||||
}, [desktopRef, wallpaperWorker]);
|
||||
const loadWallpaper = useCallback(() => {
|
||||
if (desktopRef.current) {
|
||||
// eslint-disable-next-line no-undef-init, unicorn/no-useless-undefined
|
||||
let config: WallpaperConfig | undefined = undefined;
|
||||
let config: WallpaperConfig | undefined;
|
||||
|
||||
if (wallpaperName === "VANTA") {
|
||||
config = { ...vantaConfig };
|
||||
|
||||
@@ -6,11 +6,10 @@ import {
|
||||
import type { VantaWavesConfig } from "components/system/Desktop/Wallpapers/vantaWaves/types";
|
||||
import { loadFiles } from "utils/functions";
|
||||
|
||||
const vantaWaves = async (
|
||||
const vantaWaves = (
|
||||
el: HTMLElement | null,
|
||||
config: WallpaperConfig = {} as WallpaperConfig
|
||||
// eslint-disable-next-line @typescript-eslint/require-await
|
||||
): Promise<void> => {
|
||||
): void => {
|
||||
const { VANTA: { current: currentEffect } = {} } = window;
|
||||
|
||||
try {
|
||||
|
||||
@@ -580,7 +580,10 @@ type WrapData = {
|
||||
width: number;
|
||||
};
|
||||
|
||||
const canvasContexts: Record<string, CanvasRenderingContext2D> = {};
|
||||
const canvasContexts = Object.create(null) as Record<
|
||||
string,
|
||||
CanvasRenderingContext2D
|
||||
>;
|
||||
|
||||
const measureText = (
|
||||
text: string,
|
||||
|
||||
@@ -155,8 +155,9 @@ const useFileContextMenu = (
|
||||
url: join("/", mappedFolder),
|
||||
});
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
.catch(() => {}),
|
||||
.catch(() => {
|
||||
// Ignore failure to map
|
||||
}),
|
||||
label: "Map directory",
|
||||
},
|
||||
MENU_SEPERATOR
|
||||
|
||||
@@ -23,10 +23,12 @@ const DEBOUNCE_TIME = MILLISECONDS_IN_SECOND / FPS;
|
||||
const useSelection = (
|
||||
containerRef: React.MutableRefObject<HTMLElement | null>
|
||||
): Selection => {
|
||||
const [position, setPosition] = useState<Position>();
|
||||
const [size, setSize] = useState<Size>();
|
||||
const { x, y } = position || {};
|
||||
const { height: h, width: w } = size || {};
|
||||
const [position, setPosition] = useState<Position>(
|
||||
() => Object.create(null) as Position
|
||||
);
|
||||
const [size, setSize] = useState<Size>(() => Object.create(null) as Size);
|
||||
const { x, y } = position;
|
||||
const { height: h, width: w } = size;
|
||||
const debounceTimer = useRef<number>();
|
||||
const onMouseMove: React.MouseEventHandler<HTMLElement> = ({
|
||||
clientX,
|
||||
@@ -56,7 +58,7 @@ const useSelection = (
|
||||
const { x: targetX = 0, y: targetY = 0 } =
|
||||
containerRef.current.getBoundingClientRect();
|
||||
|
||||
setSize({} as Size);
|
||||
setSize(Object.create(null) as Size);
|
||||
setPosition({
|
||||
x: clientX - targetX,
|
||||
y: clientY - targetY + scrollTop,
|
||||
@@ -66,8 +68,8 @@ const useSelection = (
|
||||
const hasSize = typeof w === "number" && typeof h === "number";
|
||||
const hasPosition = typeof x === "number" && typeof y === "number";
|
||||
const resetSelection = (): void => {
|
||||
setSize({} as Size);
|
||||
setPosition({} as Position);
|
||||
setSize(Object.create(null) as Size);
|
||||
setPosition(Object.create(null) as Position);
|
||||
};
|
||||
const isSelecting = hasSize && hasPosition;
|
||||
const selectionStyling = isSelecting
|
||||
|
||||
@@ -74,11 +74,11 @@ export const sortContents = (
|
||||
});
|
||||
|
||||
const sortContent = (fileStats: FileStats[]): FileStats[] => {
|
||||
const sortedByName = fileStats.sort(sortByName);
|
||||
fileStats.sort(sortByName);
|
||||
|
||||
return sortFunction && sortFunction !== sortByName
|
||||
? sortedByName.sort(sortFunction)
|
||||
: sortedByName;
|
||||
? fileStats.sort(sortFunction)
|
||||
: fileStats;
|
||||
};
|
||||
const sortedFolders = sortContent(folders);
|
||||
const sortedFiles = sortContent(files);
|
||||
|
||||
@@ -42,7 +42,9 @@ const useDraggableEntries = (
|
||||
const { iconPositions, sortOrders, setIconPositions, setSortOrder } =
|
||||
useSession();
|
||||
const dragImageRef = useRef<HTMLImageElement | null>();
|
||||
const dragPositionRef = useRef<DragPosition>({});
|
||||
const dragPositionRef = useRef<DragPosition>(
|
||||
Object.create(null) as DragPosition
|
||||
);
|
||||
const draggedOnceRef = useRef(false);
|
||||
const onDragging = ({ clientX: x, clientY: y }: DragEvent): void => {
|
||||
dragPositionRef.current = { ...dragPositionRef.current, x, y };
|
||||
@@ -146,7 +148,7 @@ const useDraggableEntries = (
|
||||
offsetX: event.nativeEvent.offsetX,
|
||||
offsetY: event.nativeEvent.offsetY,
|
||||
}
|
||||
: {};
|
||||
: (Object.create(null) as DragPosition);
|
||||
fileManagerRef.current?.addEventListener("dragover", onDragging, {
|
||||
passive: true,
|
||||
});
|
||||
|
||||
@@ -100,8 +100,9 @@ const useFolderContextMenu = (
|
||||
updateFolder(url, mappedFolder);
|
||||
open("FileExplorer", { url: join(url, mappedFolder) });
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
.catch(() => {}),
|
||||
.catch(() => {
|
||||
// Ignore failure to map
|
||||
}),
|
||||
label: "Map directory",
|
||||
};
|
||||
const FS_COMMANDS = isFileSystemSupported()
|
||||
|
||||
@@ -62,7 +62,9 @@ const easterEggOnClick: React.MouseEventHandler<HTMLElement> = async ({
|
||||
};
|
||||
|
||||
const Clock: FC = () => {
|
||||
const [now, setNow] = useState<LocaleTimeDate>({} as LocaleTimeDate);
|
||||
const [now, setNow] = useState<LocaleTimeDate>(
|
||||
Object.create(null) as LocaleTimeDate
|
||||
);
|
||||
const { date, time } = now;
|
||||
const { clockSource } = useSession();
|
||||
const clockWorkerInit = useCallback(
|
||||
@@ -124,6 +126,7 @@ const Clock: FC = () => {
|
||||
);
|
||||
}
|
||||
},
|
||||
// NOTE: Need `now` in the dependency array to ensure the clock is updated
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[currentWorker, now]
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ const contextFactory = <T,>(
|
||||
Provider: FC;
|
||||
useContext: () => T;
|
||||
} => {
|
||||
const Context = createContext<T>({} as T);
|
||||
const Context = createContext<T>(Object.create(null) as T);
|
||||
const ProcessProvider: FC = ({ children }) => (
|
||||
<Context.Provider value={useContextState()}>
|
||||
{children}
|
||||
|
||||
@@ -141,14 +141,16 @@ const getKeyValStore = (): ReturnType<typeof openDB> =>
|
||||
});
|
||||
|
||||
export const getFileSystemHandles = async (): Promise<FileSystemHandles> => {
|
||||
if (!(await supportsIndexedDB())) return {};
|
||||
if (!(await supportsIndexedDB())) {
|
||||
return Object.create(null) as FileSystemHandles;
|
||||
}
|
||||
|
||||
const db = await getKeyValStore();
|
||||
|
||||
return (
|
||||
(await (<Promise<FileSystemHandles>>(
|
||||
db.get(KEYVAL_STORE_NAME, FS_HANDLES)
|
||||
))) || {}
|
||||
))) || (Object.create(null) as FileSystemHandles)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ const useAsyncFs = (): AsyncFSModule => {
|
||||
}),
|
||||
lstat: (path) =>
|
||||
new Promise((resolve, reject) => {
|
||||
fs?.lstat(path, (error, stats = {} as Stats) =>
|
||||
fs?.lstat(path, (error, stats = Object.create(null) as Stats) =>
|
||||
error ? reject(error) : resolve(stats)
|
||||
);
|
||||
}),
|
||||
@@ -118,19 +118,22 @@ const useAsyncFs = (): AsyncFSModule => {
|
||||
if (!renameError) {
|
||||
resolve(true);
|
||||
} else if (renameError.code === "ENOTSUP") {
|
||||
fs.lstat(oldPath, (_statsError, stats = {} as Stats) => {
|
||||
if (stats.isDirectory()) {
|
||||
reject();
|
||||
} else {
|
||||
fs.readFile(oldPath, (readError, data) =>
|
||||
fs.writeFile(newPath, data, (writeError) =>
|
||||
readError || writeError
|
||||
? reject(readError || writeError)
|
||||
: resolve(false)
|
||||
)
|
||||
);
|
||||
fs.lstat(
|
||||
oldPath,
|
||||
(_statsError, stats = Object.create(null) as Stats) => {
|
||||
if (stats.isDirectory()) {
|
||||
reject();
|
||||
} else {
|
||||
fs.readFile(oldPath, (readError, data) =>
|
||||
fs.writeFile(newPath, data, (writeError) =>
|
||||
readError || writeError
|
||||
? reject(readError || writeError)
|
||||
: resolve(false)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
} else if (renameError.code === "EISDIR") {
|
||||
rootFs?.umount(oldPath);
|
||||
asyncFs.rename(oldPath, newPath).then(resolve, reject);
|
||||
@@ -145,7 +148,7 @@ const useAsyncFs = (): AsyncFSModule => {
|
||||
}),
|
||||
stat: (path) =>
|
||||
new Promise((resolve, reject) => {
|
||||
fs?.stat(path, (error, stats = {} as Stats) =>
|
||||
fs?.stat(path, (error, stats = Object.create(null) as Stats) =>
|
||||
error ? reject(error) : resolve(stats)
|
||||
);
|
||||
}),
|
||||
|
||||
@@ -125,7 +125,7 @@ const useSessionContextState = (): SessionContextState => {
|
||||
initializedSession.current = true;
|
||||
|
||||
try {
|
||||
let session = {} as SessionData;
|
||||
let session: SessionData;
|
||||
|
||||
try {
|
||||
session =
|
||||
|
||||
@@ -65,13 +65,13 @@ const getPublicDirectoryIcons = (directory) => {
|
||||
}
|
||||
|
||||
const iconPath = url || `${directory}/${file}`;
|
||||
const iconFileName = `${iconPath}${ICON_CACHE_EXTENSION}`;
|
||||
const iconCacheFileName = `${iconPath}${ICON_CACHE_EXTENSION}`;
|
||||
|
||||
if (
|
||||
extname(iconPath) &&
|
||||
existsSync(join("./public", ICON_CACHE, `${iconFileName}`))
|
||||
existsSync(join("./public", ICON_CACHE, `${iconCacheFileName}`))
|
||||
) {
|
||||
icons.push(encodeURI(`${ICON_CACHE}${iconFileName}`));
|
||||
icons.push(encodeURI(`${ICON_CACHE}${iconCacheFileName}`));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,10 +82,7 @@ const getPublicDirectoryIcons = (directory) => {
|
||||
|
||||
writeFileSync(
|
||||
"./public/.index/desktopIcons.json",
|
||||
JSON.stringify([
|
||||
SHORTCUT_ICON,
|
||||
...getPublicDirectoryIcons(DESKTOP_PATH, true),
|
||||
])
|
||||
JSON.stringify([SHORTCUT_ICON, ...getPublicDirectoryIcons(DESKTOP_PATH)])
|
||||
);
|
||||
|
||||
writeFileSync(
|
||||
|
||||
@@ -8,10 +8,7 @@ const buildAppSitemap = (path) => {
|
||||
readdirSync(path).forEach((entry) => {
|
||||
if (statSync(join(path, entry)).isDirectory()) {
|
||||
xmlUrls.push(
|
||||
`<url><loc>${`${author.url}/?app=${entry.replace(
|
||||
/-/g,
|
||||
""
|
||||
)}`}</loc></url>`
|
||||
`<url><loc>${author.url}/?app=${entry.replace(/-/g, "")}</loc></url>`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -117,10 +117,9 @@ const Icon = forwardRef<
|
||||
failedUrls.length > 0 &&
|
||||
failedUrls.includes(srcSet.split(" ")[0])
|
||||
) {
|
||||
return;
|
||||
return <></>;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
return (
|
||||
<source
|
||||
key={ratio}
|
||||
|
||||
@@ -225,16 +225,17 @@ export const calcInitialPosition = (
|
||||
viewHeight() - (relativePosition.bottom || 0) - container.offsetHeight,
|
||||
});
|
||||
|
||||
const GRID_TEMPLATE_ROWS = "grid-template-rows";
|
||||
|
||||
const calcGridDropPosition = (
|
||||
gridElement: HTMLElement | null,
|
||||
{ x = 0, y = 0, offsetX = 0, offsetY = 0 }: DragPosition
|
||||
): IconPosition => {
|
||||
if (!gridElement) return {} as IconPosition;
|
||||
if (!gridElement) return Object.create(null) as IconPosition;
|
||||
|
||||
const gridComputedStyle = window.getComputedStyle(gridElement);
|
||||
const gridTemplateRows = gridComputedStyle
|
||||
// eslint-disable-next-line sonarjs/no-duplicate-string
|
||||
.getPropertyValue("grid-template-rows")
|
||||
.getPropertyValue(GRID_TEMPLATE_ROWS)
|
||||
.split(" ");
|
||||
const gridTemplateColumns = gridComputedStyle
|
||||
.getPropertyValue("grid-template-columns")
|
||||
@@ -273,7 +274,7 @@ const updateIconPositionsIfEmpty = (
|
||||
const newIconPositions: IconPositions = {};
|
||||
const gridComputedStyle = window.getComputedStyle(gridElement);
|
||||
const gridTemplateRowCount = gridComputedStyle
|
||||
.getPropertyValue("grid-template-rows")
|
||||
.getPropertyValue(GRID_TEMPLATE_ROWS)
|
||||
.split(" ").length;
|
||||
|
||||
fileOrder.forEach((entry, index) => {
|
||||
@@ -330,7 +331,7 @@ const calcGridPositionOffset = (
|
||||
|
||||
const gridComputedStyle = window.getComputedStyle(gridElement);
|
||||
const gridTemplateRowCount = gridComputedStyle
|
||||
.getPropertyValue("grid-template-rows")
|
||||
.getPropertyValue(GRID_TEMPLATE_ROWS)
|
||||
.split(" ").length;
|
||||
const {
|
||||
gridColumnStart: targetGridColumnStart,
|
||||
@@ -438,8 +439,8 @@ export const isCanvasDrawn = (canvas?: HTMLCanvasElement | null): boolean =>
|
||||
);
|
||||
|
||||
const bytesInKB = 1024;
|
||||
const bytesInMB = 1022976; // 1024 * 999;
|
||||
const bytesInGB = 1047527424; // 1024 * 1024 * 999;
|
||||
const bytesInMB = 1022976; // 1024 * 999
|
||||
const bytesInGB = 1047527424; // 1024 * 1024 * 999
|
||||
const bytesInTB = 1072668082176; // 1024 * 1024 * 1024 * 999
|
||||
|
||||
const formatNumber = (number: number): string =>
|
||||
@@ -520,7 +521,7 @@ export const haltEvent = (
|
||||
export const createOffscreenCanvas = (
|
||||
containerElement: HTMLElement,
|
||||
devicePixelRatio = 1,
|
||||
customSize: Size = {} as Size
|
||||
customSize: Size = Object.create(null) as Size
|
||||
): OffscreenCanvas => {
|
||||
const canvas = document.createElement("canvas");
|
||||
const height = Number(customSize?.height) || containerElement.offsetHeight;
|
||||
|
||||
@@ -81,8 +81,7 @@ export const getIpfsFileName = async (
|
||||
};
|
||||
|
||||
export const getIpfsResource = async (ipfsUrl: string): Promise<Buffer> => {
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
let response: Response | null = null;
|
||||
let response: Response | undefined;
|
||||
const requestOptions = {
|
||||
...HIGH_PRIORITY_REQUEST,
|
||||
cache: "no-cache",
|
||||
|
||||
@@ -13,7 +13,7 @@ const FILE_INDEX = "/.index/search.lunr.json";
|
||||
|
||||
export const SEARCH_LIBS = ["/System/lunr/lunr.min.js"];
|
||||
|
||||
let baseIndex = {} as Index;
|
||||
let baseIndex = Object.create(null) as Index;
|
||||
|
||||
const search = async (
|
||||
searchTerm: string,
|
||||
|
||||
@@ -27,8 +27,7 @@ const pickRandomPet = (): string => {
|
||||
const petNames = Object.keys(PETS).flatMap((pet) => {
|
||||
const [, probability] = PETS[pet];
|
||||
|
||||
// eslint-disable-next-line unicorn/new-for-builtins
|
||||
return Array(probability).fill(pet) as string[];
|
||||
return Array.from({ length: probability }).fill(pet) as string[];
|
||||
});
|
||||
const randomPet = Math.floor(Math.random() * petNames.length);
|
||||
const [petPath] = PETS[petNames[randomPet]];
|
||||
|
||||
6
utils/types.d.ts
vendored
6
utils/types.d.ts
vendored
@@ -1,8 +1,10 @@
|
||||
/**
|
||||
* Functional Component
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
type FC<TProps = {}> = (props: React.PropsWithChildren<TProps>) => JSX.Element;
|
||||
|
||||
type FC<TProps = Record<string, unknown>> = (
|
||||
props: React.PropsWithChildren<TProps>
|
||||
) => JSX.Element;
|
||||
|
||||
type HTMLElementWithPriority<T> = T & {
|
||||
fetchPriority?: "auto" | "high" | "low";
|
||||
|
||||
Reference in New Issue
Block a user