简体   繁体   English

PHP和Javascript的命令行格式化程序

[英]Command line formatter for PHP and Javascript

是否有任何命令行(非交互式,而非基于Web)的工具将重新格式化(漂亮)PHP和Javascript代码?

For a PHP beautifier, you can also use this pear package PHP_Beautyfier , which can either be called from the command line or instantiated within your own PHP code. 对于PHP美化器,您也可以使用这个梨包PHP_Beautyfier ,它可以从命令行调用 ,也可以在您自己的PHP代码中实例化。 For the Javascript one instead, find an open discussion here 对于Javascript而言,请在此处找到公开讨论

PHP_ Beautifier is very outdated! PHP_ Beautifier非常过时! For a more modern approach try php-cs-fixer 对于更现代的方法,请尝试使用php-cs-fixer

Example command: php-cs-fixer fix --rules=@PSR2 path/to/php/src 示例命令: php-cs-fixer fix --rules=@PSR2 path/to/php/src

A second alternative is PHP_CodeSniffer 第二种选择是PHP_CodeSniffer

Example command: phpcbf --standard=PSR2 path/to/php/src 示例命令: phpcbf --standard=PSR2 path/to/php/src

I wrote an article explaining how to build a command-line JavaScript beautifier implemented in JavaScript . 我写了一篇文章,解释了如何构建一个用JavaScript实现命令行JavaScript美化器 The best part - it takes under 5 minutes to do it, YMMV. 最好的部分 - 它需要不到5分钟,YMMV。

Cheers! 干杯!
Shonzilla Shonzilla

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM