Skip to content

Commit 7f6f20a

Browse files
authored
run prettier on all code in CI (github#23482)
* run prettier on all code in CI * rename * test .tsx too * ignore more * prettier the stragglers * minimal permission
1 parent 0bd69f1 commit 7f6f20a

File tree

7 files changed

+108
-81
lines changed

7 files changed

+108
-81
lines changed

.github/workflows/js-lint.yml .github/workflows/code-lint.yml

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
name: Lint JS
1+
name: Lint code
22

3-
# **What it does**: Lints our JavaScript to ensure the code matches the specified code style.
4-
# **Why we have it**: We want some level of consistency to our JavaScript.
3+
# **What it does**: Lints our code to ensure the code matches the specified code style.
4+
# **Why we have it**: We want some level of consistency to our code.
55
# **Who does it impact**: Docs engineering, open-source engineering contributors.
66

7+
permissions:
8+
contents: read
9+
710
on:
811
workflow_dispatch:
912
push:
@@ -15,10 +18,13 @@ on:
1518
- '**.mjs'
1619
- '**.ts'
1720
- '**.tsx'
21+
- '**.yaml'
22+
- '**.yml'
23+
- '**.scss'
1824
# In case something like eslint or tsc or prettier upgrades
1925
- 'package-lock.json'
2026
# Ultimately, for debugging this workflow itself
21-
- .github/workflows/js-lint.yml
27+
- .github/workflows/code-lint.yml
2228

2329
jobs:
2430
lint:
@@ -39,5 +45,8 @@ jobs:
3945
- name: Run linter
4046
run: npm run lint
4147

48+
- name: Run Prettier
49+
run: npm run prettier-check
50+
4251
- name: Run TypeScript
4352
run: npm run tsc

.prettierignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
translations/
2-
includes/
2+
includes/
3+
data/release-notes/

components/guides/ArticleCards.tsx

+23-28
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import React, { useEffect, useState } from 'react'
22

3-
import {
4-
ArticleGuide,
5-
useProductGuidesContext,
6-
} from 'components/context/ProductGuidesContext'
3+
import { ArticleGuide, useProductGuidesContext } from 'components/context/ProductGuidesContext'
74
import { useTranslation } from 'components/hooks/useTranslation'
85
import { ArticleCard } from './ArticleCard'
96
import { DropdownMenu } from '@primer/components'
@@ -35,20 +32,16 @@ export const ArticleCards = () => {
3532
const guides = isUserFiltering ? filteredResults : includeGuides || []
3633

3734
const types = Object.entries(guideTypes).map(([key, val]) => {
38-
return (
39-
{text: val, key: key}
40-
)
35+
return { text: val, key: key }
4136
}) as ItemInput[]
42-
43-
types.unshift({text: t('filters.all'), key: undefined})
44-
37+
38+
types.unshift({ text: t('filters.all'), key: undefined })
39+
4540
const topics = allTopics?.map((topic) => {
46-
return (
47-
{text: topic, key: topic}
48-
)
41+
return { text: topic, key: topic }
4942
}) as ItemInput[]
5043

51-
topics.unshift({text: t('filters.all'), key: undefined})
44+
topics.unshift({ text: t('filters.all'), key: undefined })
5245

5346
return (
5447
<div>
@@ -58,26 +51,28 @@ export const ArticleCards = () => {
5851
<label htmlFor="type" className="text-uppercase f6 color-fg-muted d-block">
5952
{t('filters.type')}
6053
</label>
61-
<DropdownMenu
62-
aria-label="guide types"
63-
data-testid="types-dropdown"
64-
placeholder={t('filters.all')}
65-
items={types}
66-
selectedItem={typeFilter}
67-
onChange={setTypeFilter} />
54+
<DropdownMenu
55+
aria-label="guide types"
56+
data-testid="types-dropdown"
57+
placeholder={t('filters.all')}
58+
items={types}
59+
selectedItem={typeFilter}
60+
onChange={setTypeFilter}
61+
/>
6862
</div>
6963

7064
<div data-testid="card-filter-topics" className="mx-4">
7165
<label htmlFor="topic" className="text-uppercase f6 color-fg-muted d-block">
7266
{t('filters.topic')}
7367
</label>
74-
<DropdownMenu
75-
aria-label="guide topics"
76-
data-testid="topics-dropdown"
77-
placeholder={t('filters.all')}
78-
items={topics}
79-
selectedItem={topicFilter}
80-
onChange={setTopicFilter} />
68+
<DropdownMenu
69+
aria-label="guide topics"
70+
data-testid="topics-dropdown"
71+
placeholder={t('filters.all')}
72+
items={topics}
73+
selectedItem={topicFilter}
74+
onChange={setTopicFilter}
75+
/>
8176
</div>
8277
</form>
8378

components/landing/TableOfContents.tsx

+62-45
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,71 @@ export const TableOfContents = (props: Props) => {
2020
className={cx(variant === 'compact' ? 'list-style-outside pl-2' : 'list-style-none')}
2121
>
2222
<ActionList
23-
items=
24-
{(items || []).filter(item => typeof item !== 'undefined').map((item) => {
23+
items={(items || [])
24+
.filter((item) => typeof item !== 'undefined')
25+
.map((item) => {
2526
const { fullPath: href, title, intro, childTocItems } = item
2627
const isActive = router.pathname === href
27-
return (variant === 'compact') ? {
28-
key: href,
29-
text: title,
30-
renderItem: () => (
31-
<ActionList.Item>
32-
<li key={href} className="f4 d-list-item width-full">
33-
<Link className="d-block width-full" href={href}>{title}</Link>
34-
{(childTocItems || []).length > 0 && (
35-
<ul
36-
className={cx(
37-
variant === 'compact' ? 'list-style-circle pl-5 my-3' : 'list-style-none'
38-
)}
28+
return variant === 'compact'
29+
? {
30+
key: href,
31+
text: title,
32+
renderItem: () => (
33+
<ActionList.Item>
34+
<li key={href} className="f4 d-list-item width-full">
35+
<Link className="d-block width-full" href={href}>
36+
{title}
37+
</Link>
38+
{(childTocItems || []).length > 0 && (
39+
<ul
40+
className={cx(
41+
variant === 'compact'
42+
? 'list-style-circle pl-5 my-3'
43+
: 'list-style-none'
44+
)}
45+
>
46+
{(childTocItems || []).map((childItem) => {
47+
if (!childItem) {
48+
return null
49+
}
50+
return (
51+
<li key={childItem.fullPath} className="f4 d-block width-full">
52+
<Link className="d-block width-full" href={childItem.fullPath}>
53+
{childItem.title}
54+
</Link>
55+
</li>
56+
)
57+
})}
58+
</ul>
59+
)}
60+
</li>
61+
</ActionList.Item>
62+
),
63+
}
64+
: {
65+
key: href,
66+
title: title,
67+
renderItem: () => (
68+
<ActionList.Item className={cx('border-bottom')}>
69+
<li key={href} className={cx('mt-2', isActive && 'color-fg-muted')}>
70+
<BumpLink
71+
as={Link}
72+
href={href}
73+
title={<h2 className="py-1 h4">{title}</h2>}
3974
>
40-
{(childTocItems || []).map((childItem) => {
41-
if (!childItem) {
42-
return null
43-
}
44-
return (
45-
<li key={childItem.fullPath} className="f4 d-block width-full">
46-
<Link className="d-block width-full" href={childItem.fullPath}>{childItem.title}</Link>
47-
</li>
48-
)
49-
})}
50-
</ul>
51-
)}
52-
</li>
53-
</ActionList.Item>
54-
)
55-
} : {
56-
key: href,
57-
title: title,
58-
renderItem: () => (
59-
<ActionList.Item className={cx('border-bottom')}>
60-
<li key={href} className={cx('mt-2', isActive && 'color-fg-muted')}>
61-
<BumpLink as={Link} href={href} title={<h2 className="py-1 h4">{title}</h2>}>
62-
{intro && (
63-
<p className="f4 color-fg-muted" dangerouslySetInnerHTML={{ __html: intro }} />
64-
)}
65-
</BumpLink>
66-
</li>
67-
</ActionList.Item>
68-
)
69-
}
70-
})} />
75+
{intro && (
76+
<p
77+
className="f4 color-fg-muted"
78+
dangerouslySetInnerHTML={{ __html: intro }}
79+
/>
80+
)}
81+
</BumpLink>
82+
</li>
83+
</ActionList.Item>
84+
),
85+
}
86+
})}
87+
/>
7188
</ul>
7289
)
7390
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
"prebrowser-test": "npm run build",
211211
"prepare": "husky install",
212212
"prettier": "prettier -w \"**/*.{ts,tsx,js,mjs,scss,yml,yaml}\"",
213+
"prettier-check": "prettier -c \"**/*.{ts,tsx,js,mjs,scss,yml,yaml}\"",
213214
"prevent-pushes-to-main": "node script/prevent-pushes-to-main.js",
214215
"rest-dev": "script/rest/update-files.js && npm run dev",
215216
"start": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon server.mjs",

script/i18n/liquid-diff.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import languages from '../../lib/languages.js'
77
program
88
.argument('<files...>', 'The file name(s) without the language dir. \nI.E. content/foo.md')
99
.description('Shows the differences of liquid tags between two files')
10-
.requiredOption('-l, --language <language>', `Choose one of these languages to compare: ${Object.keys(languages).filter(l => l !== 'en')}`)
10+
.requiredOption(
11+
'-l, --language <language>',
12+
`Choose one of these languages to compare: ${Object.keys(languages).filter((l) => l !== 'en')}`
13+
)
1114
.parse(process.argv)
1215

1316
function reportFileDifference(diff) {

stylesheets/images.scss

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
padding: 0;
1313
box-shadow: var(--color-shadow-medium);
1414
}
15-
16-
img[src*="https://github.githubassets.com/images/icons/emoji"] {
15+
16+
img[src*="https://github.githubassets.com/images/icons/emoji"]
17+
{
1718
box-shadow: none;
1819
}
1920
}

0 commit comments

Comments
 (0)