Is there a TFS check in a policy that automatically formats the code for you?

It’s possible that what I’m looking for does not exist, but I heard rumors that in TFS you can configure some way to automatically format / style the source code when checking. So far in the study that I did, it looks like the "Policy Check" simply sends alerts if the checkbox is checked ... Is there a way that the code can be auto-formatted during registration, or is that just a desirable thinking? Could you provide / link to examples.

+5
source share
2 answers

These are actually not direct answers, but they can help someone:

For many languages, you can enable automatic formatting as you type in Visual Studio (Tools> Options> Text Editor> {language}> Formatting), so it shouldn't be too hard to have the code in order before you can check.

You can also format the document on demand using Edit> Advanced> Document Format, so you can always do this immediately before checking (although you will have to reopen any pending changes)

As a rule, it’s pretty fast / easy to keep the code in order (especially with the above). If you hang yourself too much on “perfect” formatting, you will find that you spend a lot of time indenting and layout instead of doing useful work — and you will be annoyed by “broken” formatting when you return to the same code several times weeks later, just to find that what you thought was perfect still had some glitches in it or that your personal coding style deviated slightly. This behavior can even lead to a battle for style with others when you try to work in a team, which can become a serious destructive activity. Thus, there is value in learning when “good enough is enough” and do not waste energy trying to achieve perfection.

Finally, it would be very easy to write code that sat on the TFS event and handled all the checks to ensure the encoding layout style. But then again, if you feel that the amount of effort is required / justified, you are likely to have some fun in your text layout and can benefit from focusing more on writing good code that supports the code than on making it looked beautiful. The compiler doesn’t care, since the code is read to you and your team members, it is probably good enough.

0
source

On my team, we have implemented a registration policy that runs AStyle.exe throughout the code before registration, you can download AStyle from sourceforge. Yes, we are the ones who, like all the code in projects, have the same formatting and style, and yes, this is easy to do with shortcuts in VS. The advantage of performing a style over registration is that when comparing versions of the same file, the format has not changed depending on the developer who completed the registration.

0
source

Source: https://habr.com/ru/post/1210590/


All Articles