From f219e0ef3a6bb7e261dc117e9fe65e567e8741ad Mon Sep 17 00:00:00 2001 From: Oliver Ford Date: Sun, 5 Feb 2023 11:42:05 +0000 Subject: [PATCH 01/12] Add eslint --- .pre-commit-config.yaml | 15 +- eml-client/.gitignore | 3 +- eml-client/.prettierignore | 2 + eml-client/eslint.config.js | 144 +++ eml-client/justfile | 4 + eml-client/package.json | 6 + eml-client/prettier.config.cjs | 5 + eml-client/src/App.svelte | 154 ++- eml-client/src/api.js | 91 +- eml-client/src/components/Eml.svelte | 96 +- eml-client/src/components/EmlAddresses.svelte | 55 +- .../src/components/EmlAttachment.svelte | 99 +- eml-client/src/components/EmlBodyPart.svelte | 17 +- eml-client/src/components/EmlCompose.svelte | 61 +- eml-client/src/components/EmlList.svelte | 22 +- eml-client/src/components/EmlListItem.svelte | 19 +- eml-client/src/components/EmlNewModal.svelte | 52 +- .../src/components/EmlReplyModal.svelte | 54 +- eml-client/src/components/NavQueryItem.svelte | 19 +- .../src/components/PdfAttachmentViewer.svelte | 64 +- eml-client/src/components/RelativeDate.svelte | 47 +- eml-client/src/components/Search.svelte | 8 +- eml-client/src/components/TagBadges.svelte | 12 +- .../src/components/TagQueryModal.svelte | 32 +- eml-client/src/components/TagsSelect.svelte | 24 +- eml-client/src/components/VCalSummary.svelte | 76 +- eml-client/src/main.js | 8 +- eml-client/svelte.config.js | 8 +- eml-client/vite.config.js | 13 +- eml-client/yarn.lock | 1129 ++++++++++++++++- 30 files changed, 1872 insertions(+), 467 deletions(-) create mode 100644 eml-client/.prettierignore create mode 100644 eml-client/eslint.config.js create mode 100644 eml-client/prettier.config.cjs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e5c105..0c60238 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,14 +21,6 @@ repos: - id: terraform_fmt - id: terraform_validate - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.5.1 - hooks: - - id: prettier - additional_dependencies: - - prettier - - prettier-plugin-svelte@2.3.1 - - repo: local hooks: - id: cargo-test @@ -37,3 +29,10 @@ repos: entry: cargo test files: ^.*\.rs pass_filenames: false + + - id: lint-eml-client + name: Lint eml-client + language: system + entry: just eml-client/lint + files: ^eml-client/ + pass_filenames: false diff --git a/eml-client/.gitignore b/eml-client/.gitignore index fe7d047..9b1c8b1 100644 --- a/eml-client/.gitignore +++ b/eml-client/.gitignore @@ -1,2 +1 @@ -/dist/build/* -/dist/index.tauri.html +/dist diff --git a/eml-client/.prettierignore b/eml-client/.prettierignore new file mode 100644 index 0000000..5076b76 --- /dev/null +++ b/eml-client/.prettierignore @@ -0,0 +1,2 @@ +dist/ +target/ diff --git a/eml-client/eslint.config.js b/eml-client/eslint.config.js new file mode 100644 index 0000000..79cd1c2 --- /dev/null +++ b/eml-client/eslint.config.js @@ -0,0 +1,144 @@ +import importPlugin from "eslint-plugin-import" +import modulesNewlines from "@spence1115/eslint-plugin-modules-newlines" +import svelteParser from "svelte-eslint-parser" +import svelte from "eslint-plugin-svelte" + +export default [ + "eslint:recommended", + + { + ignores: [ + "**/dist/*", + "**/target/*", + ], + }, + + { + languageOptions: { + globals: { + Intl: true, + console: true, + document: true, + process: true, + setInterval: true, + }, + }, + + plugins: { + modulesNewlines, + import: importPlugin, + svelte, + }, + + rules: { + "array-bracket-newline": [ + "error", + { + minItems: 1, + }, + ], + "array-element-newline": [ + "error", + { + minItems: 1, + }, + ], + "comma-dangle": [ + "error", + "always-multiline", + ], + "dot-location": [ + "error", + "property", + ], + "modulesNewlines/import-declaration-newline": "error", + "implicit-arrow-linebreak": [ + "error", + "beside", + ], + "import/order": [ + "error", + ], + "import/newline-after-import": [ + "error", + { + considerComments: true, + }, + ], + indent: [ + "error", + 2, + ], + "newline-per-chained-call": [ + "error", + { + ignoreChainWithDepth: 1, + }, + ], + "no-trailing-spaces": "error", + "object-curly-newline": [ + "error", + { + minProperties: 1, + }, + ], + "object-property-newline": [ + "error", + { + allowAllPropertiesOnSameLine: false, + }, + ], + "one-var": [ + "error", + "never", + ], + "operator-linebreak": [ + "error", + "before", + { + overrides: { + "=": "none", + }, + }, + ], + "padded-blocks": [ + "error", + "never", + { + allowSingleLineBlocks: false, + }, + ], + semi: [ + "error", + "never", + ], + "sort-imports": [ + "error", + { + allowSeparatedGroups: true, + ignoreDeclarationSort: true, // Handled by import/order rule + }, + ], + "quote-props": [ + "error", + "as-needed", + ], + }, + }, + + { + files: [ + "**/*.svelte", + ], + + languageOptions: { + parser: svelteParser, + }, + + rules: { + ...svelte.configs.recommended.rules, + "init-declarations": "off", + "svelte/no-at-html-tags": "warn", // pending disable line + }, + }, +] diff --git a/eml-client/justfile b/eml-client/justfile index 0b1de1d..5522d76 100644 --- a/eml-client/justfile +++ b/eml-client/justfile @@ -1,2 +1,6 @@ dev: cargo tauri dev + +lint: + yarn prettier --write . + yarn eslint --fix . diff --git a/eml-client/package.json b/eml-client/package.json index 34b6624..4ec564a 100644 --- a/eml-client/package.json +++ b/eml-client/package.json @@ -1,13 +1,19 @@ { "devDependencies": { "@fortawesome/free-solid-svg-icons": "^6.0.0", + "@spence1115/eslint-plugin-modules-newlines": "^1.0.1", "@sveltejs/vite-plugin-svelte": "^2.0.2", "@tauri-apps/cli": "^1.0.0-rc", "bootstrap-scss": "5.2.*", "bootswatch": "^5.0.2", + "eslint": "^8.33.0", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-svelte": "^2.15.0", "fa-svelte": "^3.1.0", "ical.js": "^1.5.0", "pdfjs-dist": "^3.0.279", + "prettier": "^2.8.3", + "prettier-plugin-svelte": "^2.9.0", "sass": "^1.58.0", "svelte": "^3.39.0", "svelte-pdfjs": "^0.6.1", diff --git a/eml-client/prettier.config.cjs b/eml-client/prettier.config.cjs new file mode 100644 index 0000000..410e9be --- /dev/null +++ b/eml-client/prettier.config.cjs @@ -0,0 +1,5 @@ +module.exports = { + plugins: [ + "prettier-plugin-svelte", + ], +} diff --git a/eml-client/src/App.svelte b/eml-client/src/App.svelte index 8c6625c..03d34d0 100644 --- a/eml-client/src/App.svelte +++ b/eml-client/src/App.svelte @@ -1,83 +1,100 @@ @@ -130,15 +147,16 @@ t.query)} + quietQueries={specialQueries.concat(tagQueries) + .map((t) => t.query)} /> { - tagSelected = tag.detail; - tagModalOpen = true; + tagSelected = tag.detail + tagModalOpen = true }} /> @@ -148,8 +166,8 @@ tag={tagSelected} query={querySelected} on:tagsUpdated={() => { - refreshTagList(); - refreshQuery(); + refreshTagList() + refreshQuery() }} /> @@ -170,8 +188,8 @@ { - refreshTagList(); - refreshQuery(); + refreshTagList() + refreshQuery() }} /> diff --git a/eml-client/src/api.js b/eml-client/src/api.js index cc75489..e966eb1 100644 --- a/eml-client/src/api.js +++ b/eml-client/src/api.js @@ -1,32 +1,59 @@ -import * as tauri from "@tauri-apps/api/tauri"; - -export const applyTag = (query, tag, dispatch) => - tauri - .invoke("apply_tag", { query, tag }) - .then(() => Promise.resolve("tagsUpdated", { tags: [tag] })); - -export const getName = () => tauri.invoke("get_name"); - -export const getReplyTemplate = (id) => - tauri.invoke("get_reply_template", { id }); - -export const listEml = (query) => tauri.invoke("list_eml", { query }); - -export const listTags = () => tauri.invoke("list_tags"); - -export const countMatches = (query) => tauri.invoke("count_matches", { query }); - -export const rmTag = (query, tag) => - tauri - .invoke("rm_tag", { query, tag }) - .then(() => Promise.resolve("tagsUpdated", { tags: [tag] })); - -export const previewEml = (meta, body, attachments = []) => - tauri.invoke("preview_eml", { meta, body, attachments }); - -export const sendEml = (meta, body, attachments = []) => - tauri.invoke("send_eml", { meta, body, attachments }); - -export const tagList = () => tauri.invoke("list_tags"); - -export const viewEml = (id) => tauri.invoke("view_eml", { id }); +import * as tauri from "@tauri-apps/api/tauri" + +export const applyTag = (query, tag) => tauri + .invoke("apply_tag", { + query, + tag, + }) + .then(() => Promise.resolve("tagsUpdated", { + tags: [ + tag, + ], + }), + ) + +export const getName = () => tauri.invoke("get_name") + +export const getReplyTemplate = (id) => tauri.invoke("get_reply_template", { + id, +}) + +export const listEml = (query) => tauri.invoke("list_eml", { + query, +}) + +export const listTags = () => tauri.invoke("list_tags") + +export const countMatches = (query) => tauri.invoke("count_matches", { + query, +}) + +export const rmTag = (query, tag) => tauri + .invoke("rm_tag", { + query, + tag, + }) + .then(() => Promise.resolve("tagsUpdated", { + tags: [ + tag, + ], + }), + ) + +export const previewEml = (meta, body, attachments = []) => tauri.invoke("preview_eml", { + meta, + body, + attachments, +}) + +export const sendEml = (meta, body, attachments = []) => tauri.invoke("send_eml", { + meta, + body, + attachments, +}) + +export const tagList = () => tauri.invoke("list_tags") + +export const viewEml = (id) => tauri.invoke("view_eml", { + id, +}) diff --git a/eml-client/src/components/Eml.svelte b/eml-client/src/components/Eml.svelte index 85ee17c..29399c2 100644 --- a/eml-client/src/components/Eml.svelte +++ b/eml-client/src/components/Eml.svelte @@ -1,60 +1,72 @@ @@ -91,7 +103,7 @@ {#each alts.filter((a) => a != selectedAlt) as alt} { - selectedAlt = alt; + selectedAlt = alt }} > {alt.mimetype} @@ -105,14 +117,15 @@ {#if emlMeta.tags.includes("inbox")} {:else} @@ -122,14 +135,15 @@ {#if !emlMeta.tags.includes("spam")} {:else} diff --git a/eml-client/src/components/EmlAddresses.svelte b/eml-client/src/components/EmlAddresses.svelte index 8c90401..847cba5 100644 --- a/eml-client/src/components/EmlAddresses.svelte +++ b/eml-client/src/components/EmlAddresses.svelte @@ -1,36 +1,43 @@

diff --git a/eml-client/src/components/EmlAttachment.svelte b/eml-client/src/components/EmlAttachment.svelte index e439e39..e697b0e 100644 --- a/eml-client/src/components/EmlAttachment.svelte +++ b/eml-client/src/components/EmlAttachment.svelte @@ -1,72 +1,71 @@ { - if (ev.key == "Escape") previewOpen = false; + if (ev.key == "Escape") { + previewOpen = false + } }} /> diff --git a/eml-client/src/components/EmlBodyPart.svelte b/eml-client/src/components/EmlBodyPart.svelte index 48c8e63..99d0d2c 100644 --- a/eml-client/src/components/EmlBodyPart.svelte +++ b/eml-client/src/components/EmlBodyPart.svelte @@ -1,15 +1,20 @@ {#if part.is_cleaned_html} diff --git a/eml-client/src/components/EmlCompose.svelte b/eml-client/src/components/EmlCompose.svelte index 5c2acec..ef20b70 100644 --- a/eml-client/src/components/EmlCompose.svelte +++ b/eml-client/src/components/EmlCompose.svelte @@ -1,43 +1,52 @@ diff --git a/eml-client/src/components/EmlList.svelte b/eml-client/src/components/EmlList.svelte index cf091da..c0e64c3 100644 --- a/eml-client/src/components/EmlList.svelte +++ b/eml-client/src/components/EmlList.svelte @@ -3,18 +3,18 @@ ListGroup, ListGroupItem, Spinner, - // - } from "sveltestrap"; + } from "sveltestrap" - import * as api from "../api.js"; - import EmlListItem from "./EmlListItem.svelte"; + import * as api from "../api.js" + import EmlListItem from "./EmlListItem.svelte" - export let emlSelected = null; - export let hideTags = new Set(); - export let query; + export let emlSelected = null + export let hideTags = new Set() + export let query - let emls = null; - $: api.listEml(query).then((emlList) => (emls = emlList)); + let emls = null + $: api.listEml(query) + .then((emlList) => (emls = emlList)) {#if emls == null} @@ -29,8 +29,8 @@ color={emlMeta.Err ? "warning" : emlSelected && emlSelected.id == emlMeta.Ok.id - ? "secondary" - : ""} + ? "secondary" + : ""} > {#if emlMeta.Ok} diff --git a/eml-client/src/components/EmlListItem.svelte b/eml-client/src/components/EmlListItem.svelte index a9b6038..e7948b9 100644 --- a/eml-client/src/components/EmlListItem.svelte +++ b/eml-client/src/components/EmlListItem.svelte @@ -1,16 +1,15 @@
@@ -38,14 +37,16 @@ {#if emlMeta.sender} - {#if emlMeta.from.map((m) => m.name).includes(emlMeta.sender.name)} + {#if emlMeta.from.map((m) => m.name) + .includes(emlMeta.sender.name)} {emlMeta.sender.address} {:else} {emlMeta.sender.name} {/if} on behalf of {/if} - {emlMeta.from.map((m) => m.name).join(", ")} + {emlMeta.from.map((m) => m.name) + .join(", ")}
diff --git a/eml-client/src/components/EmlNewModal.svelte b/eml-client/src/components/EmlNewModal.svelte index 8279178..fca45e6 100644 --- a/eml-client/src/components/EmlNewModal.svelte +++ b/eml-client/src/components/EmlNewModal.svelte @@ -5,18 +5,17 @@ ModalBody, ModalFooter, ModalHeader, - // - } from "sveltestrap"; + } from "sveltestrap" - import * as api from "../api.js"; - import EmlCompose from "./EmlCompose.svelte"; + import * as api from "../api.js" + import EmlCompose from "./EmlCompose.svelte" - export let isOpen; + export let isOpen - let emlMeta; - let body; - let attachments; - let confirm; + let attachments + let body + let confirm + let emlMeta const init = () => { emlMeta = { @@ -26,31 +25,36 @@ tags: [], timestamp: Number((Date.now() / 1000).toFixed()), to: [], - }; - body = ""; - attachments = []; - confirm = null; - }; + } + body = "" + attachments = [] + confirm = null + } - init(); + init() const toggle = () => { - isOpen = !isOpen; - return Promise.resolve(isOpen); - }; + isOpen = !isOpen + return Promise.resolve(isOpen) + } const toggleConfirm = async () => { - if (confirm) confirm = null; - else confirm = await api.previewEml(emlMeta, body, attachments); - }; + if (confirm) { + confirm = null + } else { + confirm = await api.previewEml(emlMeta, body, attachments) + } + } - const send = () => - api.sendEml(emlMeta, body, attachments).then(toggle).then(init); + const send = () => api.sendEml(emlMeta, body, attachments) + .then(toggle) + .then(init) toggle().then((open) => (open ? null : (confirm = false)))} + toggle={() => toggle() + .then((open) => (open ? null : (confirm = false)))} > {#if confirm}Sure?{/if} diff --git a/eml-client/src/components/EmlReplyModal.svelte b/eml-client/src/components/EmlReplyModal.svelte index c1b66f2..ca6cebc 100644 --- a/eml-client/src/components/EmlReplyModal.svelte +++ b/eml-client/src/components/EmlReplyModal.svelte @@ -5,45 +5,55 @@ ModalBody, ModalFooter, ModalHeader, - // - } from "sveltestrap"; + } from "sveltestrap" - import * as api from "../api.js"; - import EmlCompose from "./EmlCompose.svelte"; + import * as api from "../api.js" + import EmlCompose from "./EmlCompose.svelte" - export let emlMeta; - export let isOpen; + export let emlMeta + export let isOpen + + let attachments + let body + let confirm + let replyMeta - let attachments, body, confirm, replyMeta; const refreshMeta = async () => { - attachments = []; - confirm = null; + attachments = [] + confirm = null console.debug(`getting template for reply to ${emlMeta.id}`); - ({ meta: replyMeta, body } = await api.getReplyTemplate(emlMeta.id)); - console.debug(replyMeta); - }; + ({ + meta: replyMeta, body, + } = await api.getReplyTemplate(emlMeta.id)) + console.debug(replyMeta) + } $: if (isOpen) { - refreshMeta(); + refreshMeta() } else { - replyMeta = null; + replyMeta = null } const toggle = () => { - isOpen = !isOpen; - return Promise.resolve(isOpen); - }; + isOpen = !isOpen + return Promise.resolve(isOpen) + } const toggleConfirm = async () => { - if (confirm) confirm = null; - else confirm = await api.previewEml(replyMeta, body, attachments); - }; + if (confirm) { + confirm = null + } else { + confirm = await api.previewEml(replyMeta, body, attachments) + } + } - const send = () => api.sendEml(replyMeta, body, attachments).then(toggle); + const send = () => api.sendEml(replyMeta, body, attachments) + .then(toggle) toggle().then((open) => (open ? null : (confirm = false)))} + toggle={() => toggle() + .then((open) => (open ? null : (confirm = false)))} > {#if confirm}Sure?{:else}Reply{/if} diff --git a/eml-client/src/components/NavQueryItem.svelte b/eml-client/src/components/NavQueryItem.svelte index 4a7c6c4..95567d7 100644 --- a/eml-client/src/components/NavQueryItem.svelte +++ b/eml-client/src/components/NavQueryItem.svelte @@ -1,17 +1,22 @@ diff --git a/eml-client/src/components/PdfAttachmentViewer.svelte b/eml-client/src/components/PdfAttachmentViewer.svelte index ecde882..39d7143 100644 --- a/eml-client/src/components/PdfAttachmentViewer.svelte +++ b/eml-client/src/components/PdfAttachmentViewer.svelte @@ -1,37 +1,41 @@ @@ -41,18 +45,26 @@ {#if !atBeginning} + + handleKey({ key: "ArrowLeft" })} + on:click={() => handleKey({ + key: "ArrowLeft", + })} > {/if} {#if !atEnd} + + handleKey({ key: "ArrowRight" })} + on:click={() => handleKey({ + key: "ArrowRight", + })} > diff --git a/eml-client/src/components/RelativeDate.svelte b/eml-client/src/components/RelativeDate.svelte index c62fa88..eec9f51 100644 --- a/eml-client/src/components/RelativeDate.svelte +++ b/eml-client/src/components/RelativeDate.svelte @@ -1,47 +1,54 @@ {formattedDate} diff --git a/eml-client/src/components/Search.svelte b/eml-client/src/components/Search.svelte index b1679f3..dac2be1 100644 --- a/eml-client/src/components/Search.svelte +++ b/eml-client/src/components/Search.svelte @@ -1,8 +1,10 @@