@springernature/prettier-config
v0.1.0
Published
Springernature shareable config for Prettier
Readme
Springer Nature Prettier Configuration
Shareable Prettier config 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/[email protected]and above@springernature/[email protected]and above
Requirements
This package requires:
- Node version 22 or greater
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 [email protected] @springernature/prettier-configYou then need to setup the configuration so it can be used in your project. This can be done in 3 different ways:
Add an entry into your package.json file.
"prettier": "@springernature/prettier-config"Create a
prettier.config.jsfile in the root of your project, and add either of the following lines to it:
'@springernature/prettier-config'; or
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.
- This final option allows you to override the Springer Nature config.
Create a
prettier.config.jsfile in the root of your project, and add the following to it:
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.
Visual code, for example, has a prettier-vscode plugin. This allows you to format an individual file or selection using the Command Palette, or formatting a file 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:
npx prettier . --writeThis 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.
# Ignore artifacts:
*.html
*.css
*.scss
*.md
coverage
targetContributing
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.
All packages within this repository are licensed under the MIT License.
Copyright © 2025, Springer Nature
