Prettier Plugin AutoCorrect
raw JSON → 0.4.3 verified Sat Apr 25 auth: no javascript
A Prettier plugin that integrates AutoCorrect to format copywriting in various file types, automatically adding spaces between CJK and Latin characters, correcting punctuation, and enforcing consistent whitespace. Version 0.4.3 requires Prettier 3.0.3+ and Node.js 14.18+ (LTS). Built on top of the autocorrect library, it aims to be a drop-in formatter but may not always match Prettier's format exactly. Ships TypeScript types. Developed by the un-ts team, part of a collection of Prettier plugins. Currently under active development with a focus on CJK text formatting.
Common errors
error Cannot find module 'prettier-plugin-autocorrect' ↓
cause Plugin not installed as a devDependency or not resolved correctly.
fix
Run 'npm install -D prettier prettier-plugin-autocorrect' or 'yarn add -D prettier prettier-plugin-autocorrect'.
error Error: Couldn't resolve plugin "prettier-plugin-autocorrect" ↓
cause Plugin is not declared in .prettierrc's plugins array or Prettier version is too old.
fix
Add '"plugins": ["prettier-plugin-autocorrect"]' to .prettierrc and ensure Prettier >=3.0.3.
error SyntaxError: Invalid or unexpected token (using require) ↓
cause Trying to require the plugin in CommonJS (CJS) when it is ESM-only.
fix
Use 'const { AutocorrectPlugin } = require('prettier-plugin-autocorrect')' if available, or switch to ESM imports. Prefer adding to Prettier config instead of requiring directly.
Warnings
breaking Requires Prettier 3.x; not compatible with Prettier 2.x. ↓
fix Update Prettier to version 3.0.3 or higher.
gotcha Plugin output may not always match Prettier's formatting conventions, especially in edge cases. ↓
fix Review formatted output manually or disable plugin for specific files where needed.
deprecated Node.js 14 is EOL; future versions may drop support. ↓
fix Upgrade Node.js to v16 or later, as recommended by the package.
gotcha Plugin only works with file types supported by autocorrect (Markdown, plain text, etc). ↓
fix Ensure your file extensions are in the autocorrect list; otherwise, plugin may not apply.
Install
npm install prettier-plugin-autocorrect yarn add prettier-plugin-autocorrect pnpm add prettier-plugin-autocorrect Imports
- prettier-plugin-autocorrect wrong
import { prettier-plugin-autocorrect } from 'prettier-plugin-autocorrect' (no named import)correctAdd to .prettierrc: { "plugins": ["prettier-plugin-autocorrect"] } - AutocorrectPlugin wrong
const prettierPluginAutocorrect = require('prettier-plugin-autocorrect') (may not work in CJS)correctconst { AutocorrectPlugin } = require('prettier-plugin-autocorrect') - options wrong
import { options } from 'prettier-plugin-autocorrect' (no such export)correct// No import needed, use Prettier options in config: { "autocorrectOptions": { ... } }
Quickstart
// Install
yarn add -D prettier prettier-plugin-autocorrect
// .prettierrc
{
"plugins": ["prettier-plugin-autocorrect"]
}
// Format a file
npx prettier --write "src/**/*.md"