npm package: @springernature/prettier-config
Description: Springernature shareable config for Prettier
Author: Springer Nature
Latest version: 0.1.1

# Springer Nature Prettier Configuration

[![MIT licensed][badge-license]][info-license]
![NPM Version](https://img.shields.io/npm/v/%40springernature%2Fprettier-config)

[Shareable Prettier config](https://prettier.io/) used at Springer Nature for enforcing consistent code style across many file formats, including JavaScript, HTML, CSS, and Markdown.

Prettier is an opinionated code formatter, and much of it's formatting is not configurable.
This package provides configuration rules used by Springer Nature, for the options that can be set.

> [!IMPORTANT]  
> Prettier is intended to be used with the following versions of our other linters found in this repository:  
> `@springernature/stylelint-config@2.0.0` and above  
> `@springernature/eslint-config@7.0.0` and above

## Requirements

This package requires:

- [Node version 24 or greater](https://nodejs.org/en/download/releases)
- `prettier@^3.6.2`

## Installation

Our default export contains all of our **Prettier rules**.

`prettier` is defined in `peerDependencies`, which means that you will need to add these to your own project's `devDependencies`.

Install `prettier` and our config to your `devDependencies`

```
npm install -D prettier@3.6.2 @springernature/prettier-config
```

You then need to setup the configuration so it can be used in your project. This can be done in 3 different ways:

1. Add an entry into your package.json file.
`"prettier": "@springernature/prettier-config"`

2. Create a `prettier.config.js` file in the root of your project, and add **_either_** of the following lines to it:
```javascript
'@springernature/prettier-config'; 
```
or 

```javascript
export { default } from '@springernature/prettier-config';
```

Both of these tell Prettier that you just want to use the Springer Nature config, without specifying overrides.
The format you choose is up to you, whichever you feel makes the code clearer.

3. This final option allows you to override the Springer Nature config.
Create a `prettier.config.js` file in the root of your project, and add the following to it:

```javascript
import springerNatureConfig from '@springernature/prettier-config';

export default {
	...springerNatureConfig,
	singleQuote: false // example override
};
```

## Usage

There are several ways that Prettier can be used, however, it is recommended to run it from within your [code editor](https://prettier.io/docs/en/editors).

Visual code, for example, has a [prettier-vscode plugin](https://github.com/prettier/prettier-vscode).
This allows you to [format an individual file or selection](https://github.com/prettier/prettier-vscode?tab=readme-ov-file#using-command-palette-cmdctrl--shift--p) using the Command Palette, or [formatting a file on save](https://github.com/prettier/prettier-vscode?tab=readme-ov-file#format-on-save).

If you don't already use prettier, it is likely that you will want to run it against your whole project, and then use the editor to maintain it's usage as you make code changes.

To do this, you can run:

```shell
npx prettier . --write
```

This will format all matching files according to the Prettier configuration. This could result in a large number of stylistic changes to the code, mostly from changing quote style, adding spaces around braces, etc. If you want to start using Prettier more incrementally, you can instruct it to ignore code.

### Ignore code

Often you will want to ignore certain files or folders from being formatted. For example, compiled code or test coverage folders.
You can do this by creating a `.prettierignore` file in the root of your project.

```shell
# Ignore artifacts:
*.html
*.css
*.scss
*.md
coverage
target
```

## Contributing

This package is used by many active Springer Nature projects. We always welcome issues and pull requests, but we may not always be able to merge your suggestions.

If we decide that we can't merge your PR or act on your issue, it's nothing personal! We love to see new contributors, and we strive to provide a welcoming and inclusive environment.

## License

The prettier-config-springernature repository is licensed under the [MIT License][info-license].    
All packages within this repository are licensed under the [MIT License][info-license].    
Copyright &copy; 2025, Springer Nature

[info-license]: /LICENSE
[badge-license]: https://img.shields.io/badge/license-MIT-blue.svg