gulp-plugin-prettier
Gulp plugin to format code with Prettier
Last updated a year ago by ikatyang .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install gulp-plugin-prettier 
SYNC missed versions from official npm registry.

gulp-plugin-prettier

npm build coverage

Gulp plugin to format code with Prettier

Changelog

Install

# using npm
npm install --save-dev gulp-plugin-prettier gulp prettier

# using yarn
yarn add --dev gulp-plugin-prettier gulp prettier

NOTE: For TypeScript user, you have to install @types/prettier to get full types.

Usage

(gulpfile.ts)

import * as gulp from 'gulp';
import * as prettier from 'gulp-plugin-prettier';

// replace unformatted with formatted
function format() {
  return gulp.src(['./src/**/*.ts', './gulpfile.ts'])
    .pipe(prettier.format({ singleQuote: true }))
    .pipe(gulp.dest(file => file.base));
}

// throw error if there is unformatted file
function format_check() {
  return gulp.src(['./src/**/*.ts', './gulpfile.ts'])
    .pipe(
      prettier.format({ singleQuote: true }, { reporter: prettier.Reporter.Error }),
    );
}

(gulpfile.js)

const gulp = require('gulp');
const prettier = require('gulp-plugin-prettier');

// replace unformatted with formatted
function format() {
  return gulp.src(['./src/**/*.js', './gulpfile.js'])
    .pipe(prettier.format({ singleQuote: true }))
    .pipe(gulp.dest(file => file.base));
}

// throw error if there is unformatted file
function format_check() {
  return gulp.src(['./src/**/*.js', './gulpfile.js'])
    .pipe(prettier.format({ singleQuote: true }, { reporter: 'error' }));
}

API

Prettier Options

export function format(prettier_options?: PrettierOptions, plugin_options?: PluginOptions): stream.Transform;

export interface PluginOptions {
  /**
   * default: 'warning'
   * report the filenames of files that are different from Prettier formatting
   */
  reporter?: Reporter | CustomReporter;
  /**
   * default: false
   * omit formatted files
   */
  filter?: boolean;
  /**
   * default: true
   * include rules from Prettier config files, e.g. .prettierrc
   */
  configFile?: boolean;
}

export const enum Reporter {
  /**
   * do nothing
   */
  None = 'none',
  /**
   * throw error for the filenames of files that are different from Prettier formatting
   */
  Error = 'error',
  /**
   * print warning for the filenames of files that are different from Prettier formatting
   */
  Warning = 'warning'
}

export type CustomReporter = (filename: string, different: boolean) => void;

Development

# lint
yarn run lint

# format
yarn run format

# build
yarn run build

# test
yarn run test

Related

License

MIT © Ika

Current Tags

  • 2.1.0                                ...           latest (a year ago)

5 Versions

  • 2.1.0                                ...           a year ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           5 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (20)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE