From 54b49cbc3e2da8bdf8b0817081ef3787e5f1c74c Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Wed, 28 Apr 2021 23:07:21 +0200 Subject: [PATCH] Apply linter --- source/plugins/wakatime/index.mjs | 42 ++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/source/plugins/wakatime/index.mjs b/source/plugins/wakatime/index.mjs index bc83b38d..37098150 100644 --- a/source/plugins/wakatime/index.mjs +++ b/source/plugins/wakatime/index.mjs @@ -1,24 +1,25 @@ //Setup -export default async function ({ login, q, imports, data, account },{ enabled = false, token } = {}) { +export default async function ({ login, q, imports, data, account }, { enabled = false, token } = {}) { //Plugin execution try { //Check if plugin is enabled and requirements are met - if (!enabled || !q.wakatime) return null; + if (!enabled || !q.wakatime) + return null //Load inputs - let { sections, days, limit, url, user } = imports.metadata.plugins.wakatime.inputs({ data, account, q }); - if (!limit) limit = void limit; + let { sections, days, limit, url, user } = imports.metadata.plugins.wakatime.inputs({ data, account, q }) + if (!limit) limit = void limit const range = { - 7: "last_7_days", - 30: "last_30_days", - 180: "last_6_months", - 365: "last_year", - }[days] ?? "last_7_days"; + "7": "last_7_days", + "30": "last_30_days", + "180": "last_6_months", + "365": "last_year", + }[days] ?? "last_7_days" //Querying api and format result (https://wakatime.com/developers#stats) - console.debug(`metrics/compute/${login}/plugins > wakatime > querying api`); - const {data: { data: stats }} = await imports.axios.get(`${url}/api/v1/users/${user}/stats/${range}?api_key=${token}`); + console.debug(`metrics/compute/${login}/plugins > wakatime > querying api`) + const {data: { data: stats }} = await imports.axios.get(`${url}/api/v1/users/${user}/stats/${range}?api_key=${token}`) const result = { sections, days, @@ -30,18 +31,19 @@ export default async function ({ login, q, imports, data, account },{ enabled = languages:stats.languages.map(({name, percent, total_seconds:total}) => ({name, percent:percent/100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit), os:stats.operating_systems.map(({name, percent, total_seconds:total}) => ({name, percent:percent/100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit), editors:stats.editors.map(({name, percent, total_seconds:total}) => ({name, percent:percent/100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit), - }; + } //Result - return result; - } catch (error) { - //Handle errors - let message = "An error occured"; + return result + } + //Handle errors + catch (error) { + let message = "An error occured" if (error.isAxiosError) { - const status = error.response?.status; - message = `API returned ${status}`; - error = error.response?.data ?? null; + const status = error.response?.status + message = `API returned ${status}` + error = error.response?.data ?? null } - throw {error:{message, instance:error }}; + throw {error:{message, instance:error }} } }