A shareable Prettier configuration.
This package provides a consistent Prettier configuration that can be easily shared across multiple projects.
Important
Prettier version 3.5.0 or higher is required as a peer dependency. Please ensure it is installed in your project's devDependencies.
npm install --save-dev --save-exact @winnerpc/prettier-config prettieryarn add --dev --exact @winnerpc/prettier-config prettierpnpm add --save-dev --save-exact @winnerpc/prettier-config prettierTo use the shared configuration, add the following to your .prettierrc file in your project's root directory:
"@winnerpc/prettier-config"This will apply the default configuration defined in this package to your project.
Here's a simple example of how your project structure might look:
my-project/
├── node_modules/
├── src/
│ └── index.js
├── .prettierrc # Paste "@winnerpc/prettier-config" here 👈
└── package.json
The default configuration provided by @winnerpc/prettier-config is as follows:
{
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"semi": false,
"singleQuote": false,
"quoteProps": "consistent",
"jsxSingleQuote": false,
"trailingComma": "all",
"bracketSpacing": true,
"objectWrap": "preserve",
"bracketSameLine": false,
"arrowParens": "avoid",
"endOfLine": "lf",
"embeddedLanguageFormatting": "off",
"singleAttributePerLine": false
}These settings promote a clean and consistent code style across your codebase.
If you want to customize or override the default settings, you can create a prettier.config.js, .prettierrc.js, prettier.config.mjs, or .prettierrc.mjs file in your project's root directory.
Example of extending the config:
// prettier.config.js, .prettierrc.js, prettier.config.mjs, or .prettierrc.mjs
import winnerpcPrettierConfig from "@winnerpc/prettier-config"
/**
* @see https://prettier.io/docs/configuration
* @type {import("prettier").Config}
*/
const config = {
...winnerpcPrettierConfig,
semi: true, // Override the 'semi' rule
// Customize other Prettier options as needed
}
export default configIn this example, we import the shared configuration and then override the semi option to true. You can add or override any other Prettier options as needed.
Add these scripts to your package.json for easier usage:
{
"scripts": {
"format": "prettier --write ."
}
}Format the entire project using Prettier:
npm run format
# Or Yarn
yarn format
# Or pnpm
pnpm formatEach command above can be run in the terminal from the root of your project. These scripts help automate repetitive tasks and ensure consistency across your codebase.
Contributions are welcome! If you have ideas, improvements, or run into any issues, feel free to open an issue.
MIT © Winner-pc