Skip to content

Commit

Permalink
lint: fix failing eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Sep 14, 2024
1 parent 8f8ac7f commit 04f8322
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 135 deletions.
21 changes: 20 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import globals from "globals";
import eslintPluginUnicorn from "eslint-plugin-unicorn";
import eslintPluginReactHooks from "eslint-plugin-react-hooks";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
languageOptions: {
globals: { ...globals.builtin, ...globals.browser }
},
ignores: ["config/*", "scripts/*", "public/*", "*.test.tsx"],

rules: {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-expressions": "off",
"no-empty": "off",
"unicorn/no-reduce": "off",
"unicorn/no-array-for-each": "off",
"unicorn/no-array-reduce": "off",
"unicorn/no-array-callback-reference": "off",
"unicorn/no-useless-undefined": "off",
"unicorn/prevent-abbreviations": "off",
"unicorn/no-abusive-eslint-disable": "off"
},
plugins: {
"react-hooks": eslintPluginReactHooks,
unicorn: eslintPluginUnicorn
}
}
);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.13",
"@types/lodash": "^4.17.7",
"@types/ramda": "types/npm-ramda",
"@types/ramda": "^0.30.2",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@types/react-onclickoutside": "^6.7.10",
Expand Down Expand Up @@ -129,6 +129,7 @@
"firebase": "^10.13.1",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"fuse.js": "^7.0.0",
"globals": "^15.9.0",
"hex-rgb": "^5.0.0",
"html-webpack-plugin": "5.6.0",
"husky": "^9.1.6",
Expand Down
8 changes: 4 additions & 4 deletions src/components/bottom-tabs/mobile-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ const MobileTabs = ({
/>
)
: mobileTabIndex === 1
? MobileFileTree
: mobileTabIndex === 3
? MobileManual
: undefined}
? MobileFileTree
: mobileTabIndex === 3
? MobileManual
: undefined}
<MobileNavigation
mobileTabIndex={mobileTabIndex}
setMobileTabIndex={setMobileTabIndex}
Expand Down
12 changes: 5 additions & 7 deletions src/components/csound/render-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function fixLeadingSlash(filename) {
}

function FileTypeIcon({ filename }) {
const basename = last(filename.split("/"));
const basename = last(filename.split("/")) || "";
if (basename.endsWith(".csd")) {
return (
<span className="rendered-csd-icon">
Expand Down Expand Up @@ -266,7 +266,6 @@ function AudioPlayer({
"timeupdate",
onAudioProgress
);
// eslint-disable-next-line unicorn/prefer-add-event-listener
audioReference.current.onended = () => {
audioReference &&
audioReference.current &&
Expand Down Expand Up @@ -425,8 +424,8 @@ function RenderModal({
{type === "new"
? "Generated files"
: type === "mod"
? "Files changed after render"
: "Unmodified files"}
? "Files changed after render"
: "Unmodified files"}
</h1>
<List css={rootStyle}>
{Object.keys(data).map((filename) => {
Expand Down Expand Up @@ -537,9 +536,8 @@ function RenderModal({
onClick={async () => {
const bundle = new JSZip();
for (const filename of selectedFiles) {
const arrayBuffer = await csound.fs.readFile(
filename
);
const arrayBuffer =
await csound.fs.readFile(filename);
bundle.file(filename, arrayBuffer);
}

Expand Down
54 changes: 25 additions & 29 deletions src/components/editor/plugins/show-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ function Completion(cm, options) {
this.cm.getLine(this.startPos.line).length -
this.cm.getSelection().length;

const self = this;
cm.on(
"cursorActivity",
(this.activityFunc = function () {
self.cursorActivity();
(this.activityFunc = () => {
this.cursorActivity();
})
);
}
Expand Down Expand Up @@ -152,9 +151,8 @@ Completion.prototype = {
) {
this.close();
} else {
const self = this;
this.debounce = requestAnimationFrame(function () {
self.update();
this.debounce = requestAnimationFrame(() => {
this.update();
});
if (this.widget) {
this.widget.disable();
Expand All @@ -166,11 +164,11 @@ Completion.prototype = {
if (!this.tick) {
return;
}
const self = this;
const myTick = ++this.tick;
fetchHints(this.options.hint, this.cm, this.options, function (data) {
if (self.tick === myTick) {
self.finishUpdate(data, first);

fetchHints(this.options.hint, this.cm, this.options, (data) => {
if (this.tick === myTick) {
this.finishUpdate(data, first);
}
});
},
Expand Down Expand Up @@ -321,8 +319,7 @@ function Widget(completion, data) {
this.completion = completion;
this.data = data;
this.picked = false;
const widget = this,
cm = completion.cm;
const cm = completion.cm;
const ownerDocument = cm.getInputField().ownerDocument;
const parentWindow =
ownerDocument.defaultView || ownerDocument.parentWindow;
Expand Down Expand Up @@ -440,21 +437,21 @@ function Widget(completion, data) {

cm.addKeyMap(
(this.keyMap = buildKeyMap(completion, {
moveFocus: function (n, avoidWrap) {
widget.changeActive(widget.selectedHint + n, avoidWrap);
moveFocus: (n, avoidWrap) => {
this.changeActive(this.selectedHint + n, avoidWrap);
},
setFocus: function (n) {
widget.changeActive(n);
setFocus: (n) => {
this.changeActive(n);
},
menuSize: function () {
return widget.screenAmount();
menuSize: () => {
return this.screenAmount();
},
length: completions.length,
close: function () {
completion.close();
},
pick: function () {
widget.pick();
pick: () => {
this.pick();
},
data: data
}))
Expand Down Expand Up @@ -502,20 +499,20 @@ function Widget(completion, data) {
})
);

CodeMirror.on(hints, "dblclick", function (event) {
CodeMirror.on(hints, "dblclick", (event) => {
const t = getHintElement(hints, event.target || event.srcElement);
if (t && t.hintId) {
widget.changeActive(t.hintId);
widget.pick();
this.changeActive(t.hintId);
this.pick();
}
});

CodeMirror.on(hints, "click", function (event) {
CodeMirror.on(hints, "click", (event) => {
const t = getHintElement(hints, event.target || event.srcElement);
if (t && t.hintId) {
widget.changeActive(t.hintId);
this.changeActive(t.hintId);
if (completion.options.completeOnSingleClick) {
widget.pick();
this.pick();
}
}
});
Expand Down Expand Up @@ -555,10 +552,9 @@ Widget.prototype = {

disable: function () {
this.completion.cm.removeKeyMap(this.keyMap);
const widget = this;
this.keyMap = {
Enter: function () {
widget.picked = true;
Enter: () => {
this.picked = true;
}
};
this.completion.cm.addKeyMap(this.keyMap);
Expand Down
7 changes: 3 additions & 4 deletions src/components/file-tree/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const initialState: DnDState = { docIdx: {} };
export const DnDStateContext = createContext(initialState);

export const DnDDispatchContext = createContext(
// eslint-disable-next-line @typescript-eslint/no-empty-function,@typescript-eslint/no-unused-vars
(dispatch: Record<string, any>): void => {}
);

Expand Down Expand Up @@ -129,17 +128,17 @@ const reducer = (state: DnDState, action: Record<string, any>): DnDState => {
);

const newState = reduceIndexed(
(accumulator, item, newIndex) =>
(accumulator, item: any, newIndex) =>
assocPath(
["docIdx", item.uid, "index"],
newIndex,
accumulator
),
state,
state as DnDState,
reorderedFiles
);

return newState;
return newState as DnDState;
}
case "setDocIdx": {
return assoc("docIdx", action.docIdx, state);
Expand Down
1 change: 0 additions & 1 deletion src/components/hot-keys/hot-keys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const HotKeys = ({
{},
[...keyboardCallbacks.keys()]
),
/* eslint-disable-next-line react-hooks/exhaustive-deps */
[updateCounter]
);
return (
Expand Down
1 change: 0 additions & 1 deletion src/components/main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ const Main = (): React.ReactElement => {
(window as any).ps_body &&
(window as any).ps_body.destroy();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
Expand Down
1 change: 0 additions & 1 deletion src/components/profile/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ const handleProjectTags = async (projectUid, loggedInUserUid, currentTags) => {
query(tags, where(projectUid, "==", loggedInUserUid))
);

/* eslint-disable-next-line unicorn/prefer-object-from-entries */
const currentProjTags = currentProjTagsReference.docs.reduce(
(accumulator, document_) =>
assoc(document_.id, document_.data(), accumulator),
Expand Down
14 changes: 5 additions & 9 deletions src/components/project-editor/actions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { openSimpleModal } from "@comp/modal/actions";
import { IDocument } from "@comp/projects/types";
import { ITarget } from "@comp/target-controls/types";
import { find, propEq } from "ramda";
import { sortByStoredTabOrder } from "./utils";
import {
MANUAL_LOOKUP_STRING,
Expand Down Expand Up @@ -79,19 +78,16 @@ export const tabDockInit = (
});
});
} else if (
/* eslint-disable-next-line unicorn/no-useless-length-check */
allDocuments.length > 0 &&
/* eslint-disable-next-line unicorn/no-useless-length-check */
allDocuments.some((d) => d.filename === "project.csd")
) {
const projectCsd = find(
propEq("filename", "project.csd"),
allDocuments
const projectCsd = allDocuments.find(
(d) => d.filename === "project.csd"
);

projectCsd &&
!find(
propEq("uid", projectCsd.documentUid),
initialOpenDocuments
!initialOpenDocuments.find(
(d) => d.uid === projectCsd.documentUid
) &&
initialOpenDocuments.push({
uid: projectCsd.documentUid
Expand Down
22 changes: 10 additions & 12 deletions src/components/project-editor/project-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type IEditorForDocumentProperties = {
isOwner: boolean;
};

type AnyTab = IDocument | IOpenDocument | NonCloudFile;

const MySplit = ({
primary,
split,
Expand All @@ -70,7 +72,6 @@ const MySplit = ({
onDragFinished,
children
}) => {
/* eslint-disable-next-line unicorn/prefer-native-coercion-functions */
const filteredChildren = children.filter(Boolean);
return filteredChildren.length === 1 ? (
filteredChildren[0]
Expand Down Expand Up @@ -182,7 +183,6 @@ const ProjectEditor = ({
activeProject
);
const isOwner: boolean = useSelector(selectIsOwner(projectUid));
// eslint-disable-next-line unicorn/no-useless-undefined
const csound: CsoundObj | undefined = undefined;

useEffect(() => {
Expand Down Expand Up @@ -236,11 +236,8 @@ const ProjectEditor = ({
pathOr(-1, ["ProjectEditorReducer", "tabDock", "tabIndex"])
);

const openDocuments: (IDocument | IOpenDocument)[] = reduce(
(
accumulator: (IDocument | IOpenDocument)[],
tabDocument: IOpenDocument
) => {
const openDocuments: AnyTab[] = tabDockDocuments.reduce(
(accumulator: AnyTab[], tabDocument: IOpenDocument) => {
const maybeDocument = pathOr(
{} as IDocument,
["documents", propOr("", "uid", tabDocument)],
Expand All @@ -252,11 +249,10 @@ const ProjectEditor = ({
return isNonCloudFile
? append(tabDocument, accumulator)
: maybeDocument && Object.keys(maybeDocument).length > 0
? append(maybeDocument, accumulator)
: accumulator;
? append(maybeDocument, accumulator)
: accumulator;
},
[] as (IDocument | NonCloudFile)[],
tabDockDocuments
[] as AnyTab[]
);

const closeTab = (documentUid, isModified) => {
Expand Down Expand Up @@ -376,7 +372,9 @@ const ProjectEditor = ({
<MobileTabs
activeProject={activeProject}
projectUid={projectUid}
currentDocument={openDocuments[tabIndex]}
currentDocument={
openDocuments[tabIndex] as IDocument | IOpenDocument | undefined
}
/>
) : (
<>
Expand Down
Loading

0 comments on commit 04f8322

Please sign in to comment.