1.0.0 • Published 1 year ago
@itaober/prettier-config v1.0.0
@itaober/prettier-config
English | 简体中文
Introduction
@itaober/prettier-config provides a shared Prettier preset with optimized rules and plugin support for consistent code formatting.
Features
This package includes thoughtfully chosen presets and several built-in plugins:
prettier-plugin-jsdoc: Formats JSDoc commentsprettier-plugin-packagejson: Formatspackage.jsonfilesprettier-plugin-tailwindcss: Formats Tailwind CSS classes (auto-enabled iftailwindcssin dependencies)
For the full configuration details, see the source code.
Installation
pnpm add prettier @itaober/prettier-config -DUsage
Configuration
If you fully agree with the @itaober/prettier-config, you can add it directly to your package.json:
{
"prettier": "@itaober/prettier-config"
}Or, if you prefer using a JS config file, create a .prettierrc.js and include the following code:
import config from '@itaober/prettier-config';
export default config;Of course, if you want to customize the configuration, create a .prettierrc.js and use the following code:
import config from '@itaober/prettier-config';
/** @type {import('prettier').Config} */
export default {
...config,
plugins: [
...config.plugins,
// Your custom plugins
],
// Your custom configurations
};Add package.json Script
{
"scripts": {
"format": "prettier --write ."
}
}IDE Support
VSCode
- Install the Prettier extension
- Add the following settings to your
.vscode/settings.json:
{
"prettier.enable": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}Extra Configuration (Optional)
Pre-commit Formatting
To ensure your code is consistently formatted before each commit, you can use simple-git-hooks and lint-staged:
- Install the required packages:
pnpm add simple-git-hooks lint-staged -D- Add the following config to your
package.json:
{
"scripts": {
"prepare": "simple-git-hooks"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "pnpm format"
}
}- Activate
simple-git-hooks:
npx simple-git-hooks