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

[core] Setup vale for enforcing style guides #39633

Merged
merged 7 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
13 changes: 13 additions & 0 deletions .github/styles/Blog/ComposedWords.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends: substitution
message: To be consistent with the rest of the documentation, consider using '%s' instead of '%s'.
level: warning
ignorecase: true
# swap maps tokens in form of bad: good
# for more information: https://vale.sh/docs/topics/styles/#substitution
swap:
sub-component: subcomponent
sub-components: subcomponents
'sub component': subcomponent
'sub components': subcomponents
'use-case': 'use case'
'use-case': 'use case'
17 changes: 17 additions & 0 deletions .github/styles/Blog/NamingConventions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends: substitution
message: To be consistent with capitalization, consider using '%s' instead of '%s'.
level: warning
ignorecase: false
# swap maps tokens in form of bad: good
# for more information: https://vale.sh/docs/topics/styles/#substitution
swap:
api: API
Api: API
typescript: TypeScript
Typescript: TypeScript
ts: TypeScript
TS: TypeScript
javascript: JavaScript
Javascript: JavaScript
css: CSS
Css: CSS
11 changes: 11 additions & 0 deletions .github/styles/Blog/Typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends: substitution
message: Do you mean '%s' instead of '%s'?
level: warning
ignorecase: true
# swap maps tokens in form of bad: good
# for more information: https://vale.sh/docs/topics/styles/#substitution
swap:
bellow: below
eg: e.g.
eg.: e.g.
'e.g ': 'e.g. '
Copy link
Contributor

Choose a reason for hiding this comment

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

this reminds me: can we add a rule to avoid Latinisms altogether? (etc., e.g., i.e.) - they're often confusing to non-native English speakers, and the latter two in particular are frequently misused. "etc." can always be cut or replaced with "and more", and "e.g" and "i.e." can be replaced with "for example."

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, Google has a Latin packge to detect eg and ie: https://github.com/errata-ai/Google/tree/master/Google

alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
Empty file added .github/styles/Vocab/accept.txt
Empty file.
Empty file added .github/styles/Vocab/reject.txt
Empty file.
23 changes: 23 additions & 0 deletions .github/workflows/vale-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Vale action

on: [pull_request]

permissions: {}

jobs:
vale:
name: runner / vale
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: errata-ai/vale-action@c4213d4de3d5f718b8497bd86161531c78992084 # v2.0.1
with:
reporter: github-pr-review
files: docs/data
env:
# Required, set by GitHub actions automatically:
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ node_modules
package-lock.json
size-snapshot.json
docs/public/static/blog/feed/*
# vale downloaded config
.github/styles/Google
.github/styles/write-good
31 changes: 31 additions & 0 deletions .vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Config vale. More information at https://docs.errata.ai/vale/config
StylesPath = .github/styles
MinAlertLevel = suggestion

Packages = Google

[*.md]
# Ignore code injection which start with {{...
BlockIgnores = {{.*

# Custom syle
# BasedOnStyles = Blog

Blog.ComposedWords = YES
Blog.NamingConventions = YES
Blog.Typos = YES

# Google:
Google.FirstPerson = YES # Avoid first-person pronouns such as I, me, ...'.
Google.GenderBias = YES # Avoid gendered profession
Google.OxfordComma = YES
Google.Quotes = YES # Commas and periods go inside quotation marks.
Google.Spelling = YES #In general, use American spelling (word ending with 'nised' or 'logue')
Google.We = YES # Try to avoid using first-person plural
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved

# Those rules are not repected a lot
# Google.Passive = YES # In general, use active voice instead of passive voice.
# Google.Will = YES # Avoid using will
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved

# False positives with "1st" nearly no use in our doc
# Google.Units = YES # Put a nonbreaking space between the number and the unit
2 changes: 1 addition & 1 deletion docs/data/base/components/focus-trap/focus-trap.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The following demo uses the [Portal](/base-ui/react-portal/) component to render

### Using a toggle inside the trap

The most common use case for the Focus Trap component is to maintain focus within a [Modal](/base-ui/react-modal/) component that is entirely separate from the element that opens the modal.
The most common use-case for the Focus Trap component is to maintain focus within a [Modal](/base-ui/react-modal/) component that is entirely separate from the element that opens the modal.
But you can also create a toggle button for the `open` prop of the Focus Trap component that is stored inside of the component itself, as shown in the following demo:

{{"demo": "ContainedToggleTrappedFocus.js"}}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ All credits go to the Tailwind Labs team for designing this component, found on

## Setting up the project

We'll use [`create-react-app` with typescript](https://create-react-app.dev/docs/adding-typescript/#installation) for this guide.
We'll use [`create-react-app` with TypeScript](https://create-react-app.dev/docs/adding-typescript/#installation) for this guide.
After you have created the project, follow the instructions given on the [Tailwind CSS installation page](https://tailwindcss.com/docs/guides/create-react-app) in order to configure `tailwind`.
Next, install `@mui/base` in the project:

Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/selects/selects.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ It's meant to be an improved version of the "react-select" and "downshift" packa
## Props

The Select component is implemented as a custom `<input>` element of the [InputBase](/material-ui/api/input-base/).
It extends the [text field components](/material-ui/react-text-field/) sub-components, either the [OutlinedInput](/material-ui/api/outlined-input/), [Input](/material-ui/api/input/), or [FilledInput](/material-ui/api/filled-input/), depending on the variant selected.
It extends the [text field components](/material-ui/react-text-field/) subcomponents, either the [OutlinedInput](/material-ui/api/outlined-input/), [Input](/material-ui/api/input/), or [FilledInput](/material-ui/api/filled-input/), depending on the variant selected.
It shares the same styles and many of the same props. Refer to the respective component's API page for details.

### Filled and standard variants
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/guides/api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Nested components inside a component have:

- their own flattened props when these are key to the top level component abstraction,
for instance an `id` prop for the `Input` component.
- their own `xxxProps` prop when users might need to tweak the internal render method's sub-components,
- their own `xxxProps` prop when users might need to tweak the internal render method's subcomponents,
for instance, exposing the `inputProps` and `InputProps` props on components that use `Input` internally.
- their own `xxxComponent` prop for performing component injection.
- their own `xxxRef` prop when you might need to perform imperative actions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ If, however, you would like to use styled-components, you can configure your app
<!-- #default-branch-switch -->

- [Create React App with styled-components](https://github.com/mui/material-ui/tree/master/examples/material-ui-cra-styled-components)
- [Create React App with styled-components and typescript](https://github.com/mui/material-ui/tree/master/examples/material-ui-cra-styled-components-ts)
- [Create React App with styled-components and TypeScript](https://github.com/mui/material-ui/tree/master/examples/material-ui-cra-styled-components-ts)

Following this approach reduces the bundle size, and removes the need to configure the CSS injection order.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const myCustomDefaultTheme = extendTheme();
export default myCustomDefaultTheme;
```

Here, the returned `theme` object needs to follow a certain structure to be used correctly by the final `CssVarsProvider`. It should have a `colorSchemes` key with the light and dark (and any other) palette. `prepareCssVars` import from `@mui/system` is used to create css variable names which can then be easily accessed using the returned `vars`. This is also added to the `theme` object. Finally, `myCustomDefaultTheme` theme object is created that can now be passed to the `createCssVarsProvider` to get a `CssVarsProvider`.
Here, the returned `theme` object needs to follow a certain structure to be used correctly by the final `CssVarsProvider`. It should have a `colorSchemes` key with the light and dark (and any other) palette. `prepareCssVars` import from `@mui/system` is used to create CSS variable names which can then be easily accessed using the returned `vars`. This is also added to the `theme` object. Finally, `myCustomDefaultTheme` theme object is created that can now be passed to the `createCssVarsProvider` to get a `CssVarsProvider`.

```js
// CssVarsProvider.js
Expand All @@ -133,7 +133,7 @@ export { CssVarsProvider, useColorScheme };

Now wrap your top level app component with this `CssVarsProvider` component and then you can access the passed theme value to any of the components rendered inside the provider.

Example of a component using the css variable -
Example of a component using the CSS variable -

```js
// Button.js
Expand Down