or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/npm-prettier-eslint-cli

CLI tool for formatting JavaScript files using both Prettier and ESLint

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/prettier-eslint-cli@8.0.x

To install, run

npx @tessl/cli install tessl/npm-prettier-eslint-cli@8.0.0

0

# prettier-eslint-cli

1

2

prettier-eslint-cli is a command-line interface for formatting JavaScript files using both Prettier and ESLint. It combines Prettier's formatting capabilities with ESLint's linting rules, allowing developers to maintain consistent code style while respecting project-specific ESLint configurations.

3

4

## Package Information

5

6

- **Package Name**: prettier-eslint-cli

7

- **Package Type**: npm

8

- **Language**: JavaScript (Node.js)

9

- **Installation**: `npm install --save-dev prettier-eslint-cli`

10

11

## Core Imports

12

13

This package provides a CLI binary rather than importable modules:

14

15

```bash

16

# Global installation

17

npm install -g prettier-eslint-cli

18

prettier-eslint "src/**/*.js"

19

20

# Local installation (recommended)

21

npm install --save-dev prettier-eslint-cli

22

npx prettier-eslint "src/**/*.js"

23

```

24

25

## Basic Usage

26

27

```bash

28

# Format files matching a glob pattern

29

prettier-eslint "src/**/*.js"

30

31

# Format files and write changes in-place

32

prettier-eslint --write "src/**/*.js"

33

34

# Format code from stdin

35

echo "const foo = 'bar'" | prettier-eslint --stdin

36

37

# Check for formatting differences (useful in CI)

38

prettier-eslint --list-different "src/**/*.js"

39

```

40

41

In package.json scripts:

42

43

```json

44

{

45

"scripts": {

46

"format": "prettier-eslint --write \"src/**/*.js\"",

47

"format:check": "prettier-eslint --list-different \"src/**/*.js\""

48

}

49

}

50

```

51

52

## Architecture

53

54

prettier-eslint-cli operates as a file processing pipeline:

55

56

1. **File Discovery**: Uses glob patterns to find target files

57

2. **Ignore File Processing**: Applies .eslintignore and .prettierignore rules

58

3. **Format Engine**: Delegates to prettier-eslint for actual formatting

59

4. **Output Processing**: Handles writing files, stdout output, or diff reporting

60

5. **Error Handling**: Provides comprehensive error reporting and debugging information

61

62

The tool can process files from glob patterns or stdin, with extensive configuration options for both Prettier and ESLint behavior.

63

64

## Capabilities

65

66

### File Pattern Processing

67

68

Process multiple files using glob patterns with support for ignore files and custom patterns.

69

70

```bash { .api }

71

prettier-eslint <globs>... [options]

72

73

# Examples:

74

prettier-eslint "src/**/*.js"

75

prettier-eslint "lib/**/*.js" "test/**/*.js"

76

prettier-eslint "**/*.{js,jsx,ts,tsx}"

77

```

78

79

**Glob Pattern Options:**

80

- Multiple glob patterns are supported

81

- Automatically excludes `**/node_modules/**` unless explicitly included

82

- Supports standard glob syntax (*, **, ?, [], {})

83

84

### Output Mode Control

85

86

Control how formatted results are output - to stdout, written in-place, or as difference reports.

87

88

```bash { .api }

89

# Write formatted content to stdout (default)

90

prettier-eslint "src/**/*.js"

91

92

# Write changes in-place to original files

93

prettier-eslint --write "src/**/*.js"

94

95

# List files that would be changed (CI mode)

96

prettier-eslint --list-different "src/**/*.js"

97

```

98

99

### Stdin Processing

100

101

Process code from standard input for integration with editors and pipes.

102

103

```bash { .api }

104

# Format code from stdin

105

echo "const foo = 'bar'" | prettier-eslint --stdin

106

107

# Specify file path for stdin (affects ESLint config detection)

108

echo "const foo = 'bar'" | prettier-eslint --stdin --stdin-filepath src/example.js

109

```

110

111

### Ignore File Configuration

112

113

Control which files are processed using ignore file patterns.

114

115

```bash { .api }

116

# Apply .eslintignore patterns (default: true)

117

prettier-eslint --eslint-ignore "src/**/*.js"

118

119

# Disable .eslintignore patterns

120

prettier-eslint --no-eslint-ignore "src/**/*.js"

121

122

# Apply .prettierignore patterns (default: true)

123

prettier-eslint --prettier-ignore "src/**/*.js"

124

125

# Disable .prettierignore patterns

126

prettier-eslint --no-prettier-ignore "src/**/*.js"

127

128

# Include dotfiles in processing

129

prettier-eslint --include-dot-files "src/**/*"

130

131

# Add custom ignore patterns

132

prettier-eslint --ignore "**/*.min.js" --ignore "dist/**" "src/**/*.js"

133

```

134

135

### Tool Configuration

136

137

Configure paths to eslint and prettier binaries and configuration files.

138

139

```bash { .api }

140

# Specify eslint binary path

141

prettier-eslint --eslint-path ./node_modules/.bin/eslint "src/**/*.js"

142

143

# Specify eslint config file

144

prettier-eslint --eslint-config-path .eslintrc.custom.js "src/**/*.js"

145

146

# Specify prettier binary path

147

prettier-eslint --prettier-path ./node_modules/.bin/prettier "src/**/*.js"

148

149

# Specify prettier config file

150

prettier-eslint --config .prettierrc.custom.json "src/**/*.js"

151

```

152

153

### Execution Order Control

154

155

Control whether prettier or eslint runs first in the formatting process.

156

157

```bash { .api }

158

# Run prettier first, then eslint --fix (default)

159

prettier-eslint "src/**/*.js"

160

161

# Run eslint --fix first, then prettier

162

prettier-eslint --prettier-last "src/**/*.js"

163

```

164

165

### Logging Configuration

166

167

Configure logging levels for debugging and monitoring.

168

169

```bash { .api }

170

# Set log level

171

prettier-eslint --log-level debug "src/**/*.js"

172

prettier-eslint -l warn "src/**/*.js"

173

174

# Available log levels: silent, error, warn, info, debug, trace

175

```

176

177

**Log Levels:**

178

- `silent`: No output

179

- `error`: Only errors

180

- `warn`: Errors and warnings (default)

181

- `info`: Informational messages

182

- `debug`: Debug information

183

- `trace`: Verbose debugging

184

185

### Prettier Formatting Options

186

187

Configure Prettier-specific formatting options directly through CLI arguments.

188

189

```bash { .api }

190

# Tab/spacing configuration

191

prettier-eslint --use-tabs "src/**/*.js"

192

prettier-eslint --tab-width 4 "src/**/*.js"

193

prettier-eslint --print-width 120 "src/**/*.js"

194

195

# Quote configuration

196

prettier-eslint --single-quote "src/**/*.js"

197

prettier-eslint --no-single-quote "src/**/*.js"

198

199

# Semicolon configuration

200

prettier-eslint --semi "src/**/*.js"

201

prettier-eslint --no-semi "src/**/*.js"

202

203

# Trailing comma configuration

204

prettier-eslint --trailing-comma es5 "src/**/*.js"

205

prettier-eslint --trailing-comma all "src/**/*.js"

206

prettier-eslint --trailing-comma none "src/**/*.js"

207

208

# Bracket spacing

209

prettier-eslint --bracket-spacing "src/**/*.js"

210

prettier-eslint --no-bracket-spacing "src/**/*.js"

211

212

# JSX-specific options

213

prettier-eslint --jsx-bracket-same-line "src/**/*.jsx"

214

215

# Arrow function parentheses

216

prettier-eslint --arrow-parens avoid "src/**/*.js"

217

prettier-eslint --arrow-parens always "src/**/*.js"

218

219

# Parser selection

220

prettier-eslint --parser babel "src/**/*.js"

221

prettier-eslint --parser typescript "src/**/*.ts"

222

223

# Pragma support

224

prettier-eslint --require-pragma "src/**/*.js"

225

prettier-eslint --insert-pragma "src/**/*.js"

226

227

# Prose wrapping (for markdown)

228

prettier-eslint --prose-wrap always "docs/**/*.md"

229

prettier-eslint --prose-wrap never "docs/**/*.md"

230

prettier-eslint --prose-wrap preserve "docs/**/*.md"

231

```

232

233

**Prettier Option Values:**

234

235

- `--trailing-comma`: `none`, `es5`, `all`

236

- `--arrow-parens`: `avoid`, `always`

237

- `--parser`: `babel`, `typescript`, `flow`, `json`, `css`, `markdown`, etc.

238

- `--prose-wrap`: `always`, `never`, `preserve`

239

- Boolean options can be negated with `--no-` prefix

240

241

**Pragma Options Detail:**

242

- `--require-pragma`: Only format files containing a special `@format` comment at the top. Useful for gradual adoption in large codebases.

243

- `--insert-pragma`: Automatically insert a `@format` pragma comment at the top of formatted files. Works well with `--require-pragma`.

244

- `--prose-wrap`: Controls how markdown text wrapping is handled (`always` = wrap at print width, `never` = no wrapping, `preserve` = keep existing wrapping)

245

246

## Exit Codes

247

248

The CLI uses standard exit codes for automation and CI/CD integration:

249

250

```bash { .api }

251

# Exit code 0: Success - all files processed without errors

252

prettier-eslint "src/**/*.js"

253

echo $? # 0

254

255

# Exit code 1: Formatting differences found (with --list-different)

256

prettier-eslint --list-different "src/**/*.js" # when files differ from expected format

257

echo $? # 1

258

259

# Exit code 1: Formatting errors occurred

260

prettier-eslint "src/broken-syntax.js" # when formatting fails due to syntax errors

261

echo $? # 1

262

263

# Exit code 1: Configuration or runtime errors

264

prettier-eslint --eslint-config-path ./nonexistent.js "src/**/*.js"

265

echo $? # 1

266

```

267

268

**Exit Code Meanings:**

269

- `0`: Success - all operations completed without errors

270

- `1`: Failure - formatting errors, syntax errors, configuration issues, or differences found (in `--list-different` mode)

271

272

## Environment Variables

273

274

The CLI supports environment variables for configuration:

275

276

```bash { .api }

277

# Set default log level (overrides default "warn")

278

LOG_LEVEL=debug prettier-eslint "src/**/*.js"

279

LOG_LEVEL=silent prettier-eslint "src/**/*.js"

280

281

# Available values: silent, error, warn, info, debug, trace

282

# Equivalent to using --log-level flag

283

```

284

285

**Environment Variable Options:**

286

- `LOG_LEVEL`: Sets the default logging level (same values as `--log-level`)

287

288

## Integration Examples

289

290

### npm Scripts

291

292

```json

293

{

294

"scripts": {

295

"format": "prettier-eslint --write \"src/**/*.{js,jsx,ts,tsx}\"",

296

"format:check": "prettier-eslint --list-different \"src/**/*.{js,jsx,ts,tsx}\"",

297

"precommit": "prettier-eslint --write --list-different \"src/**/*.{js,jsx,ts,tsx}\""

298

}

299

}

300

```

301

302

### Git Hooks

303

304

```bash

305

# .git/hooks/pre-commit

306

#!/bin/sh

307

prettier-eslint --list-different "src/**/*.js"

308

if [ $? -ne 0 ]; then

309

echo "Code formatting issues found. Run 'npm run format' to fix."

310

exit 1

311

fi

312

```

313

314

### CI/CD Pipeline

315

316

```yaml

317

# GitHub Actions example

318

- name: Check code formatting

319

run: |

320

npm install

321

npx prettier-eslint --list-different "src/**/*.{js,jsx,ts,tsx}"

322

```

323

324

### Editor Integration

325

326

#### Vim Configuration

327

328

```vim

329

" Vim configuration - basic formatting with gq command

330

autocmd FileType javascript set formatprg=prettier-eslint\ --stdin

331

332

" Auto-format on save (optional)

333

autocmd BufWritePre *.js :normal gggqG

334

```

335

336

This configuration allows vim users to:

337

- Use the `gq` command for manual formatting with prettier-eslint

338

- Optionally auto-format JavaScript files on save

339

340

## Configuration Files Support

341

342

prettier-eslint-cli respects standard configuration files:

343

344

- **ESLint**: `.eslintrc.*`, `eslint.config.js`, `package.json` eslintConfig

345

- **Prettier**: `.prettierrc.*`, `prettier.config.js`, `package.json` prettier

346

- **Ignore Files**: `.eslintignore`, `.prettierignore`

347

348

## Error Handling

349

350

The CLI provides comprehensive error handling and logging:

351

352

- **Individual File Errors**: Logged with full stack traces but don't stop processing other files

353

- **Uncaught Exceptions**: Provide debugging steps and issue reporting guidance

354

- **Configuration Errors**: Clear messages about missing or invalid config files

355

- **Syntax Errors**: Detailed error information with file locations

356

- **Exit Codes**: Returns appropriate exit codes for automation (0 = success, 1 = errors/differences)

357

358

**Common Error Scenarios:**

359

- Invalid JavaScript syntax in source files

360

- Incompatible ESLint and Prettier rule configurations

361

- Missing required dependencies (`prettier-eslint` or fallback)

362

- File permission issues preventing read/write operations

363

- Invalid glob patterns or file paths

364

365

**Troubleshooting Steps:**

366

1. Verify file syntax is valid JavaScript/TypeScript

367

2. Check ESLint and Prettier configurations are compatible

368

3. Ensure all required dependencies are installed

369

4. Verify file permissions allow reading/writing

370

5. Use `--log-level debug` for detailed diagnostic information

371

372

## Dependencies

373

374

prettier-eslint-cli requires:

375

376

- **Node.js**: >=16.10.0

377

- **Peer Dependency**: `prettier-eslint` (optional, falls back to internal version)

378

379

The package includes an internal fallback version (`@prettier/eslint`) when `prettier-eslint` is not installed.