From 5a33c581fd002b762acba6740e6db479560579f2 Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Wed, 28 Apr 2021 23:05:08 +0200 Subject: [PATCH] Auto-format code (#277) --- .github/config/dprint.json | 25 +++++++++++++++++++++++++ package.json | 3 ++- source/.eslintrc.yml | 12 ++---------- source/app/action/index.mjs | 4 +++- source/app/metrics/utils.mjs | 2 +- source/app/mocks/.eslintrc.yml | 3 +-- source/plugins/achievements/index.mjs | 2 +- source/plugins/habits/index.mjs | 2 +- source/plugins/licenses/index.mjs | 4 +++- source/plugins/tweets/index.mjs | 4 ++-- 10 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 .github/config/dprint.json diff --git a/.github/config/dprint.json b/.github/config/dprint.json new file mode 100644 index 00000000..034516f2 --- /dev/null +++ b/.github/config/dprint.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://dprint.dev/schemas/v0.json", + "projectType": "openSource", + "incremental": true, + "indentWidth": 2, + "typescript": { + "lineWidth": 280, + "semiColons": "asi", + "quoteStyle": "preferDouble", + "useBraces": "preferNone", + "singleBodyPosition": "nextLine", + "arrowFunction.useParentheses": "preferNone", + "commentLine.forceSpaceAfterSlashes": false, + "taggedTemplate.spaceBeforeLiteral": false, + "nextControlFlowPosition": "nextLine" + }, + "includes": ["**/*.{js,mjs}"], + "excludes": [ + "**/node_modules", + "**/.github" + ], + "plugins": [ + "https://plugins.dprint.dev/typescript-0.42.0.wasm" + ] +} diff --git a/package.json b/package.json index fbfd9208..2306e6fc 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "preview": "node .github/preview.mjs", "linter": "eslint source/**/*.mjs", "dev": "nodemon source/app/web/index.mjs -e mjs,css,ejs,json", - "postinstall": "node node_modules/puppeteer/install.js" + "postinstall": "node node_modules/puppeteer/install.js", + "fmt": "dprint fmt --config .github/config/dprint.json && eslint source/**/*.mjs --fix" }, "repository": { "type": "git", diff --git a/source/.eslintrc.yml b/source/.eslintrc.yml index 04f525a7..07fb0281 100644 --- a/source/.eslintrc.yml +++ b/source/.eslintrc.yml @@ -89,7 +89,6 @@ rules: # Prefer using new syntax and features prefer-regex-literals: error - prefer-named-capture-group: error prefer-arrow-callback: error prefer-destructuring: error prefer-numeric-literals: error @@ -103,15 +102,15 @@ rules: no-unsafe-finally: off # ========================================================================= - # Rules below are really motivated by # Code style (general rules) no-tabs: error no-trailing-spaces: error brace-style: [error, stroustrup] - comma-dangle: [error, always-multiline] comma-style: error sort-vars: error + no-async-promise-executor: off + no-misleading-character-class: off # Coding style (quoting rules) quote-props: [error, as-needed, {numbers: true}] @@ -120,7 +119,6 @@ rules: # Coding style (comments rules) line-comment-position: error - capitalized-comments: error # Coding style (spacing rules) block-spacing: [error, always] @@ -128,14 +126,10 @@ rules: func-call-spacing: error arrow-spacing: error generator-star-spacing: error - object-curly-spacing: [error, never] rest-spread-spacing: error - key-spacing: [error, {afterColon: false}] computed-property-spacing: error - switch-colon-spacing: [error, {after: false}] array-bracket-spacing: [error, never] no-whitespace-before-property: error - space-before-function-paren: [error, never] space-in-parens: error spaced-comment: [error, never] lines-between-class-members: error @@ -148,8 +142,6 @@ rules: no-new-func: error no-new-wrappers: error func-names: [error, never] - function-call-argument-newline: [error, never] - function-paren-newline: [error, never] no-extra-parens: [error, functions] arrow-body-style: [error, as-needed] arrow-parens: [error, as-needed] diff --git a/source/app/action/index.mjs b/source/app/action/index.mjs index 12ada790..f54fcbaf 100644 --- a/source/app/action/index.mjs +++ b/source/app/action/index.mjs @@ -8,7 +8,9 @@ import fs from "fs/promises" import paths from "path" import sgit from "simple-git" - process.on("unhandledRejection", error => { throw error }) //eslint-disable-line max-statements-per-line, brace-style + process.on("unhandledRejection", error => { + throw error + }) //Debug message buffer let DEBUG = true diff --git a/source/app/metrics/utils.mjs b/source/app/metrics/utils.mjs index 749c0dd3..b5c652ab 100644 --- a/source/app/metrics/utils.mjs +++ b/source/app/metrics/utils.mjs @@ -344,7 +344,7 @@ //Apply replacements for (const [emoji, twemoji] of emojis) { if (custom) - rendered = rendered.replace(new RegExp(`[^>]*)>${emoji}`, "g"), twemoji.replace(/()/, "$1 $ $2")) //eslint-disable-line prefer-named-capture-group + rendered = rendered.replace(new RegExp(`[^>]*)>${emoji}`, "g"), twemoji.replace(/()/, "$1 $ $2")) rendered = rendered.replace(new RegExp(emoji, "g"), twemoji) } return rendered diff --git a/source/app/mocks/.eslintrc.yml b/source/app/mocks/.eslintrc.yml index 24f4cc11..888a7814 100644 --- a/source/app/mocks/.eslintrc.yml +++ b/source/app/mocks/.eslintrc.yml @@ -1,5 +1,4 @@ # Overrides enforced rules for mocks rules: max-params: off - no-unused-vars: off - prefer-named-capture-group: off \ No newline at end of file + no-unused-vars: off \ No newline at end of file diff --git a/source/plugins/achievements/index.mjs b/source/plugins/achievements/index.mjs index dd7a2e07..4dbc0e06 100644 --- a/source/plugins/achievements/index.mjs +++ b/source/plugins/achievements/index.mjs @@ -65,7 +65,7 @@ /**Total extracter */ async function total({imports}) { if (!total.promise) { - total.promise = new Promise(async(solve, reject) => { //eslint-disable-line no-async-promise-executor + total.promise = new Promise(async(solve, reject) => { //Setup browser console.debug("metrics/compute/plugins > achievements > filling total from github.com/search") const browser = await imports.puppeteer.launch() diff --git a/source/plugins/habits/index.mjs b/source/plugins/habits/index.mjs index 3751e3f7..617f0ba4 100644 --- a/source/plugins/habits/index.mjs +++ b/source/plugins/habits/index.mjs @@ -74,7 +74,7 @@ //Attempt to guess whether tabs or spaces are used in patches console.debug(`metrics/compute/${login}/plugins > habits > searching indent style`) patches - .map(({patch}) => patch.match(/((?:\t)|(?:[ ]{2})) /gm) ?? []) //eslint-disable-line prefer-named-capture-group + .map(({patch}) => patch.match(/((?:\t)|(?:[ ]{2})) /gm) ?? []) .forEach(indent => habits.indents[/^\t/.test(indent) ? "tabs" : "spaces"]++) habits.indents.style = habits.indents.spaces > habits.indents.tabs ? "spaces" : habits.indents.tabs > habits.indents.spaces ? "tabs" : "" } diff --git a/source/plugins/licenses/index.mjs b/source/plugins/licenses/index.mjs index 0f71db27..fc2b21d2 100644 --- a/source/plugins/licenses/index.mjs +++ b/source/plugins/licenses/index.mjs @@ -16,8 +16,10 @@ //Register existing licenses properties const licenses = Object.fromEntries((await graphql(queries.licenses())).licenses.map(license => [license.key, license])) - for (const license of Object.values(licenses)) + for (const license of Object.values(licenses)) { + //dprint-ignore [...license.limitations, ...license.conditions, ...license.permissions].flat().map(({key, label}) => text[key] = label) + } colors(licenses) //Check if licensed exists diff --git a/source/plugins/tweets/index.mjs b/source/plugins/tweets/index.mjs index dc2c2fa4..c16cca94 100644 --- a/source/plugins/tweets/index.mjs +++ b/source/plugins/tweets/index.mjs @@ -64,13 +64,13 @@ //Format text console.debug(`metrics/compute/${login}/plugins > tweets > formatting tweet ${tweet.id}`) tweet.createdAt = `${imports.date(tweet.created_at, {timeStyle:"short", timeZone:data.config.timezone?.name})} on ${imports.date(tweet.created_at, {dateStyle:"short", timeZone:data.config.timezone?.name})}` - tweet.text = imports.htmlescape( //eslint-disable-line function-paren-newline + tweet.text = imports.htmlescape( //Escape tags imports.htmlescape(tweet.text, {"<":true, ">":true}) //Mentions .replace(new RegExp(`@(${tweet.mentions.join("|")})`, "gi"), '@$1') //Hashtags (this regex comes from the twitter source code) - .replace(/(?#$1 ') //eslint-disable-line no-misleading-character-class, prefer-named-capture-group + .replace(/(?#$1 ') //Line breaks .replace(/\n/g, "
") //Links