gulp-plugin-prettier

raw JSON →
2.1.0 verified Sat Apr 25 auth: no javascript

A Gulp plugin that formats code using Prettier with support for custom Prettier options, config file resolution, and flexible error/warning reporting. Version 2.1.0 is the latest stable release (last updated 2020). It requires Gulp 3.9+ or 4.0+ and Prettier 1.4+ / 2.x / 3.x. Unlike alternative Gulp Prettier plugins, it offers a clean API with TypeScript types and a choice of reporters (warning, error, none) or a custom reporter callback. It also supports filtering formatted files and respects .prettierrc configuration. The package is minimal and focuses on a single function (format) with consistent options.

error TypeError: prettier.format is not a function
cause Using default import instead of named import in TypeScript/ESM
fix
Use import { format } from 'gulp-plugin-prettier'
error Cannot find module 'gulp-plugin-prettier'
cause Package not installed or installed as dev dependency but missing peer dependencies
fix
npm install --save-dev gulp-plugin-prettier gulp prettier
error Error: reporter must be one of 'none', 'warning', 'error' or a custom function
cause Invalid reporter string passed
fix
Use Reporter enum or one of the allowed strings: 'none', 'warning', 'error'
deprecated The 'reporter' option as a string is deprecated; use Reporter enum or 'none'/'warning'/'error'.
fix Use prettier.Reporter.Error instead of 'error'.
gotcha Can't use 'filter' option when using Reporter.Error because filter may skip files and error reporter expects to check all.
fix Avoid combining filter: true with reporter: Error.
gotcha TypeScript users need to install @types/prettier separately for full type safety.
fix Run npm install --save-dev @types/prettier
npm install gulp-plugin-prettier
yarn add gulp-plugin-prettier
pnpm add gulp-plugin-prettier

Shows how to use format with Error reporter to fail on unformatted files, and pipe to destination.

const gulp = require('gulp');
const { format, Reporter } = require('gulp-plugin-prettier');

function formatTask() {
  return gulp.src(['./src/**/*.js'])
    .pipe(format({ singleQuote: true }, { reporter: Reporter.Error }))
    .pipe(gulp.dest('./dist'));
}

exports.format = formatTask;