Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a code style enforcer?

I'm working with websites written in PHP, along with many other programmers, and sometimes I have to deal with really awful code.

Indentation totally messed up, curly braces in the wrong places, terrible whitespace use, it really hurts my eyes and actually makes my work harder and take longer.

Is there a tool where you can specify your coding style and then it applies it to files? I'm sure there must be such functions in different IDEs, but I need an independent tool as I code with simple notepads like Notepad++ or the like. ( if it's such a function in Notepad++, I didn't see it )

like image 817
Petruza Avatar asked Sep 02 '09 13:09

Petruza


People also ask

How do you enforce code styling in a project?

Use an EditorConfig file when you want to enforce coding styles for all contributors to your repo or project. You can manually populate your EditorConfig file, or you can automatically generate the file based on the code style settings you've chosen in the Visual Studio Options dialog box.

What is code cleanup C#?

"Code Cleanup is a new feature of Visual Studio 2019 that will automatically clean up your code file to make sure it is formatted correctly and that your coding style preferences are applied," the marketplace description says.

How do I change the format in Visual Studio?

To access this options page, choose Tools > Options from the menu bar. In the Options dialog box, choose Text Editor > C# > Code Style > Formatting.


2 Answers

Try PHP Code Sniffer.

That should be exactly what you are looking for(at least that's what I thought afert reading the heading, see the update).

UPDATE: Actually what Code Sniffer does is go through your code and detect coding style violations, it does not however fix the problems.

But by telling you what's wrong it enforces you to adhere to a certain coding style. So that might be an option for you in the future.

like image 61
André Hoffmann Avatar answered Oct 08 '22 09:10

André Hoffmann


While I have never used any, as I (luckly?) don't use anyone else code much, google found this, PHP Beautifier.

EDIT
See this question which recommends PHP Code Beautifier which is free (but requires an account creation)

like image 34
Yacoby Avatar answered Oct 08 '22 08:10

Yacoby