53
We would like to have a possibility that gives you the oppurtinity to suppress a CodeCop warning per line.

Why? Here is an example:
We got a warning "Possible overflow assigning 'Text' to 'Text[50]'.AL(AA0139)". Usually, this warning is correct and should be resolved, but we have a case where we want to cancel the transaction by an error.

There are two ways:
1. Assign the value, that is too long for the variable, and maybe throw the default NAV/BC overflow error (not resolving the warning).
2. Check if the value is too long and throw an own error. Otherwise use "copystr" too assign the value and suppress the warning.

We would like to use the first approach because we do not want to write another error that is almost the same. But if we are followin the first approach, the codeline is underlined in yellow and the whole file is marked that there are warnings in it.

Solution:
Something like a //ignore-Tag in the line that should be not checked would be helpful.
Category: Development
STATUS DETAILS
Completed
Ideas Administrator

Thank you for your valuable feedback. We have decided to deliver this idea and make it available with Business Central 2020 Wave 2 (fall).

There will be two ways to suppress warnings:
  • Per line(s): New pragma directive to instruct compiler to ignore warnings in marked area. Can surround a continuous section of lines in a file. Use "#pragma warning disable <list of warning IDs>" and remember ending pragma (otherwise rest of file) with #pragma warning restore <ID>. Restore returns it to whatever global suppression state there is.
  • Per app: New app.json property, supports a list of warning IDs, e.g., "suppressWarnings": ["<Warning ID>","<Warning ID2>"]
Remember that most warnings are there for a reason, and suppressing them could lead to sudden impact if warnings are changed to errors (such as obsoletes).

Your help was greatly appreciated,  
Peter Borring
PM, Microsoft