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

Format Sass stylesheets using Prettier #3799

Merged
merged 10 commits into from
Aug 7, 2023
2 changes: 1 addition & 1 deletion .lintstagedrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
'*.{cjs,js,mjs}': commands.eslint,
'*.{json,yaml,yml}': commands.prettier,
'*.md': [commands.eslint, commands.stylelint, commands.prettier],
'*.scss': commands.stylelint
'*.scss': [commands.stylelint, commands.prettier]
}

// Configure paths to ignore
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
{
files: '*.scss',
options: {
printWidth: 120,
singleQuote: false
}
}
Expand Down
18 changes: 15 additions & 3 deletions docs/contributing/coding-standards/css.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ This makes it easier to keep track of different contexts.

To ensure code quality and consistency in our Sass files we check that certain rules are followed. These rules are based on [GDS Stylelint Config](https://github.com/alphagov/stylelint-config-gds/blob/main/scss.js), but we also add our own custom rules with a project [config file](/stylelint.config.js).

For consistent formatting we run [Prettier](https://prettier.io).

See [testing and linting](/docs/releasing/testing-and-linting.md) for more information.

## Running the lint task
Expand All @@ -125,6 +127,16 @@ To automatically fix Stylelint issues, add the `--fix` flag:
npm run lint:scss -- --fix
```

## Running the formatting task

You can run the formatter with `npm run lint:prettier`, or use formatting in [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and [other editors that support Prettier](https://prettier.io/docs/en/editors.html)

To automatically fix Prettier issues in all supported files, add the `--write` flag:

```shell
npm run lint:prettier -- --write
```

## Linting rules

We use the following rules when linting files:
Expand Down Expand Up @@ -493,21 +505,21 @@ Good:
$my-example-var: value;
```

### Don't write leading or trailing zeroes for numeric values with a decimal point
### Write leading or trailing zeroes for numeric values with a decimal point

Bad:

```scss
.selector {
font-size: 0.50em;
font-size: .50em;
}
```

Good:

```scss
.selector {
font-size: .5em;
font-size: 0.5em;
}
```

Expand Down
Loading