{"id":20346,"library":"prettier-plugin-cspell","title":"Prettier CSpell Plugin","description":"A Prettier plugin that sorts dictionary keys in CSpell configuration files, ensuring consistent ordering of words, flagWords, ignoreWords, etc. Version 0.3.0 requires Prettier ^3 and ships TypeScript types. It is the only dedicated plugin for alphabetizing CSpell dictionary entries, focusing on lint-time ordering rather than runtime linting. The plugin is actively maintained with a small scope (dictionary file sorting only; config sorting planned). Alternative: manual sorting or other generic JSON sorters that don't understand CSpell structure.","status":"active","version":"0.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/sjwall/prettier-plugin-cspell","tags":["javascript","prettier","plugin","cspell","typescript"],"install":[{"cmd":"npm install prettier-plugin-cspell","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-cspell","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-cspell","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required as the plugin runs within Prettier's plugin system.","package":"prettier","optional":false}],"imports":[{"note":"Package is ESM-only. Use dynamic import() or configure Prettier's plugins array with a string path.","wrong":"const prettierPluginCspell = require('prettier-plugin-cspell')","symbol":"default","correct":"import prettierPluginCspell from 'prettier-plugin-cspell'"},{"note":"Prettier accepts plugin names as strings in config. Node.js require() may fail due to ESM-only.","wrong":"// Incorrect if using require(): plugins: [require('prettier-plugin-cspell')] (only works with ESM loader)","symbol":"plugins","correct":"// In .prettierrc: { \"plugins\": [\"prettier-plugin-cspell\"] }"},{"note":"TypeScript types are bundled. No separate @types package needed.","wrong":"","symbol":"type definitions","correct":"import type { Plugin } from 'prettier'; // types provided"}],"quickstart":{"code":"// 1. Install\nnpm i -D prettier prettier-plugin-cspell\n\n// 2. Configure .prettierrc\n{\n  \"plugins\": [\"prettier-plugin-cspell\"]\n}\n\n// 3. Create a CSpell dictionary file (e.g., .cspell/dictionary.txt or cspell.json words array)\n// The plugin will sort the words alphabetically on format.\n\n// Example cspell.json before:\n{\n  \"words\": [\"zebra\", \"apple\", \"mango\"]\n}\n\n// After running prettier --write:\n{\n  \"words\": [\"apple\", \"mango\", \"zebra\"]\n}","lang":"typescript","description":"Installation and basic usage of prettier-plugin-cspell to alphabetically sort CSpell dictionary words."},"warnings":[{"fix":"Upgrade Prettier to ^3.0.0","message":"Requires Prettier 3 or higher. Will not work with Prettier 2.","severity":"breaking","affected_versions":"<=2.x"},{"fix":"Use dynamic import() or configure Prettier's plugins array with a string (e.g., 'prettier-plugin-cspell').","message":"Package is ESM-only. CommonJS require() will throw ERR_REQUIRE_ESM.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Current scope is limited; check documentation for planned features.","message":"Only sorts dictionary keys (words, flagWords, ignoreWords) in CSpell JSON/YAML files. Does not sort other properties or config keys.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Place this plugin last in the plugins array to avoid conflicts.","message":"Plugin may interfere with other Prettier plugins if they also modify the same file types. Ensure plugin order in the plugins array.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use dynamic import() in scripts, or reference the plugin by string name in Prettier config (e.g., 'prettier-plugin-cspell').","cause":"Using CommonJS require() to load the plugin.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module"},{"fix":"Run 'npm install -D prettier-plugin-cspell' and ensure it's in package.json.","cause":"Plugin not installed or not in node_modules.","error":"Cannot find module 'prettier-plugin-cspell'"},{"fix":"Add 'plugins: [\"prettier-plugin-cspell\"]' to .prettierrc. Ensure the file has a supported extension (e.g., .json, .yaml) and is within Prettier's range.","cause":"Plugin is not registered in Prettier config, or the file is not matched by Prettier's file pattern.","error":"prettier --write did not sort my CSpell file"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}