Prettier ESLint CLI

8.0.1 · active · verified Wed Apr 22

prettier-eslint-cli is a command-line interface (CLI) tool designed to streamline code formatting by integrating Prettier with ESLint. It first formats code using Prettier, then passes the output to ESLint for auto-fixing any remaining linting issues according to your ESLint configuration. This approach helps resolve potential conflicts between Prettier's strict formatting and ESLint's stylistic rules. The current stable version is 8.0.1, though alpha versions for v9 are actively being released, indicating ongoing development, including support for ESLint v9's new flat config system. Key differentiators include its single-command workflow for combined formatting and linting, and its intelligent handling of tool conflicts by prioritizing Prettier's output before ESLint's fixes. It primarily targets JavaScript and TypeScript projects that utilize both tools for code quality.

Common errors

Warnings

Install

Imports

Quickstart

This script demonstrates how to set up `prettier-eslint-cli` in a project, including installing its peer dependencies and creating minimal configuration files. It then uses `npx prettier-eslint-cli` to format and fix both JavaScript and TypeScript files, showing the before-and-after content.

#!/usr/bin/env bash

# Create a directory and some dummy JavaScript and TypeScript files
mkdir -p src
echo "const foo = \"bar\"; function add(a,b){return a + b;}" > src/file1.js
echo "let x = 10; const myObject = { key: 'value', other: 123 };" > src/file2.ts

# Install the necessary peer dependencies (Prettier, ESLint, prettier-eslint)
# This ensures that prettier-eslint-cli has the underlying tools it needs.
npm install --save-dev prettier eslint prettier-eslint

# Optionally, create minimal configuration files for prettier and eslint
# .prettierrc.json
echo '{"singleQuote": true, "semi": true, "printWidth": 80}' > .prettierrc.json
# .eslintrc.js (using recommended configs for demonstration)
echo 'module.exports = { extends: ["eslint:recommended", "prettier"] };' > .eslintrc.js

# Run prettier-eslint-cli to format and fix the files in place
npx prettier-eslint-cli --write 'src/**/*.js' 'src/**/*.ts'

# Output the content of the formatted files to see the changes
echo "\n--- Formatted src/file1.js ---"
cat src/file1.js

echo "\n--- Formatted src/file2.ts ---"
cat src/file2.ts

# Expected output for src/file1.js (example, exact depends on config):
# const foo = 'bar';
# function add(a, b) {
#   return a + b;
# }

view raw JSON →