We are using git for our source control. Team members either use eclipse, atom, notepad++, or IDEA for development. There is the occasional visual studio development but it is often. We use a variety of languages, HTML, CSS, JavaScript, Java, etc.

My question is how can I make sure that code is always formatted the same no matter what development tool the engineer uses? Is there a git hook that will format the incoming code? I want to be able to specify the file so if there is a plugin or way to create a global manifest file that will hold all the requirements and they can just load the file that would be great also. The reason that I don't want to leave it to the engineer is because we do make changes and hire new people and having to go through and make sure everything is configured correctly is time consuming and often something is missed. Anyone have a solution to this?

  • 1
    It sounds restrictive at first, but I prefer to use the same IDE (and other tools) across the entire team. Same directory structure too. (in fact, coding style is not my major issue, although I do like to have a general agreement (naming conventions are fine, but who cares about The One True Brace Style?)). This allows any team member to sit at the desk of any other and quickly help him check or change his code. Choice of which IDE is best left to a vote, proponents explain why theirs is best & then the team votes & chooses. – Mawg says reinstate Monica Jan 19 '15 at 16:04
  • Are you willing to consider using a prettyprinter for each langauge, that cannot break the code? You might have to script the checkin to run the prettyprinter first, but that just means you have a required check-in script. – Ira Baxter Apr 17 '16 at 4:07

One trick that you can use is to have a git hook to run lint, or it's equivalent for other languages, and reject the code with clear error messages if it doesn't meet the requirements. While the lint family of tools try to locate errors by static analysis there are also style rules that you can enable and/or customise in most of them - there are a long list of such tools depending on budget, etc.

Another possibility is to use Review Board and check code is as expected at the commit stage, (see the FAQ for git usage).

Note that either or both of the above will tend to result in much better code as well as prettier code due to the other checks in addition to the stylistic ones - the other bit of good news is that your programmers will, hopefully, start to code in a compliant manner to start with after they have been through a few cycles "of this is wrong fix it" whereas any automatic code prettifier risks introducing bugs and since the code that is committed no longer matches the code that was committed will tend to annoy some even more than having issues pointed out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.