https://github.com/ikatyang/gulp-plugin-prettier
Gulp plugin to format code with Prettier
https://github.com/ikatyang/gulp-plugin-prettier
gulp gulp-plugin prettier
Last synced: 9 months ago
JSON representation
Gulp plugin to format code with Prettier
- Host: GitHub
- URL: https://github.com/ikatyang/gulp-plugin-prettier
- Owner: ikatyang
- License: mit
- Created: 2017-07-23T09:09:41.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T17:21:10.000Z (about 2 years ago)
- Last Synced: 2025-08-09T07:35:47.547Z (10 months ago)
- Topics: gulp, gulp-plugin, prettier
- Language: TypeScript
- Size: 636 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# gulp-plugin-prettier
[](https://www.npmjs.com/package/gulp-plugin-prettier)
[](https://travis-ci.org/ikatyang/gulp-plugin-prettier/builds)
[](https://codecov.io/gh/ikatyang/gulp-plugin-prettier)
Gulp plugin to format code with [Prettier](https://github.com/prettier/prettier)
[Changelog](https://github.com/ikatyang/gulp-plugin-prettier/blob/master/CHANGELOG.md)
## Install
```sh
# 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)
```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)
```ts
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](https://github.com/prettier/prettier#options)
```ts
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
```sh
# lint
yarn run lint
# format
yarn run format
# build
yarn run build
# test
yarn run test
```
## Related
- [gulp-prettier](https://github.com/bhargavrpatel/gulp-prettier)
- [gulp-nf-prettier](https://github.com/btholt/gulp-nf-prettier)
- [gulp-prettier-plugin](https://github.com/GAumala/gulp-prettier-plugin)
- [@bdchauvette/gulp-prettier](https://github.com/bdchauvette/gulp-prettier)
## License
MIT © [Ika](https://github.com/ikatyang)