Toad World® Forums

Code Analysis add rule that check the code format is done


#1

Hello everybody,

I’m using Toad 12.10 with the check code analysis before check in into repository, and I’ll like to be able to avoid check in if the plsql code is not formated using the TOAD format code.

What the best approach ?

I think about to create a rule that check the package code contains in the first line the comment like “/* Formatted on %” , is it possible to do that?

Or is there the possibility to auto format the code before to check in?

Kind regards,

Sébastien.


#2

Hello,

It seems difficult to answer this question, maybe have you documentation about the Xpath expression used to construct rules?

Thank you very much.

Sébastien.


#3

Hi Sébastien,

Sorry for the delayed response. There’s currently no way to auto format the code before check-in in Toad 12.10. And unfortunately, there’s no good way to create a rule to check to see if source has been formatted in Code Analysis. There are a few reasons for this:

  • Format comments are parsed as separate chunks from the DDL, so there’s no way from a machine-readable standpoint to determine if a format comment was applied to a single object or multiple objects in a script. If we assumed based on the comment header, there’d also be a simplistic way to circumvent the check by manually adding a “/* Formatted on today by me */” comment.
  • Formatter tag lines are not compiled as part of the object, which is what Team Coding pulls in order to send to the version control provider.
  • Formatter settings are user-specific. There’s no way to define a standard format settings on a team level, so it’s possible to have objects formatted differently depending on who modifies them.
  • Formatter tag lines can be easily disabled as an option, so it wouldn’t be a reliable indication of formatted code.
    That being said, there is a set of new options in Toad 13 (soon to be released) to define how DDL is extracted from the database in Team Coding when sending files to the version control provider. In those DDL options, you can choose to format PL/SQL code. By setting those options, all PL/SQL code will be formatted before being sent to the version control provider. You’ll need to make sure that all members of your team share the same formatting options for consistency, and it won’t force formatting before compilation into the database, but it will format them before checking them into the VCS.

Let us know if that will work for what you’re trying to accomplish,

-John


#4

Hello John,

thank you for your answer, I’ll take a look at toad 13 when released.

Kind Regards,

Sébastien.