Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce markdown linting #2726

Merged
merged 23 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
05cf1c7
Introduce markdown lint
khiga8 Dec 22, 2022
9a0e810
Add extension to devcontainer.json
khiga8 Dec 28, 2022
399abc1
Organize rule configuration
khiga8 Dec 28, 2022
344c104
try introducing CI step
khiga8 Dec 28, 2022
74eb624
Configure formatter
khiga8 Dec 29, 2022
3b6eb97
Just add similar to eslint
khiga8 Dec 29, 2022
18cc5c0
update config
khiga8 Dec 29, 2022
353150c
Fix: MD001/heading-increment/header-increment Heading levels should o…
khiga8 Jan 10, 2023
d2591ff
fix: MD030/list-marker-space Spaces after list markers
khiga8 Jan 10, 2023
e92701d
fix: MD040/fenced-code-language Fenced code blocks should have a lang…
khiga8 Jan 10, 2023
6675d93
Fix: MD051/link-fragments Link fragments should be valid
khiga8 Jan 10, 2023
a7a29e3
Create rules to enforce eventualy
khiga8 Jan 10, 2023
88b2216
Fix: no-emphasis-as-heading/no-emphasis-as-header Emphasis used inste…
khiga8 Jan 10, 2023
ad55a36
fix: MD031/blanks-around-fences Fenced code blocks should be surroun…
khiga8 Jan 10, 2023
f992a52
Disable stylistic rule
khiga8 Jan 10, 2023
c17e0e0
Add TODO
khiga8 Jan 10, 2023
f39fa4d
Add note in config
khiga8 Jan 10, 2023
433324f
fix: GH002/no-generic-link-text Avoid using generic link text like or :
khiga8 Jan 10, 2023
d741723
update config
khiga8 Jan 10, 2023
ef7242f
Add exceptions for Link for generic text
khiga8 Jan 10, 2023
d1f87d2
Update to @joshblack suggestion
khiga8 Jan 11, 2023
572c744
Update CONTRIBUTING.md
khiga8 Jan 11, 2023
5f27844
Merge branch 'main' into kh-add-markdown-lint
joshblack Jan 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "Primer Components",
"image": "mcr.microsoft.com/vscode/devcontainers/typescript-node:16",
"extensions": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"],
"extensions": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint", "DavidAnson.vscode-markdownlint"],
"forwardPorts": [8000],
"postCreateCommand": ["/bin/bash", "-c", "pushd docs && npm install && popd && npm install"],
"remoteUser": "node",
"features": {
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
"version": "latest"
}
}
}
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:
cancel-in-progress: true

jobs:
lint:
eslint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -26,7 +26,22 @@ jobs:

- name: Lint
run: npm run lint
markdown:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run markdownlint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add this to the lint job as a step after npm run lint? Would be great to keep it in the same job for linting, something like:

      - name: Lint JavaScript
        run: npm run lint
      - name: Lint markdown
        run: npm run markdownlint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can do that! I got feedback in the primer/design repo that it's more clear when there are separate linting jobs for error clarity, but we can keep it together if you prefer. I don't have a strong opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

test:
strategy:
fail-fast: false
Expand Down
35 changes: 35 additions & 0 deletions .markdownlint-cli2.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const githubMarkdownOpinions = require('@github/markdownlint-github')

// Rules we want to turn on but currently have too many violations
const rulesToEnforce = {
'fenced-code-language': false,
'no-duplicate-header': false, // Fix https://github.com/primer/doctocat/issues/527, then set this rule to `siblings_only: true`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@primer/react-reviewers FYI,no-duplicate-header should be turned on because doctocat messes up the anchor links when headings have the same text. See linked issue. I keep it off for now because there's too many address.

Ideally, the issue is fixed in doctocat so we don't have to set this rule to be strict.

}
// Rules we don't care to enforce (usually stylistic)
const rulesToNotEnforce = {
'line-length': false,
'blanks-around-headings': false,
'blanks-around-lists': false,
'no-trailing-spaces': false,
'no-multiple-blanks': false,
'no-trailing-punctuation': false,
'single-trailing-newline': false,
'ul-indent': false,
'no-hard-tabs': false,
'first-line-heading': false,
'no-space-in-emphasis': false,
'blanks-around-fences': false,
}
Comment on lines +9 to +22
Copy link
Contributor Author

@khiga8 khiga8 Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are stylistic rules that I don't think Primer team cares to enforce for now, but not sure. Feel free to configure this to your preference!!!


const defaultOverrides = {
'no-generic-link-text': {exceptions: ['link']}, // We don't want it to flag links that link to `Link` component.
}

const options = githubMarkdownOpinions.init({...rulesToNotEnforce, ...rulesToEnforce, ...defaultOverrides})
module.exports = {
config: options,
customRules: ['@github/markdownlint-github'],
outputFormatters: [
['markdownlint-cli2-formatter-pretty', {appendLink: true}], // ensures the error message includes a link to the rule documentation
],
}
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ yarn add @primer/react

## Roadmap

You can track our roadmap progress in the [Roadmap Project Board](https://github.com/primer/react/projects/3), see more detail in the [quarterly planning Discussions](https://github.com/primer/react/discussions?discussions_q=%5BRoadmap%5D), and find a list of all the current epic tracking issues [here](https://github.com/primer/react/discussions/997).
You can track our roadmap progress in the [Roadmap Project Board](https://github.com/primer/react/projects/3), see more detail in the [quarterly planning Discussions](https://github.com/primer/react/discussions?discussions_q=%5BRoadmap%5D), and find a [list of all the current epic tracking issues](https://github.com/primer/react/discussions/997).

## Contributing

Expand All @@ -51,7 +51,3 @@ We love collaborating with folks inside and outside of GitHub and welcome contri
## New Component Proposals

We welcome and encourage new component proposals from internal GitHub teams! Our best work comes from collaborating directly with the teams using Primer React Components in their projects. If you'd like to kick off a new component proposal, please submit an issue using the [component proposal issue template](https://github.com/primer/react/issues/new?template=new-component-proposal.md) and we will get in touch!

[styled-components]: https://www.styled-components.com/docs
[primer css]: https://github.com/primer/primer
[flash of unstyled content]: https://en.wikipedia.org/wiki/Flash_of_unstyled_content
8 changes: 1 addition & 7 deletions contributor-docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const Component = styled.div<SxProp>`

Component.defaultProps = {
m: 0,
fontSize: 5
fontSize: 5,
}

export default Component
Expand Down Expand Up @@ -212,10 +212,4 @@ Make sure to run `npm install` from inside the `docs/` subfolder _as well as_ th

Ensure you are using the latest minor of Node.js for the major version specified in the `.nvmrc` file. For example, if `.nvmrc` contains `8`, make sure you're using the latest version of Node.js with the major version of 8.

[classnames]: https://www.npmjs.com/package/classnames
[spread syntax]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
[styled-system]: https://styled-system.com
[table]: https://jxnblk.com/styled-system/table
[npx]: https://www.npmjs.com/package/npx
[now]: https://zeit.co/now
[primer.style]: https://primer.style
21 changes: 8 additions & 13 deletions contributor-docs/adrs/adr-004-children-as-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ _Note: Consumer is used multiple times on this page. It refers to the developers

## Decision:


1. Prefer using children for “content”

2. For composite components, the API should be decided by how much customisation is available for children.

For components that have design decisions baked in, should use strict props. For example, the color of the icon inside a Button component is decided by the `variant` prop on the Button. The API does not allow for changing that.

```jsx
<Button variant="danger" leadingIcon={TrashIcon}>Delete branch</Button>
<Button variant="danger" leadingIcon={TrashIcon}>
Delete branch
</Button>
```

On the other hand, if we want consumers to have more control over children, a composite API is the better choice.
Expand All @@ -38,7 +39,7 @@ On the other hand, if we want consumers to have more control over children, a co

With React, `children` is the out-of-the-box way for putting [phrasing content](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#phrasing_content) inside your component. By using `children` instead of our own custom prop, we can make the API “predictable” for its consumers.

<img width="373" alt="image" src="https://user-images.githubusercontent.com/1863771/144945223-70c4c800-5827-4985-9f18-0ab416eba058.png">
<img width="373" alt="image" src="https://user-images.githubusercontent.com/1863771/144945223-70c4c800-5827-4985-9f18-0ab416eba058.png"> <!-- markdownlint-disable-line no-default-alt-text -->
Copy link
Contributor Author

@khiga8 khiga8 Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@primer/react-reviewers This is a TODO! Feel free to suggest something in this PR to fix this!


```jsx
// prefer this
Expand All @@ -62,7 +63,7 @@ import {CheckIcon} from '@primer/octicons-react'
render(
<Flash variant="success">
<CheckIcon /> Changes saved!
</Flash>
</Flash>,
)
```

Expand Down Expand Up @@ -149,8 +150,6 @@ When intentionally going off the happy path, developers can still drop down an a

_Sidenote: We might want to name this prop `leadingIcon`, even if there is no `trailingIcon`. Consistent names across components plays a big role in making the API predictable._



---

<br/>
Expand Down Expand Up @@ -233,7 +232,7 @@ We use this pattern as well in `Button`, `Button.Counter` is a restricted versio

<img width="184" alt="image 8" src="https://user-images.githubusercontent.com/1863771/144945218-5154b8a1-8854-4335-926c-08a4ffac6d9d.png">

```jsx
````jsx
<Button>
Watch <Button.Counter>1</Button.Counter>
</Button>
Expand All @@ -259,7 +258,7 @@ For Example, [legacy ActionMenu](https://primer.style/react/deprecated/ActionMen
```jsx
<ActionMenu overlayProps={{width: 'medium'}} anchorContent="Open column menu">
</ActionMenu>
```
````

<br/>

Expand Down Expand Up @@ -371,15 +370,13 @@ Prefer using children for “content”
<Button label="Watch" variant="primary"/>
```


<img width="227" alt="image 13" src="https://user-images.githubusercontent.com/1863771/145045542-0d80491b-75e1-4304-b9fe-8c2cca80b298.png">


The Icon should adapt to variant and size of the `Button`. We could use a `EyeIcon` in children here:

```jsx
<Button>
<EyeIcon/> Watch
<EyeIcon /> Watch
</Button>
```

Expand All @@ -393,10 +390,8 @@ But, we want to discourage customising the Icon’s color and size in the applic
<Button leadingIcon={<EyeIcon/>}>Watch</Button>
```


<img width="293" alt="image 14" src="https://user-images.githubusercontent.com/1863771/145045544-1a1651f1-fbcf-4022-8e9b-b37558bb2466.png">


We want to add a `Counter` that adapts to the variant without supporting all the props of a `CounterLabel` like `scheme`.

`Button.Counter` is a restricted version of `CounterLabel`, making the right thing easy and wrong thing hard:
Expand Down
76 changes: 38 additions & 38 deletions contributor-docs/adrs/adr-005-box-sx.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@ In Primer React and consuming applications, we use many different patterns for c

1. Creating components with styled-components

```tsx
const Avatar = styled.img.attrs<StyledAvatarProps>(props => ({
height: props.size,
width: props.size
}))<StyledAvatarProps>`
display: inline-block;
overflow: hidden;
line-height: ${get('lineHeights.condensedUltra')};
border-radius: ${props => getBorderRadius(props)};
${sx}
`
```

[Show full code example →](https://github.com/primer/react/pull/2019/files?diff=split&w=0)

2. Creating components with Box

```tsx
const Avatar: React.FC<AvatarProps> = ({size = 20, alt = '', square = false, sx = {}, ...props}) => {
const styles:BetterSystemStyleObject = {
display: 'inline-block',
overflow: 'hidden',
lineHeight: 'condensedUltra',
borderRadius: getBorderRadius({size, square})
}

return (
<Box
as="img"
alt={alt}
sx={merge<BetterSystemStyleObject>(styles, sx)} // styles needs to merge with props.sx
{...props}
/>
)
}
```

[Show full code example →](https://github.com/primer/react/pull/2019/files?diff=split&w=0)
```tsx
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errr I think prettier ran for these files and updated it, but not sure. @primer/react-reviewers is this expected?

const Avatar = styled.img.attrs<StyledAvatarProps>(props => ({
height: props.size,
width: props.size,
}))<StyledAvatarProps>`
display: inline-block;
overflow: hidden;
line-height: ${get('lineHeights.condensedUltra')};
border-radius: ${props => getBorderRadius(props)};
${sx}
`
```

[Show full code example →](https://github.com/primer/react/pull/2019/files?diff=split&w=0)

2. Creating components with Box

```tsx
const Avatar: React.FC<AvatarProps> = ({size = 20, alt = '', square = false, sx = {}, ...props}) => {
const styles: BetterSystemStyleObject = {
display: 'inline-block',
overflow: 'hidden',
lineHeight: 'condensedUltra',
borderRadius: getBorderRadius({size, square}),
}

return (
<Box
as="img"
alt={alt}
sx={merge<BetterSystemStyleObject>(styles, sx)} // styles needs to merge with props.sx
{...props}
/>
)
}
```

[Show full code example →](https://github.com/primer/react/pull/2019/files?diff=split&w=0)

&nbsp;

Expand Down
11 changes: 4 additions & 7 deletions contributor-docs/adrs/adr-008-experimental-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Proposed

## Context

#### Recap: Drafts
### Recap: Drafts

As we work on new components (or rewrites of old components), we often need to start with a "prototype"[^1] and not include them in the semantically versioned (semver-ed) main bundle.

Expand Down Expand Up @@ -39,8 +39,6 @@ The approach that has served us well since Dec 2021 has been "drafts" (along wit

We want to enable feature teams to contribute to Primer. We also want to make it clear which contributions haven't been evaluated by our high standards for Primer components.



&nbsp;

## Decision
Expand All @@ -53,17 +51,16 @@ The approach that has served us well since Dec 2021 has been "drafts" (along wit

This will help in sharing experimental components between the monolith and projects outside of monolith. The ownership and responsibility of maintenance will be shared by multiple teams (including primer).

#### Risks:
### Risks:

This will require improvements in the development and publishing workflow for experimental components. Without making that investment, we could create more friction and make contributions more difficult.


&nbsp;

#### Other options considered

1. The code for experimental components should live in a new repository code `github.com/primer/react-candidates` to support different conventions and processes for experimental components and convey shared ownership between primer and product teams.
1. The code for experimental components should live in a new repository code `github.com/primer/react-candidates` to support different conventions and processes for experimental components and convey shared ownership between primer and product teams.

Keeping experimental components in primer _org_ suggests that the primer _team_ would take up maintenance of these components while they are still candidates (bugs, a11y remedial, etc.). This will be a new parallel workstream for the team and with our current team size, we might not be able to give it the required attention.

2. The code for experimental components should live inside the monolith in [github/github/modules/react-shared](https://github.com/github/github/tree/master/app/assets/modules/react-shared) instead of a new repository.
Expand Down
Loading