{"id":11581,"library":"prettier-eslint","title":"Prettier ESLint Integrator","description":"Prettier-ESLint is a JavaScript utility that orchestrates code formatting by running Prettier first, then applying ESLint's `--fix` functionality. This sequential approach is crucial for maintaining consistent code style across projects, as it resolves potential conflicts between Prettier's opinionated formatting and custom ESLint rules. The current stable version is 16.4.2, with an active development branch targeting version 17 which introduces support for ESLint v9's flat configuration. The package is actively maintained with regular patch and minor releases, alongside a new major version in alpha. It differentiates itself by providing a single programmatic interface to combine these tools, ensuring that ESLint fixes are applied *after* Prettier's formatting, thus preventing ESLint from undoing Prettier's work.","status":"active","version":"16.4.2","language":"javascript","source_language":"en","source_url":"https://github.com/prettier/prettier-eslint","tags":["javascript","eslint","formatter","linter","prettier","prettier-eslint","typescript"],"install":[{"cmd":"npm install prettier-eslint","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-eslint","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-eslint","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for processing Svelte files, introduced with v16.3.0 for Svelte support.","package":"svelte-eslint-parser","optional":true},{"reason":"Required for Prettier to correctly format Svelte files, introduced with v16.3.0 for Svelte support.","package":"prettier-plugin-svelte","optional":true},{"reason":"Core dependency for formatting code before ESLint processing. Must be installed alongside.","package":"prettier","optional":false},{"reason":"Core dependency for linting and fixing code after Prettier. Must be installed alongside.","package":"eslint","optional":false},{"reason":"Runtime library for TypeScript helper functions, explicitly added as a dependency in v16.4.2.","package":"tslib","optional":false}],"imports":[{"note":"The primary formatting function is a default export. CommonJS `require` works but ESM `import` is preferred for modern Node.js environments and TypeScript.","wrong":"const prettierEslint = require('prettier-eslint');","symbol":"prettierEslint","correct":"import prettierEslint from 'prettier-eslint';"},{"note":"Import types using `import type` for clarity and to avoid bundling type definitions at runtime, especially useful since v16.4.0's TypeScript migration.","wrong":"import { Options } from 'prettier-eslint';","symbol":"Options","correct":"import type { Options } from 'prettier-eslint';"},{"note":"For CommonJS modules that need to load `prettier-eslint` dynamically or in an async context, `await import()` is the correct pattern for ESM-first packages. The default export is accessed via `.default`. Direct `import` syntax is not valid in CJS.","wrong":"import prettierEslint from 'prettier-eslint'; // in CJS module","symbol":"prettierEslint","correct":"const { default: prettierEslint } = await import('prettier-eslint');"}],"quickstart":{"code":"import prettierEslint from 'prettier-eslint';\nimport { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';\nimport { join } from 'node:path';\n\n// Create a dummy ESLint config for demonstration\nconst eslintConfigContent = `module.exports = {\n  env: { node: true, es2021: true },\n  extends: ['eslint:recommended', 'prettier'],\n  parserOptions: { ecmaVersion: 'latest' },\n  rules: {\n    'semi': ['error', 'never'],\n    'quotes': ['error', 'single'],\n    'indent': ['error', 2]\n  }\n};\n`;\n\n// Ensure a temporary directory exists for config and file\nconst tempDir = join(process.cwd(), 'temp-eslint-test');\nif (!existsSync(tempDir)) {\n  mkdirSync(tempDir, { recursive: true });\n}\n\nconst eslintConfigFile = join(tempDir, '.eslintrc.js');\nconst tempFilePath = join(tempDir, 'example.js');\n\nwriteFileSync(eslintConfigFile, eslintConfigContent);\n\nconst rawCode = `const   myVar  =  \"Hello world\" ; function   test ( ) {  console . log ( myVar )  ;  }  test ( )  ;`;\nwriteFileSync(tempFilePath, rawCode);\n\nasync function formatCode() {\n  try {\n    console.log('Original code:\\n', rawCode);\n\n    const formattedCode = await prettierEslint({\n      text: rawCode,\n      filePath: tempFilePath, // Essential for ESLint to find its config\n      eslintConfig: { // Can be provided directly or found via filePath\n        overrideConfigFile: eslintConfigFile,\n      },\n      prettierOptions: { printWidth: 80, tabWidth: 2, semi: false, singleQuote: true },\n      fallbackPrettierOptions: { printWidth: 80, tabWidth: 2, semi: false, singleQuote: true },\n      logLevel: 'debug',\n    });\n\n    console.log('\\nFormatted code:\\n', formattedCode);\n    writeFileSync(tempFilePath.replace('.js', '.formatted.js'), formattedCode);\n\n  } catch (error) {\n    console.error('Error during formatting:', error);\n  }\n}\n\nformatCode();\n","lang":"typescript","description":"This quickstart demonstrates how to programmatically format a JavaScript string using `prettier-eslint`. It creates a temporary ESLint configuration file and a JavaScript file to illustrate the process, showing how to pass the code, file path, and configuration options. It's crucial for ESLint to correctly locate its configuration to apply fixes effectively."},"warnings":[{"fix":"Upgrade to `prettier-eslint@latest` and follow ESLint v9's flat configuration migration guide. Ensure `eslint.config.js` is set up correctly for your project.","message":"Version 17.0.0-alpha.0 introduces support for ESLint v9's flat configuration. Users migrating to ESLint v9 will need to upgrade to `prettier-eslint` v17 or later and adjust their configuration accordingly. Older `.eslintrc.*` files will not be compatible with ESLint v9 and by extension, `prettier-eslint` v17.","severity":"breaking","affected_versions":">=17.0.0-alpha.0"},{"fix":"Install the required peer dependencies: `npm install --save-dev svelte-eslint-parser prettier-plugin-svelte`.","message":"When using `prettier-eslint` with Svelte files (support introduced in v16.3.0), you must install `svelte-eslint-parser` and `prettier-plugin-svelte` as peer dependencies. Without them, Svelte files will not be processed correctly.","severity":"gotcha","affected_versions":">=16.3.0"},{"fix":"Upgrade `prettier-eslint` to version `16.1.2` or higher to ensure compatibility with Prettier v3. Ensure `prettier` is also updated to v3 or later: `npm install --save-dev prettier@latest prettier-eslint@latest`.","message":"Prettier v3 introduced breaking changes that required updates in `prettier-eslint`. Versions prior to `16.1.2` might have compatibility issues or unexpected behavior when used with Prettier v3.","severity":"breaking","affected_versions":"<16.1.2"},{"fix":"Ensure `tslib` is installed in your project: `npm install tslib` or `yarn add tslib`. In some TypeScript configurations, setting `compilerOptions.importHelpers = false` in `tsconfig.json` can remove the runtime dependency on `tslib` for generated code, if appropriate for your project.","message":"Beginning with `v16.4.2`, `tslib` was explicitly added as a direct dependency. While usually installed automatically, environments with strict dependency resolution or custom build setups might encounter 'Cannot find module 'tslib'' errors if it's not present.","severity":"gotcha","affected_versions":">=16.4.2"},{"fix":"If the default order is not yielding desired results, consider setting `prettierLast: true` in your options: `prettierEslint({ text, filePath, prettierLast: true })`. However, the default order (Prettier then ESLint) is generally recommended to avoid conflicts.","message":"`prettier-eslint` performs formatting by running Prettier *then* ESLint `--fix`. If you desire ESLint fixes to run first, or if you encounter unexpected formatting, be aware of the `prettierLast` option which can reverse this order.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Upgrade `prettier-eslint` to `v17.0.0-alpha.0` or later and migrate your ESLint configuration to the flat config format (`eslint.config.js`).","cause":"Using ESLint v9 with `prettier-eslint` versions prior to v17 that do not fully support ESLint's flat configuration.","error":"Error: ESLint: The 'parser' option is deprecated. Please use the 'languageOptions.parser' option instead."},{"fix":"For ESM projects, use `import prettierEslint from 'prettier-eslint';`. For CommonJS projects that need dynamic loading, use `const { default: prettierEslint } = await import('prettier-eslint');`. Ensure the package is installed: `npm install prettier-eslint`.","cause":"CommonJS `require()` used for an ESM-first package in a Node.js context, or package not installed/path incorrect.","error":"Error: Cannot find module 'prettier-eslint'"},{"fix":"Ensure `eslint-config-prettier` is installed and properly extended in your ESLint configuration to disable conflicting formatting rules. For example, in `.eslintrc.js`: `extends: ['eslint:recommended', 'prettier']`.","cause":"ESLint rules that affect formatting (like `indent`) conflict with Prettier. `prettier-eslint` is designed to run Prettier first, then ESLint fixes. If `eslint-config-prettier` is not used, ESLint might try to fix formatting already handled by Prettier.","error":"ESLint: Definition for rule 'indent' was not found."},{"fix":"Check the `prettier-eslint` changelog for compatibility with your `prettier` version. Ensure `prettier` is updated to a compatible version with `prettier-eslint` (e.g., `prettier@^3.1.0` for `prettier-eslint@^16.1.2`).","cause":"Often caused by an unsupported version of Prettier, a breaking change in Prettier's API not yet supported by `prettier-eslint`, or a malformed input file.","error":"Prettier encountered an error. This is likely a bug in Prettier or one of its plugins."},{"fix":"Install `tslib` as a direct dependency: `npm install tslib` or `yarn add tslib`. Verify it's present in your `package.json` and `node_modules`.","cause":"`tslib` is a runtime dependency (since `v16.4.2`) but is missing from `node_modules`.","error":"Error: Cannot find module 'tslib'"}],"ecosystem":"npm"}