xbuzz / plugin-php

Prettier PHP Plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🚧 Work in Progress! 🚧

Prettier PHP

Prettier PHP Plugin

Gitter Travis npm version code style: prettier Follow+Prettier+on+Twitter

WORK IN PROGRESS

Please note that this plugin is currently in alpha stage and still under active development. We encourage everyone to try it and give feedback, but we don't recommend it for production use yet.

Intro

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

This plugin adds support for the PHP language to Prettier.

Input

array_map(function($arg1,$arg2) use ( $var1, $var2 ) {
    return $arg1+$arg2/($var+$var2);
}, array("complex"=>"code","with"=>"inconsistent","formatting"=>"is", "hard" => "to", "maintain"=>true));

Output

array_map(
    function ($arg1, $arg2) use ($var1, $var2) {
        return $arg1 + $arg2 / ($var + $var2);
    },
    array(
        "complex" => "code",
        "with" => "inconsistent",
        "formatting" => "is",
        "hard" => "to",
        "maintain" => true
    )
);

Install

Currently, the plugin can only be installed locally, due to an issue in Prettier's plugin system.

yarn:

yarn add --dev prettier/prettier prettier/plugin-php

npm:

npm install --save-dev prettier/prettier prettier/plugin-php

Use

You can add Prettier as a script in your package.json,

"scripts": {
  "prettier": "prettier"
}

and then run it via

yarn run prettier path/to/file.php --write
# or
npm run prettier path/to/file.php --write

Contributing

If you're interested in contributing to the development of Prettier for PHP, you can follow the CONTRIBUTING guide from Prettier, as it all applies to this repository too.

To test it out on a PHP file:

  • Clone this repository.
  • Run yarn.
  • Create a file called test.php.
  • Run yarn prettier test.php to check the output.

Maintainers


Mike Grip

Christian Zosel

Evilebot Tnawi

About

Prettier PHP Plugin

License:MIT License


Languages

Language:JavaScript 55.9%Language:PHP 44.1%