Registry / testing / prettier-eslint

prettier-eslint

JSON →
library16.4.2jsnpmunverified

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.

npm install prettier-eslint
INSTALL
IMPORT
SIG · PRETTIER-ESLINT
P
prettier-eslint
testingjavascriptv16.4.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

prettierEslint
import prettierEslint from 'prettier-eslint';
const prettierEslint = require('prettier-eslint');
The primary formatting function is a default export. CommonJS `require` works but ESM `import` is preferred for modern Node.js environments and TypeScript.
Options
import type { Options } from 'prettier-eslint';
import { Options } from 'prettier-eslint';
Import types using `import type` for clarity and to avoid bundling type definitions at runtime, especially useful since v16.4.0's TypeScript migration.
prettierEslint
const { default: prettierEslint } = await import('prettier-eslint');
import prettierEslint from 'prettier-eslint'; // in CJS module
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.

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.

import prettierEslint from 'prettier-eslint'; import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs'; import { join } from 'node:path'; // Create a dummy ESLint config for demonstration const eslintConfigContent = `module.exports = { env: { node: true, es2021: true }, extends: ['eslint:recommended', 'prettier'], parserOptions: { ecmaVersion: 'latest' }, rules: { 'semi': ['error', 'never'], 'quotes': ['error', 'single'], 'indent': ['error', 2] } }; `; // Ensure a temporary directory exists for config and file const tempDir = join(process.cwd(), 'temp-eslint-test'); if (!existsSync(tempDir)) { mkdirSync(tempDir, { recursive: true }); } const eslintConfigFile = join(tempDir, '.eslintrc.js'); const tempFilePath = join(tempDir, 'example.js'); writeFileSync(eslintConfigFile, eslintConfigContent); const rawCode = `const myVar = "Hello world" ; function test ( ) { console . log ( myVar ) ; } test ( ) ;`; writeFileSync(tempFilePath, rawCode); async function formatCode() { try { console.log('Original code:\n', rawCode); const formattedCode = await prettierEslint({ text: rawCode, filePath: tempFilePath, // Essential for ESLint to find its config eslintConfig: { // Can be provided directly or found via filePath overrideConfigFile: eslintConfigFile, }, prettierOptions: { printWidth: 80, tabWidth: 2, semi: false, singleQuote: true }, fallbackPrettierOptions: { printWidth: 80, tabWidth: 2, semi: false, singleQuote: true }, logLevel: 'debug', }); console.log('\nFormatted code:\n', formattedCode); writeFileSync(tempFilePath.replace('.js', '.formatted.js'), formattedCode); } catch (error) { console.error('Error during formatting:', error); } } formatCode();
Debug
Known issues
breakingVersion 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.
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.
affects: >=17.0.0-alpha.0
gotchaWhen 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.
fix
Install the required peer dependencies: `npm install --save-dev svelte-eslint-parser prettier-plugin-svelte`.
affects: >=16.3.0
breakingPrettier 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.
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`.
affects: <16.1.2
gotchaBeginning 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.
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.
affects: >=16.4.2
gotcha`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.
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.
affects: All
Errors
Common errors & fixes
Error: ESLint: The 'parser' option is deprecated. Please use the 'languageOptions.parser' option instead.
Using ESLint v9 with `prettier-eslint` versions prior to v17 that do not fully support ESLint's flat configuration.
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`).
Error: Cannot find module 'prettier-eslint'
CommonJS `require()` used for an ESM-first package in a Node.js context, or package not installed/path incorrect.
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`.
ESLint: Definition for rule 'indent' was not found.
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.
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']`.
Prettier encountered an error. This is likely a bug in Prettier or one of its plugins.
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.
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`).
Error: Cannot find module 'tslib'
`tslib` is a runtime dependency (since `v16.4.2`) but is missing from `node_modules`.
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`.
Upgrade
Version history
16.4.2latest on npm
Audit
Dependencies
svelte-eslint-parseroptionalRequired for processing Svelte files, introduced with v16.3.0 for Svelte support.
prettier-plugin-svelteoptionalRequired for Prettier to correctly format Svelte files, introduced with v16.3.0 for Svelte support.
prettierrequiredCore dependency for formatting code before ESLint processing. Must be installed alongside.
eslintrequiredCore dependency for linting and fixing code after Prettier. Must be installed alongside.
tslibrequiredRuntime library for TypeScript helper functions, explicitly added as a dependency in v16.4.2.
Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources
prettier-eslint — npm install prettier-eslint · libregistry