From 4c2307ab4b30c02123e072f91b1675b876299a72 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 6 Sep 2022 03:09:45 -0400 Subject: [PATCH] Add prettier check to CI (#1999) * Add prettier check to CI * Run prettier:format --- .github/workflows/test.yml | 4 ++++ package.json | 4 +++- scripts/generate-langs-json.js | 40 ++++++++++++++++++-------------- src/calculateRank.js | 4 ++-- src/cards/repo-card.js | 12 +++++----- src/fetchers/wakatime-fetcher.js | 2 +- tests/fetchTopLanguages.test.js | 5 +++- tests/fetchWakatime.test.js | 2 +- tests/renderWakatimeCard.test.js | 17 +++++++++----- themes/index.js | 4 ++-- 10 files changed, 56 insertions(+), 38 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 89df34e6..d26607d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,5 +25,9 @@ jobs: npm install npm run test + - name: Run Prettier + run: | + npm run prettier:check:ci + - name: Code Coverage uses: codecov/codecov-action@v1 diff --git a/package.json b/package.json index e2f13552..110a4e80 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,9 @@ "test:watch": "jest --watch", "theme-readme-gen": "node scripts/generate-theme-doc", "preview-theme": "node scripts/preview-theme", - "generate-langs-json": "node scripts/generate-langs-json" + "generate-langs-json": "node scripts/generate-langs-json", + "prettier:check:ci": "./node_modules/.bin/prettier --check .", + "prettier:format": "./node_modules/.bin/prettier --write ." }, "author": "Anurag Hazra", "license": "MIT", diff --git a/scripts/generate-langs-json.js b/scripts/generate-langs-json.js index 0705080d..bd210a3c 100644 --- a/scripts/generate-langs-json.js +++ b/scripts/generate-langs-json.js @@ -1,26 +1,30 @@ -const fs = require('fs'); -const jsYaml = require('js-yaml'); -const axios = require('axios'); +const fs = require("fs"); +const jsYaml = require("js-yaml"); +const axios = require("axios"); -const LANGS_FILEPATH = "./src/common/languageColors.json" +const LANGS_FILEPATH = "./src/common/languageColors.json"; //Retrieve languages from github linguist repository yaml file //@ts-ignore -axios.get("https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml") -.then((response) => { +axios + .get( + "https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml", + ) + .then((response) => { + //and convert them to a JS Object + const languages = jsYaml.load(response.data); - //and convert them to a JS Object - const languages = jsYaml.load(response.data); + const languageColors = {}; - const languageColors = {}; + //Filter only language colors from the whole file + Object.keys(languages).forEach((lang) => { + languageColors[lang] = languages[lang].color; + }); - //Filter only language colors from the whole file - Object.keys(languages).forEach((lang) => { - languageColors[lang] = languages[lang].color; + //Debug Print + //console.dir(languageColors); + fs.writeFileSync( + LANGS_FILEPATH, + JSON.stringify(languageColors, null, " "), + ); }); - - //Debug Print - //console.dir(languageColors); - fs.writeFileSync(LANGS_FILEPATH, JSON.stringify(languageColors, null, ' ')); - -}); diff --git a/src/calculateRank.js b/src/calculateRank.js index 9a8a55d5..742b9ab1 100644 --- a/src/calculateRank.js +++ b/src/calculateRank.js @@ -67,9 +67,9 @@ function calculateRank({ if (normalizedScore < RANK_S_VALUE) return "S+"; if (normalizedScore < RANK_DOUBLE_A_VALUE) return "S"; if (normalizedScore < RANK_A2_VALUE) return "A++"; - if (normalizedScore < RANK_A3_VALUE) return "A+" + if (normalizedScore < RANK_A3_VALUE) return "A+"; return "B+"; - })() + })(); return { level, score: normalizedScore }; } diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index bb5c178a..034ee1f6 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -67,8 +67,8 @@ const iconWithLabel = (icon, label, testid) => { }; /** - * @param {import('../fetchers/types').RepositoryData} repo - * @param {Partial} options + * @param {import('../fetchers/types').RepositoryData} repo + * @param {Partial} options * @returns {string} */ const renderRepoCard = (repo, options = {}) => { @@ -167,11 +167,11 @@ const renderRepoCard = (repo, options = {}) => { return card.render(` ${ isTemplate - // @ts-ignore - ? getBadgeSVG(i18n.t("repocard.template"), colors.textColor) + ? // @ts-ignore + getBadgeSVG(i18n.t("repocard.template"), colors.textColor) : isArchived - // @ts-ignore - ? getBadgeSVG(i18n.t("repocard.archived"), colors.textColor) + ? // @ts-ignore + getBadgeSVG(i18n.t("repocard.archived"), colors.textColor) : "" } diff --git a/src/fetchers/wakatime-fetcher.js b/src/fetchers/wakatime-fetcher.js index e9779d60..fe06c638 100644 --- a/src/fetchers/wakatime-fetcher.js +++ b/src/fetchers/wakatime-fetcher.js @@ -7,7 +7,7 @@ const { MissingParamError } = require("../common/utils"); */ const fetchWakatimeStats = async ({ username, api_domain, range }) => { if (!username) throw new MissingParamError(["username"]); - + try { const { data } = await axios.get( `https://${ diff --git a/tests/fetchTopLanguages.test.js b/tests/fetchTopLanguages.test.js index 54238df1..0792f28d 100644 --- a/tests/fetchTopLanguages.test.js +++ b/tests/fetchTopLanguages.test.js @@ -81,7 +81,10 @@ describe("FetchTopLanguages", () => { it("should fetch correct language data while excluding the 'test-repo-1' repository", async () => { mock.onPost("https://api.github.com/graphql").reply(200, data_langs); - let repo = await fetchTopLanguages("anuraghazra", exclude_repo=["test-repo-1"]); + let repo = await fetchTopLanguages( + "anuraghazra", + (exclude_repo = ["test-repo-1"]), + ); expect(repo).toStrictEqual({ HTML: { color: "#0f0", diff --git a/tests/fetchWakatime.test.js b/tests/fetchWakatime.test.js index 6255890c..ef8c64c3 100644 --- a/tests/fetchWakatime.test.js +++ b/tests/fetchWakatime.test.js @@ -207,7 +207,7 @@ describe("Wakatime fetcher", () => { mock.onGet(/\/https:\/\/wakatime\.com\/api/).reply(404, wakaTimeData); await expect(fetchWakatimeStats("noone")).rejects.toThrow( - "Missing params \"username\" make sure you pass the parameters in URL", + 'Missing params "username" make sure you pass the parameters in URL', ); }); }); diff --git a/tests/renderWakatimeCard.test.js b/tests/renderWakatimeCard.test.js index 51d63e6c..a6d7c85f 100644 --- a/tests/renderWakatimeCard.test.js +++ b/tests/renderWakatimeCard.test.js @@ -48,10 +48,15 @@ describe("Test Render Wakatime Card", () => { }); it('should show "no coding activitiy this week" message when there hasn not been activity', () => { - document.body.innerHTML = renderWakatimeCard({ - ...wakaTimeData.data, - languages: undefined - }, {}); - expect(document.querySelector(".stat").textContent).toBe("No coding activity this week") - }) + document.body.innerHTML = renderWakatimeCard( + { + ...wakaTimeData.data, + languages: undefined, + }, + {}, + ); + expect(document.querySelector(".stat").textContent).toBe( + "No coding activity this week", + ); + }); }); diff --git a/themes/index.js b/themes/index.js index 2508c9d2..4312496a 100644 --- a/themes/index.js +++ b/themes/index.js @@ -355,12 +355,12 @@ const themes = { bg_color: "09131B", border_color: "0c1a25", }, - "rose_pine":{ + rose_pine: { title_color: "9ccfd8", icon_color: "ebbcba", text_color: "e0def4", bg_color: "191724", - } + }, }; module.exports = themes;