Code Analysis Disable Rule for specific cases
it would be extremely useful to allow the user to disable a code analysis rule for specific cases and not just on a global scope.
cast(cast(0 as binary) pops up the issue BP008 (CAST/CONVERT to var types without length) which my be correct for certain cases but not always.
It would be very hand if I could tell the analyzer to not give any warning for this single line, perhaps by adding a pseudo comment like --##BP008 or similar.
This comment would temporarily disable the warning for this single line/case but not for the rest of a script.
Perfect would be, if I could add more than one pseudo comment to disable more than one code, e.g. --##BP008, BP007, BP006.
Tom Pester commented
Excellent suggestion as this keeps me from enabling the feature all the time.
The single line comment (in addition to a multiline comment) is much needed as well.
Otherwise you need to add 2 lines to disable a rule:
-- SQL Prompt BP008 off
-- SQL Prompt BP008 on
I miss this single line option to disable the formatting as prompt as well.
AdminMichael Clark (Admin, Redgate) commented
Related UserVoice (closed as duplicate)
Adrian Brough commented
I would find this useful to turn off BP018 "UPDATE Statement without WHERE or INNER JOIN clause" where I really do intend to update a whole table at once. At the moment I add "WHERE 1=1" which is rather contrived.
Thomas Rushton commented
There's at least one other uservoice on this.
Richard Moss commented
I like the idea of the UPDATE without WHERE warning - there has been a couple of disastrous times where I've missed out a WHERE and updated the wrong data.
However, SQL Prompts "one size fits all" option of on or off makes the feature useless. For example, I have multiple scripts that do UPDATES to clear out personal information from various tables, which I use when taking copies of customer databases for support purposes, be that hunting down a bug, or performance profiling.
Resharper lets your selectively disabled it's multitude of rules by adding comments in the source code, eg
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
This functionality is incredibly useful, and I have these annotations throughout my codebase to shut it up about individual cases while still having the rule running everywhere else.
I think this sort of functionality could be a good fit for SQL Prompt too, allowing me fine control over what statements such not be flagged as warnings, while having everything else flagged. Then I won't get annoyed when my support scripts are blocked, but I will get saved when I run a statement which is supposed to have a WHERE but I fumbled.