diff --git a/gdn-app/eslint.config.js b/gdn-app/eslint.config.js index eaecbff..ac54ec1 100644 --- a/gdn-app/eslint.config.js +++ b/gdn-app/eslint.config.js @@ -34,4 +34,19 @@ export default tseslint.config( // Tell the vue parser that it should use the ts parser instead of the js parser. { files: ["**/*.vue"], languageOptions: { parserOptions: { parser: tseslint.parser } } }, + + // My own rules. + // + // https://eslint.org/docs/latest/rules/ + // https://typescript-eslint.io/rules/ + // https://eslint.vuejs.org/rules/ + { + rules: { + "@typescript-eslint/explicit-function-return-type": "error", + "vue/block-lang": ["error", { script: { lang: "ts" } }], + "vue/block-order": ["error", { order: ["script", "template", "style"] }], + "vue/component-api-style": ["error", ["script-setup"]], + "vue/v-for-delimiter-style": ["error", "of"], + }, + }, ); diff --git a/gdn-app/src/components/CNavbar.vue b/gdn-app/src/components/CNavbar.vue index 8d64965..3de2de8 100644 --- a/gdn-app/src/components/CNavbar.vue +++ b/gdn-app/src/components/CNavbar.vue @@ -17,7 +17,7 @@ function mkNote(text: string, ...children: string[]): Note { return note; } -function createSomeNotes() { +function createSomeNotes(): void { notes.clearNotes(); const n2n1 = mkNote("n2n1"); diff --git a/gdn-app/src/components/CNavbarDropdown.vue b/gdn-app/src/components/CNavbarDropdown.vue index e3eb6fe..a33bbba 100644 --- a/gdn-app/src/components/CNavbarDropdown.vue +++ b/gdn-app/src/components/CNavbarDropdown.vue @@ -25,14 +25,14 @@ const { floatingStyles } = useFloating(reference, floating, { ], }); -function onAddNewRepo() { +function onAddNewRepo(): void { const id = crypto.randomUUID(); repos.addRepo({ id, name: id }); console.log(repos.selectedRepo); open.value = false; } -function onSelectRepo(id: string) { +function onSelectRepo(id: string): void { repos.selectRepo(id); open.value = false; } diff --git a/gdn-app/src/components/CNote.vue b/gdn-app/src/components/CNote.vue index f561d67..152523d 100644 --- a/gdn-app/src/components/CNote.vue +++ b/gdn-app/src/components/CNote.vue @@ -76,11 +76,11 @@ watchEffect(() => { if (mode.value) focusOnThis(); }); -function focusOnThis() { +function focusOnThis(): void { ui.focusPath = props.path; } -function onClick() { +function onClick(): void { if (!focused.value) { focusOnThis(); return; @@ -89,36 +89,36 @@ function onClick() { ui.toggleOpen(props.path); } -function onPinButtonClick() { +function onPinButtonClick(): void { if (pinned.value) ui.unsetPinned(); else ui.setPinned(props.segment, props.parentId); } -function onEditButtonClick() { +function onEditButtonClick(): void { if (!note.value) return; mode.value = "editing"; } -function onEditEditorClose() { +function onEditEditorClose(): void { mode.value = undefined; } -function onEditEditorFinish(text: string) { +function onEditEditorFinish(text: string): void { if (!note.value) return; note.value.text = text; onEditEditorClose(); } -function onCreateButtonClick() { +function onCreateButtonClick(): void { if (!note.value) return; mode.value = "creating"; } -function onCreateEditorClose() { +function onCreateEditorClose(): void { mode.value = undefined; } -function onCreateEditorFinish(text: string) { +function onCreateEditorFinish(text: string): void { if (!note.value) return; const newNote = notes.createNote(text); diff --git a/gdn-app/src/components/CNoteEditor.vue b/gdn-app/src/components/CNoteEditor.vue index 80a8d8c..fd88987 100644 --- a/gdn-app/src/components/CNoteEditor.vue +++ b/gdn-app/src/components/CNoteEditor.vue @@ -20,17 +20,17 @@ onMounted(() => { updateTextareaHeight(); }); -function updateTextareaHeight() { +function updateTextareaHeight(): void { if (!textarea.value) return; textarea.value.style.height = "0px"; textarea.value.style.height = `${textarea.value.scrollHeight.toFixed()}px`; } -function onInput() { +function onInput(): void { updateTextareaHeight(); } -function onKeyPress(ev: KeyboardEvent) { +function onKeyPress(ev: KeyboardEvent): void { if (ev.key === "Escape") { emit("close"); } else if (ev.key === "Enter" && !ev.shiftKey) { diff --git a/gdn-app/src/stores/notes.ts b/gdn-app/src/stores/notes.ts index aee1c78..8896393 100644 --- a/gdn-app/src/stores/notes.ts +++ b/gdn-app/src/stores/notes.ts @@ -37,7 +37,7 @@ export const useNotesStore = defineStore("notes", () => { return notes.value.get(id)!; // Re-getting so returned Note is reactive } - function clearNotes() { + function clearNotes(): void { notes.value.clear(); } diff --git a/gdn-app/src/stores/repos.ts b/gdn-app/src/stores/repos.ts index 60786b1..ca6fed4 100644 --- a/gdn-app/src/stores/repos.ts +++ b/gdn-app/src/stores/repos.ts @@ -23,12 +23,12 @@ export const useReposStore = defineStore("repos", () => { const repoIdsByName = computed(() => reposByName.value.map((it) => it.id)); - function addRepo(repo: Repo) { + function addRepo(repo: Repo): void { repos.value.set(repo.id, repo); selectedRepoId.value = repo.id; } - function removeRepo(id: string | undefined) { + function removeRepo(id: string | undefined): void { if (id === undefined) return; const i = repoIdsByName.value.indexOf(id); repos.value.delete(id); @@ -38,7 +38,7 @@ export const useReposStore = defineStore("repos", () => { } } - function selectRepo(id: string | undefined) { + function selectRepo(id: string | undefined): void { if (id === undefined) return; if (repos.value.get(id) === undefined) return; selectedRepoId.value = id; diff --git a/gdn-app/src/stores/ui.ts b/gdn-app/src/stores/ui.ts index 12c15e2..b4ce770 100644 --- a/gdn-app/src/stores/ui.ts +++ b/gdn-app/src/stores/ui.ts @@ -20,7 +20,7 @@ export const useUiStore = defineStore("ui", () => { return openPaths.value.has(path.fmt()); } - function setOpen(path: UiPath, value: boolean) { + function setOpen(path: UiPath, value: boolean): void { // Don't update openPaths unnecessarily. // Just in case vue itself doesn't debounce Set operations. if (value && !isOpen(path)) { @@ -33,7 +33,7 @@ export const useUiStore = defineStore("ui", () => { } } - function toggleOpen(path: UiPath) { + function toggleOpen(path: UiPath): void { setOpen(path, !isOpen(path)); } @@ -42,11 +42,11 @@ export const useUiStore = defineStore("ui", () => { return pinned.value.segment.eq(segment) && pinned.value.parentId === parentId; } - function setPinned(segment: Segment, parentId?: string) { + function setPinned(segment: Segment, parentId?: string): void { pinned.value = { segment, parentId }; } - function unsetPinned() { + function unsetPinned(): void { pinned.value = undefined; }