Linux automated code formatting (PHP, JavaScript,

2019-07-06 17:07发布

问题:

I am seeking a Linux or PHP program to automate code formatting. Optimally it would handle many languages, but the priority is (highest first): PHP, JavaScript, HTML, CSS and MySQL. Comparability is nice, but not the most important feature.

Context / use: automation via Subversion post-commit. I'm working with teams and want to always follow a single method of formatting.

回答1:

Astyle is the canonical answer if you insist on just one.

You likely cannot get a single formatter for many langauges that understands their syntax, and you can't afford to get the syntax wrong, because you don't want the formatter to break code (especially after it has just been checked in!) [Astyle works on several because it accepts only C-like langauges]. See Semantic Designs Formatters for such tools for many langauges that do understand syntax accurately and can't make such mistakes.



回答2:

Check out Geany. It is in the Ubuntu repos and its the best PHP IDE I've used yet.

EDIT: 8 year update: try VS Code. Its my main IDE for most everything these days.



回答3:

I find that using an IDE such as Eclipse or Aptana will accomplish this task very easily. It's not automated but if all developers use an IDE this is very simple