Skip to content

Commit

Permalink
Pkg upgrade + more lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinBrett committed Jul 17, 2024
1 parent 1f0dc29 commit 9d4214c
Show file tree
Hide file tree
Showing 18 changed files with 1,425 additions and 92 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,27 @@
"regexp/no-useless-assertions": "error",
"regexp/no-useless-flag": "error",
"regexp/strict": "error",
"sonarjs/anchor-precedence": "off",
"sonarjs/cognitive-complexity": "off",
"sonarjs/deprecation": "off",
"sonarjs/file-permissions": "off",
"sonarjs/function-return-type": "off",
"sonarjs/media-has-caption": "off",
"sonarjs/mouse-events-a11y": "off",
"sonarjs/new-cap": "off",
"sonarjs/no-hardcoded-credentials": "off",
"sonarjs/no-hardcoded-ip": "off",
"sonarjs/no-misused-promises": "off",
"sonarjs/no-nested-conditional": "off",
"sonarjs/no-nested-functions": "off",
"sonarjs/no-nested-template-literals": "off",
"sonarjs/no-try-promise": "off",
"sonarjs/no-var": "off",
"sonarjs/prefer-nullish-coalescing": "off",
"sonarjs/pseudo-random": "off",
"sonarjs/slow-regex": "off",
"sonarjs/sonar-max-params": "off",
"sonarjs/sonar-no-unused-vars": "off",
"sort-keys-fix/sort-keys-fix": "error",
"unicorn/filename-case": "off",
"unicorn/import-style": [
Expand Down
4 changes: 2 additions & 2 deletions components/apps/Messenger/ProfileBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { type ProfileData } from "components/apps/Messenger/types";
import { useMenu } from "contexts/menu";
import Button from "styles/common/Button";
import { MENU_SEPERATOR } from "utils/constants";
import { haltEvent } from "utils/functions";
import { haltEvent, toSorted } from "utils/functions";

const GRADIENT = "linear-gradient(rgba(0, 0, 0, 0.10), rgba(0, 0, 0, 0.5))";
const STYLING =
Expand Down Expand Up @@ -139,7 +139,7 @@ const ProfileBanner: FC<ProfileBannerProps> = ({
{!selectedRecipientKey && connectedRelays.length > 0 && (
<div className="relays">
<ol>
{relayUrls.sort().map((relayUrl) => (
{toSorted(relayUrls).map((relayUrl) => (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
<li
key={relayUrl}
Expand Down
3 changes: 2 additions & 1 deletion components/apps/Messenger/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from "components/apps/Messenger/types";
import { type MenuItem } from "contexts/menu/useMenuContextState";
import { MILLISECONDS_IN_DAY, MILLISECONDS_IN_SECOND } from "utils/constants";
import { toSorted } from "utils/functions";

export const getRelayUrls = async (): Promise<string[]> => {
if (window.nostr?.getRelays) {
Expand Down Expand Up @@ -444,7 +445,7 @@ export const prettyChatTimestamp = (timestamp: number): string => {
export const groupChatEvents = (events: Event[]): ChatEvents => {
if (events.length === 0) return [];

const sortedEvents = events.sort(ascCreatedAt);
const sortedEvents = toSorted(events, ascCreatedAt);
const [oldestEvent, ...remainingEvents] = sortedEvents;
const groupedEvents: ChatEvents = [
[prettyChatTimestamp(oldestEvent.created_at), [oldestEvent]],
Expand Down
4 changes: 2 additions & 2 deletions components/apps/Messenger/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { useProcesses } from "contexts/process";
import directory from "contexts/process/directory";
import { PACKAGE_DATA, PROCESS_DELIMITER } from "utils/constants";
import { toSorted } from "utils/functions";

export const useNostrEvents = ({
enabled = true,
Expand Down Expand Up @@ -144,8 +145,7 @@ export const useNostrContacts = (
const { events } = useMessageContext();
const contactKeys = useMemo(() => {
const keys = new Set(
events
.sort(descCreatedAt)
toSorted(events, descCreatedAt)
.map(({ pubkey, tags }) =>
pubkey === publicKey ? getKeyFromTags(tags) || "" : pubkey
)
Expand Down
8 changes: 6 additions & 2 deletions components/apps/Terminal/loadWapm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,19 @@ const loadWapm = async (

const moduleResponse = await lowerI64Imports(wasmBinary);

if (moduleResponse !== undefined && moduleResponse instanceof Uint8Array) {
if (
typeof moduleResponse === "object" &&
moduleResponse instanceof Uint8Array
) {
bindings ||= (await import("wasi-js/dist/bindings/browser")).default;

const wasmModule = await WebAssembly.compile(moduleResponse);
const stdIn =
(WAPM_STD_IN_APPS.includes(args[0]) ||
(getExtension(args[0]) === ".wasm" &&
WAPM_STD_IN_APPS.includes(basename(args[0], extname(args[0]))))) &&
(args[2] !== undefined || !WAPM_STD_IN_EXCLUDE_ARGS.includes(args[1]));
(typeof args[2] === "string" ||
!WAPM_STD_IN_EXCLUDE_ARGS.includes(args[1]));
let readStdIn = false;
let exitStdIn = false;
const wasiArgs = stdIn
Expand Down
6 changes: 5 additions & 1 deletion components/apps/Terminal/useCommandInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ const useCommandInterpreter = (
case "color": {
const [r, g, b] = commandArgs;

if (r !== undefined && g !== undefined && b !== undefined) {
if (
typeof r === "string" &&
typeof g === "string" &&
typeof b === "string"
) {
print(rgbAnsi(Number(r), Number(g), Number(b)));
} else {
const [[bg, fg] = []] = commandArgs;
Expand Down
2 changes: 1 addition & 1 deletion components/apps/VideoPlayer/useVideoPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const useVideoPlayer = ({
useEffect(() => {
if (loading && !player) {
loadFiles(libs).then(() => {
if (window.videojs !== undefined) {
if (typeof window.videojs === "function") {
loadPlayer();
}
});
Expand Down
7 changes: 1 addition & 6 deletions components/apps/Webamp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export type ButterChurnWebampPreset = {

export type SkinData = Record<string, unknown>;

type EmitterEventData = SkinData;

type CloseWindow = {
type: "CLOSE_WINDOW";
windowId: string;
Expand Down Expand Up @@ -80,10 +78,7 @@ export type WebampCI = Webamp & {
_actionEmitter: {
on: (
event: string,
listener: (emitterEvent: {
data?: EmitterEventData;
type: string;
}) => void
listener: (emitterEvent: { data?: SkinData; type: string }) => void
) => () => void;
};
store: {
Expand Down
2 changes: 1 addition & 1 deletion components/system/Desktop/Wallpapers/useWallpaper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const useWallpaper = (

if (
!failedOffscreenContext.current &&
window.OffscreenCanvas !== undefined &&
typeof window.OffscreenCanvas === "function" &&
wallpaperWorker.current
) {
const workerConfig = { config, devicePixelRatio: 1 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const useSelection = (
clientY,
target,
}) => {
if (target !== containerRef.current) return;
if ((target as HTMLElement) !== containerRef.current) return;

const { scrollTop } = containerRef.current;
const { x: targetX = 0, y: targetY = 0 } =
Expand Down
12 changes: 7 additions & 5 deletions components/system/Files/FileManager/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "components/system/Files/FileManager/useFolder";
import { type SortBy } from "components/system/Files/FileManager/useSortBy";
import { ONE_TIME_PASSIVE_EVENT, ROOT_SHORTCUT } from "utils/constants";
import { haltEvent } from "utils/functions";
import { haltEvent, toSorted } from "utils/functions";

export type FileStat = Stats & {
systemShortcut?: boolean;
Expand Down Expand Up @@ -82,11 +82,11 @@ export const sortContents = (
});

const sortContent = (fileStats: FileStats[]): FileStats[] => {
fileStats.sort(sortByName);
const newFileStats = toSorted(fileStats, sortByName);

return sortFunction && sortFunction !== sortByName
? fileStats.sort(sortFunction)
: fileStats;
? toSorted(newFileStats, sortFunction)
: newFileStats;
};
const sortedFolders = sortContent(folders);
const sortedFiles = sortContent(files);
Expand Down Expand Up @@ -220,7 +220,9 @@ export const handleFileInputEvent = (
event: InputChangeEvent | React.DragEvent,
callback: NewPath,
directory: string,
openTransferDialog: (fileReaders: FileReaders | ObjectReaders) => void,
openTransferDialog: (
fileReaders: FileReaders | ObjectReaders
) => Promise<void>,
hasUpdateId = false
): void => {
haltEvent(event);
Expand Down
2 changes: 1 addition & 1 deletion components/system/Window/RndWindow/useRnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const useRnd = (id: string): Props => {
resizePosition
) => {
const [, x, y] =
transform.match(/translate\((-?\d+)px, (-?\d+)px\)/) || [];
/translate\((-?\d+)px, (-?\d+)px\)/.exec(transform) || [];
const newPositon =
typeof x === "string" && typeof y === "string"
? { x: pxToNum(x), y: pxToNum(y) }
Expand Down
8 changes: 6 additions & 2 deletions components/system/Window/useFocusable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const useFocusable = (
(event) => {
const { relatedTarget } = event;
const focusedElement = relatedTarget as HTMLElement | null;
const focusedOnTaskbarEntry = relatedTarget === taskbarEntry;
const focusedOnTaskbarEntry =
(relatedTarget as HTMLElement) === taskbarEntry;
const focusedOnTaskbarPeek =
focusedElement &&
taskbarEntry?.previousSibling?.contains(focusedElement);
Expand Down Expand Up @@ -71,7 +72,10 @@ const useFocusable = (
if (componentWindow?.contains(document.activeElement)) {
prependToStack(id);
setForegroundId(id);
} else if (!relatedTarget || document.activeElement === taskbarEntry) {
} else if (
!relatedTarget ||
(document.activeElement as HTMLElement) === taskbarEntry
) {
componentWindow?.focus(PREVENT_SCROLL);
callbackEvents?.onFocusCapture?.(
event as React.FocusEvent<HTMLElement>
Expand Down
2 changes: 0 additions & 2 deletions e2e/components/system/Taskbar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable sonarjs/no-duplicate-string */

import { test } from "@playwright/test";
import {
CLOCK_MENU_ITEMS,
Expand Down
9 changes: 5 additions & 4 deletions e2e/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,11 @@ export const backgroundIsUrl = async ({ page }: TestProps): Promise<void> =>
expect(async () =>
expect(
await page.evaluate(() =>
window
.getComputedStyle(document.documentElement)
.getPropertyValue("--before-background")
.match(/^url\(.*?\)/)
/^url\(.*?\)/.exec(
window
.getComputedStyle(document.documentElement)
.getPropertyValue("--before-background")
)
)
).toBeTruthy()
).toPass();
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"fflate": "^0.8.2",
"file-type": "^19.1.1",
"fix-webm-duration": "^1.0.6",
"framer-motion": "^11.3.2",
"framer-motion": "^11.3.4",
"gif.js": "^0.2.0",
"idb": "^8.0.0",
"ini": "^4.1.3",
Expand Down Expand Up @@ -81,14 +81,14 @@
"@axe-core/playwright": "^4.9.1",
"@next/bundle-analyzer": "^14.2.5",
"@next/eslint-plugin-next": "^14.2.5",
"@playwright/test": "^1.45.1",
"@playwright/test": "^1.45.2",
"@types/dompurify": "^3.0.5",
"@types/gif.js": "^0.2.5",
"@types/ini": "^4.1.1",
"@types/jest": "^29.5.12",
"@types/lunr": "^2.3.7",
"@types/minimist": "^1.2.5",
"@types/node": "^20.14.10",
"@types/node": "^20.14.11",
"@types/offscreencanvas": "^2019.7.3",
"@types/opentype.js": "^1.3.8",
"@types/react": "^18.3.3",
Expand All @@ -99,7 +99,7 @@
"@typescript-eslint/parser": "^7.16.1",
"emulators": "^8.1.4",
"emulators-ui": "^0.73.9",
"eruda": "^3.1.0",
"eruda": "^3.2.0",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-next": "^14.2.5",
Expand All @@ -115,7 +115,7 @@
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-hooks-addons": "^0.3.1",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-sonarjs": "^1.0.3",
"eslint-plugin-sonarjs": "^1.0.4-alpha.0",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-typescript-sort-keys": "^3.2.0",
"eslint-plugin-unicorn": "^54.0.0",
Expand All @@ -129,15 +129,15 @@
"lunr": "^2.3.9",
"monaco-editor": "^0.49.0",
"pdfjs-dist": "^4.4.168",
"playwright-core": "^1.45.1",
"playwright-core": "^1.45.2",
"postcss": "^8.4.39",
"postcss-styled-syntax": "^0.6.4",
"postcss-syntax": "^0.36.2",
"serve": "^14.2.3",
"stylelint": "^16.7.0",
"stylelint-config-standard": "^36.0.1",
"stylelint-order": "^6.0.4",
"terser": "^5.31.2",
"terser": "^5.31.3",
"tinymce": "^6.8.3",
"ts-prune": "^0.10.3",
"typescript": "^5.5.3",
Expand Down
5 changes: 5 additions & 0 deletions utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,8 @@ export const parseBgPosition = (position?: string): `${number}%` | "center" => {

return "center";
};

export const toSorted = <T>(
array: T[],
compareFn?: (a: T, b: T) => number
): T[] => [...array].sort(compareFn);
Loading

0 comments on commit 9d4214c

Please sign in to comment.