Giter VIP home page Giter VIP logo

gulp-phpcbf's Introduction

gulp-phpcbf NPM version

Gulp plugin for running PHP Code Beautifier.

WARNING - This will modify your source files, ensure things are backed up!

Install

  • Install the plugin with the following command:
npm install gulp-phpcbf --save-dev

Usage

var gulp = require('gulp');
var phpcbf = require('gulp-phpcbf');
var gutil = require('gutil');

gulp.task('phpcbf', function () {
  return gulp.src(['src/**/*.php', '!src/vendor/**/*.*'])
  .pipe(phpcbf({
    bin: 'phpcbf',
    standard: 'PSR2',
    warningSeverity: 0
  }))
  .on('error', gutil.log)
  .pipe(gulp.dest('src'));
});

Inspired by gulp-phpcs.

gulp-phpcbf's People

Contributors

gaving avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bross07

gulp-phpcbf's Issues

Can't get it to work!

Can't get gulp-phpcbf to work! Any help here would be greatly appreciated!

I AM able to run phpcbf from the terminal though with the following command:

$ (Project Folder) lib/vendor/composer/bin/phpcbf --standard="WordPress" src/test.php

Result:

Changing into directory /path/to/project/src
Processing test.php [PHP => 945 tokens in 193 lines]... DONE in 36ms (0 fixable violations)
No fixable errors were found
Time: 70ms; Memory: 5.75Mb

I have composer installed in my project directory in:

path/to/project/lib/vendor/composer

I'm also using gulp-phpcs and it seems to be working fine, I get an output of problems. I've also got the WP coding standards installed, although gulp-phpcbf fails with any standard.

PHP Codesniffer and the WP Standards seem to be installed fine, as they also work with gulp-phpcs. I'm on Ubuntu.

Here's my gulp task:

gulp.task( 'phpcbf', function() {
    return gulp.src(['src/**/*.php']) 
        .pipe(plugins.phpcbf({
            bin: 'lib/vendor/composer/bin/phpcbf',
            standard: 'WordPress'
            //warningSeverity: 0
        }))
        .pipe(gulp.dest(['src/']));
});

I get the following error:

events.js:141
      throw er; // Unhandled 'error' event
      ^
  Error: /bin/sh -c lib/vendor/composer/bin/phpcbf --standard="WordPress"

  - Command failed: /bin/sh -c lib/vendor/composer/bin/phpcbf --standard="WordPress"

  - child_process.js:203 ChildProcess.exithandler
    child_process.js:203:12

  - events.js:87 emitTwo
    events.js:87:13

  - events.js:172 ChildProcess.emit
    events.js:172:7

  - child_process.js:817 maybeClose
    internal/child_process.js:817:16

  - child_process.js:211 Process.ChildProcess._handle.onexit
    internal/child_process.js:211:5

Some kind of permissions problem? Why can't gulp execute the phpcbf script?

Not sure where to go from here. Thanks for any help!

gulp watch

Hi! This is a really great package, very handy!

I'm running into a problem when trying to use this with gulp watch. Basically, gulp-phpcbf retriggers itself when writing out the changed files, so it just keeps running again and again. Do you have any ideas on how to be able to utilize phpcbf with gulp watch?

Here's my relevant code:

gulp.task('phpcbf', function() {
    return gulp.src('app/**/*.php')
        .pipe(phpcbf({
            bin: 'phpcbf',
            standard: 'PSR2',
            warningSeverity: 0
        })
        .pipe(gulp.dest('app'));
});

gulp.task('watch', function() {
    gulp.watch('app/**/*.php', ['phpcbf']);
});

Thanks!

Need 'maxBuffer' option

Hi there,

Awesome tool, making good use of it so far. Thanks for you efforts.

I've noticed that on large code bases, the following error is logged and the files not 'fixed' as a result:
{ [Error: stdout maxBuffer exceeded.]
name: 'Error',
message: 'stdout maxBuffer exceeded.',
stack: 'Error: stdout maxBuffer exceeded.\n at Socket. (child_process.js:699:13)\n at Socket.emit (events.js:95:17)\n at Socket. (stream_readable.js:765:14)\n at Socket.emit (events.js:92:17)\n at emitReadable (_stream_readable.js:427:10)\n at emitReadable (_stream_readable.js:423:5)\n at readableAddChunk (_stream_readable.js:166:9)\n at Socket.Readable.push (_stream_readable.js:128:10)\n at Pipe.onread (net.js:529:21)',
showStack: false,
showProperties: true,
plugin: 'gulp-phpcbf' }

Is there a way to set 'maxBuffer' through your tool's settings? If not, consider it a feature request!

Thanks again.

Not sure if it's doing what it should be

Hey there,
Thanks for doing this; it's pretty cool. =)

So I'm using this for a WordPress project. When I run this task it completes; however, no changes are made, even though, PHPCS reports code issues. If I uncomment the gulp.dest stream, the files are sent to the src folder that are defined within the phpSource variable I set. So it seems like it's doing mostly what it should; but I don't see it fixing anything. Thoughts? I noted this with the Standard from your config and also the 'WordPress' config option set as well.

gulp.task('phpcbf', function () {
  return gulp.src( phpSource)
  .pipe(phpcbf({
    bin: vendors+'composer/bin/phpcbf',
    standard: 'WordPress',
    warningSeverity: 0
  }))
  .on('error', gutil.log)
    .pipe( notify( { message: 'phpcs task complete', onLast: true } ) )
    // .pipe(gulp.dest('src'));
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.