From 7f6f20a73f960519836fb34678a55ec1dcae51ee Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Wed, 8 Dec 2021 11:11:52 -0500 Subject: [PATCH] run prettier on all code in CI (#23482) * run prettier on all code in CI * rename * test .tsx too * ignore more * prettier the stragglers * minimal permission --- .../workflows/{js-lint.yml => code-lint.yml} | 17 ++- .prettierignore | 3 +- components/guides/ArticleCards.tsx | 51 ++++----- components/landing/TableOfContents.tsx | 107 ++++++++++-------- package.json | 1 + script/i18n/liquid-diff.js | 5 +- stylesheets/images.scss | 5 +- 7 files changed, 108 insertions(+), 81 deletions(-) rename .github/workflows/{js-lint.yml => code-lint.yml} (70%) diff --git a/.github/workflows/js-lint.yml b/.github/workflows/code-lint.yml similarity index 70% rename from .github/workflows/js-lint.yml rename to .github/workflows/code-lint.yml index dee45b54dce5..4cc25120b492 100644 --- a/.github/workflows/js-lint.yml +++ b/.github/workflows/code-lint.yml @@ -1,9 +1,12 @@ -name: Lint JS +name: Lint code -# **What it does**: Lints our JavaScript to ensure the code matches the specified code style. -# **Why we have it**: We want some level of consistency to our JavaScript. +# **What it does**: Lints our code to ensure the code matches the specified code style. +# **Why we have it**: We want some level of consistency to our code. # **Who does it impact**: Docs engineering, open-source engineering contributors. +permissions: + contents: read + on: workflow_dispatch: push: @@ -15,10 +18,13 @@ on: - '**.mjs' - '**.ts' - '**.tsx' + - '**.yaml' + - '**.yml' + - '**.scss' # In case something like eslint or tsc or prettier upgrades - 'package-lock.json' # Ultimately, for debugging this workflow itself - - .github/workflows/js-lint.yml + - .github/workflows/code-lint.yml jobs: lint: @@ -39,5 +45,8 @@ jobs: - name: Run linter run: npm run lint + - name: Run Prettier + run: npm run prettier-check + - name: Run TypeScript run: npm run tsc diff --git a/.prettierignore b/.prettierignore index a6304997cfc1..4a66ca51fc5b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,3 @@ translations/ -includes/ \ No newline at end of file +includes/ +data/release-notes/ diff --git a/components/guides/ArticleCards.tsx b/components/guides/ArticleCards.tsx index 0d655f95f598..461b2a7610a8 100644 --- a/components/guides/ArticleCards.tsx +++ b/components/guides/ArticleCards.tsx @@ -1,9 +1,6 @@ import React, { useEffect, useState } from 'react' -import { - ArticleGuide, - useProductGuidesContext, -} from 'components/context/ProductGuidesContext' +import { ArticleGuide, useProductGuidesContext } from 'components/context/ProductGuidesContext' import { useTranslation } from 'components/hooks/useTranslation' import { ArticleCard } from './ArticleCard' import { DropdownMenu } from '@primer/components' @@ -35,20 +32,16 @@ export const ArticleCards = () => { const guides = isUserFiltering ? filteredResults : includeGuides || [] const types = Object.entries(guideTypes).map(([key, val]) => { - return ( - {text: val, key: key} - ) + return { text: val, key: key } }) as ItemInput[] - - types.unshift({text: t('filters.all'), key: undefined}) - + + types.unshift({ text: t('filters.all'), key: undefined }) + const topics = allTopics?.map((topic) => { - return ( - {text: topic, key: topic} - ) + return { text: topic, key: topic } }) as ItemInput[] - topics.unshift({text: t('filters.all'), key: undefined}) + topics.unshift({ text: t('filters.all'), key: undefined }) return (
@@ -58,26 +51,28 @@ export const ArticleCards = () => { - +
- +
diff --git a/components/landing/TableOfContents.tsx b/components/landing/TableOfContents.tsx index 292790e51f4f..38e2c7b9ebe3 100644 --- a/components/landing/TableOfContents.tsx +++ b/components/landing/TableOfContents.tsx @@ -20,54 +20,71 @@ export const TableOfContents = (props: Props) => { className={cx(variant === 'compact' ? 'list-style-outside pl-2' : 'list-style-none')} > typeof item !== 'undefined').map((item) => { + items={(items || []) + .filter((item) => typeof item !== 'undefined') + .map((item) => { const { fullPath: href, title, intro, childTocItems } = item const isActive = router.pathname === href - return (variant === 'compact') ? { - key: href, - text: title, - renderItem: () => ( - -
  • - {title} - {(childTocItems || []).length > 0 && ( -
      ( + +
    • + + {title} + + {(childTocItems || []).length > 0 && ( +
        + {(childTocItems || []).map((childItem) => { + if (!childItem) { + return null + } + return ( +
      • + + {childItem.title} + +
      • + ) + })} +
      + )} +
    • +
      + ), + } + : { + key: href, + title: title, + renderItem: () => ( + +
    • + {title}} > - {(childTocItems || []).map((childItem) => { - if (!childItem) { - return null - } - return ( -
    • - {childItem.title} -
    • - ) - })} -
    - )} -
  • -
    - ) - } : { - key: href, - title: title, - renderItem: () => ( - -
  • - {title}}> - {intro && ( -

    - )} - -

  • -
    - ) - } - })} /> + {intro && ( +

    + )} + + + + ), + } + })} + /> ) } diff --git a/package.json b/package.json index ef00629b2183..fcea7fbc6155 100644 --- a/package.json +++ b/package.json @@ -210,6 +210,7 @@ "prebrowser-test": "npm run build", "prepare": "husky install", "prettier": "prettier -w \"**/*.{ts,tsx,js,mjs,scss,yml,yaml}\"", + "prettier-check": "prettier -c \"**/*.{ts,tsx,js,mjs,scss,yml,yaml}\"", "prevent-pushes-to-main": "node script/prevent-pushes-to-main.js", "rest-dev": "script/rest/update-files.js && npm run dev", "start": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon server.mjs", diff --git a/script/i18n/liquid-diff.js b/script/i18n/liquid-diff.js index ef096aea6c4f..c2b7777bfc5c 100755 --- a/script/i18n/liquid-diff.js +++ b/script/i18n/liquid-diff.js @@ -7,7 +7,10 @@ import languages from '../../lib/languages.js' program .argument('', 'The file name(s) without the language dir. \nI.E. content/foo.md') .description('Shows the differences of liquid tags between two files') - .requiredOption('-l, --language ', `Choose one of these languages to compare: ${Object.keys(languages).filter(l => l !== 'en')}`) + .requiredOption( + '-l, --language ', + `Choose one of these languages to compare: ${Object.keys(languages).filter((l) => l !== 'en')}` + ) .parse(process.argv) function reportFileDifference(diff) { diff --git a/stylesheets/images.scss b/stylesheets/images.scss index 939810fa7474..59fb8261be64 100644 --- a/stylesheets/images.scss +++ b/stylesheets/images.scss @@ -12,8 +12,9 @@ padding: 0; box-shadow: var(--color-shadow-medium); } - - img[src*="https://github.githubassets.com/images/icons/emoji"] { + + img[src*="https://github.githubassets.com/images/icons/emoji"] + { box-shadow: none; } }