Skip to content

base

npm version License: MIT Node.js

> Base Prettier configuration package that provides shared formatting rules for consistent code style across projects.

  • 🎯 Consistent Formatting: Standardized code style across all projects
  • 🔧 Zero Configuration: Works out of the box with sensible defaults
  • 📦 Extensible: Foundation for framework-specific Prettier configs
  • 🚀 Modern Defaults: Optimized for modern JavaScript/TypeScript projects
Terminal window
pnpm add -D @jmlweb/prettier-config-base prettier

> 💡 Upgrading from a previous version? See the Migration Guide for breaking changes and upgrade instructions.

Add to your package.json:

{
"prettier": "@jmlweb/prettier-config-base"
}

> ⚠️ Note for ES Module projects: If your project has "type": "module" in package.json, use Option 2: .prettierrc.mjs instead to avoid configuration loading issues.

Section titled “Option 2: Using .prettierrc.mjs (Recommended for ES Modules)”

Create a .prettierrc.mjs file in your project root:

export { default } from '@jmlweb/prettier-config-base';

> ✅ Recommended for ES Module projects: Use this option if your project has "type": "module" in package.json to ensure Prettier loads the configuration correctly.

Create a .prettierrc.js file in your project root:

module.exports = require('@jmlweb/prettier-config-base');

Create a .prettierrc.json file:

"@jmlweb/prettier-config-base"

This package provides the following Prettier settings:

OptionValueDescription
semitrueUse semicolons at the end of statements
singleQuotetrueUse single quotes instead of double quotes
tabWidth2Use 2 spaces for indentation
trailingComma'all'Add trailing commas wherever possible
useTabsfalseUse spaces instead of tabs
endOfLine'lf'Use LF line endings (Unix-style)
proseWrap'preserve'Preserve prose wrapping in markdown files
const user = { name: 'John', age: 30, email: 'john@example.com' };
function greet(user) {
return 'Hello, ' + user.name + '!';
}
const user = {
name: 'John',
age: 30,
email: 'john@example.com',
};
function greet(user) {
return 'Hello, ' + user.name + '!';
}

> Philosophy: Stop arguing about code style. Let Prettier handle formatting so you can focus on writing code.

This package provides an opinionated Prettier configuration that prioritizes readability and modern JavaScript conventions. The goal is to eliminate formatting debates and establish consistent code style across all projects.

Semicolons (semi: true): Always use semicolons

  • Why: Prevents ASI (Automatic Semicolon Insertion) edge cases and ambiguity
  • Trade-off: Slightly more verbose, but eliminates an entire class of potential bugs
  • When to override: If your team strongly prefers semicolon-free style and understands ASI rules

Single Quotes (singleQuote: true): Use single quotes for strings

  • Why: Consistent with most modern JavaScript codebases and requires less escaping in JSX
  • Trade-off: None significant - purely stylistic choice for consistency
  • When to override: If working in a codebase that already uses double quotes

Trailing Commas (trailingComma: 'all'): Add trailing commas everywhere possible

  • Why: Cleaner git diffs (changes only affect modified lines) and easier to add items without modifying previous line
  • Trade-off: Slightly unusual for developers from other languages, but widely adopted in modern JS
  • When to override: If targeting older environments that don’t support trailing commas (rare with modern transpilation)

2 Spaces Indentation (tabWidth: 2): Use 2 spaces for indentation

  • Why: Balances readability with horizontal space, standard in JavaScript ecosystem
  • Trade-off: May feel cramped compared to 4 spaces, but prevents excessive nesting visibility
  • When to override: If your team or organization has standardized on 4 spaces

Use this package when you want:

  • ✅ Consistent code formatting across projects
  • ✅ Zero-configuration Prettier setup
  • ✅ Modern JavaScript/TypeScript formatting defaults
  • ✅ Foundation for extending with framework-specific configs

For Tailwind CSS projects, use @jmlweb/prettier-config-tailwind instead.

You can extend this config for project-specific needs:

// .prettierrc.mjs (for ES modules)
import baseConfig from '@jmlweb/prettier-config-base';
export default {
...baseConfig,
// Override or add specific options
printWidth: 100,
arrowParens: 'always',
};

Or using CommonJS:

.prettierrc.js
const baseConfig = require('@jmlweb/prettier-config-base');
module.exports = {
...baseConfig,
// Override or add specific options
printWidth: 100,
arrowParens: 'always',
};

Add formatting scripts to your package.json:

{
"scripts": {
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,md}\""
}
}

Then run:

Terminal window
pnpm format # Format all files
pnpm format:check # Check formatting without modifying files
  • Node.js >= 18.0.0
  • Prettier >= 3.0.0

This package requires the following peer dependency:

  • prettier (>= 3.0.0)

See real-world usage examples:

  • Prettier - Opinionated code formatter
  • ESLint - Pluggable linting utility (use with eslint-config-prettier to avoid conflicts)
  • Editor Plugins - Format on save in VS Code, IntelliJ, and more

> Note: This section documents known issues and their solutions. If you encounter a problem not listed here, please open an issue.

Symptoms:

  • Code gets formatted by Prettier then changed back by ESLint auto-fix
  • Linting errors about formatting (quotes, semicolons, etc.)

Cause:

  • ESLint has formatting rules that conflict with Prettier
  • Both tools trying to format the same code

Solution:

Install eslint-config-prettier to disable conflicting ESLint rules:

Terminal window
pnpm add -D eslint-config-prettier

Then add it to your ESLint config (must be last):

// eslint.config.js (flat config)
import prettier from 'eslint-config-prettier';
export default [
// ... other configs
prettier, // Must be last!
];

Or use @jmlweb/eslint-config-base which already includes this integration.

Symptoms:

  • Files don’t format automatically when saving
  • Manual format command works but auto-format doesn’t

Cause:

  • IDE Prettier extension not installed or configured
  • Wrong formatter selected as default

Solution:

For VS Code, install the Prettier extension and add to .vscode/settings.json:

{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}

Symptoms:

  • Prettier uses default settings instead of your config
  • Custom options not applied

Cause:

  • Configuration file not in the correct location
  • Multiple config files conflicting

Solution:

  1. Ensure config is in project root (not nested directories)
  2. Use only one configuration method (package.json OR .prettierrc)
  3. Check for conflicting configs in parent directories
  4. Restart your IDE/editor

To verify Prettier finds your config:

Terminal window
pnpm exec prettier --find-config-path src/index.ts

Warning: “Ignored unknown option” with ES Modules

Section titled “Warning: “Ignored unknown option” with ES Modules”

Symptoms:

  • Warning: Ignored unknown option { default: { ... } }
  • Configuration not applied (Prettier uses default settings)
  • Project has "type": "module" in package.json

Cause:

  • This package has "type": "module" and exports ES modules
  • When Prettier loads config from the "prettier" field in package.json, it uses require() which receives the config wrapped in a default property
  • Prettier expects the configuration object directly, not wrapped

Solution:

Use .prettierrc.mjs instead of the "prettier" field in package.json:

  1. Create .prettierrc.mjs in your project root:
export { default } from '@jmlweb/prettier-config-base';
  1. Remove the "prettier" field from your package.json

This allows Prettier to execute the ES module code correctly and load the configuration as expected.

> Note: If no breaking changes were introduced in a version, it’s safe to upgrade without additional steps.

No breaking changes have been introduced yet. This package follows semantic versioning. When breaking changes are introduced, detailed migration instructions will be provided here.

For version history, see the Changelog.

Need Help? If you encounter issues during migration, please open an issue.

See CHANGELOG.md for version history and release notes.

MIT