Disabling warnings in D-Scanner: looking for suggestions

CodeMyst codemyst at outlook.com
Wed Mar 25 11:50:14 UTC 2020


On Wednesday, 25 March 2020 at 00:26:01 UTC, Dennis wrote:
> On Tuesday, 24 March 2020 at 21:58:43 UTC, WebFreak001 wrote:
>> sometimes this isn't possible very well (like long embedded 
>> strings)
>
> You can split those string literals up and concatenate with ~, 
> though you do lose the convenience of a single embedded string 
> literal.
>
>> often this happens when you explicitly make something not 
>> match style guidelines (UDA struct, ABI/mangling compatibility 
>> for some binding, etc)
>
> Yes, that's when I run into this warning too.
>
>> here is a "fix": a.length + -1
>
> That's... actually not that bad, thanks! It doesn't really 
> express "I know this is unsigned, but it can't underflow" but 
> if it pleases D-Scanner, I might take it. :p
>
>> for example PC-Lint includes some syntax like
>> //lint e715    // disable "'argument' not referenced " for 
>> entire module
>> //lint +e715    // enable "'argument' not referenced" again 
>> for module
>> //lint --e(715)    // disable 'argument' not referenced once
>>
>> however they have extremely complicated additional syntax too, 
>> but it's hard to look up this stuff.
>
> If you sell it like that, it's an obvious no for me. Upon 
> encountering 'lint e715' it's not only unknown what kind of 
> warning the code 'e715' refers to, but 'lint' doesn't tell me 
> what reference I should use either.
>
> Of course D-Scanner can do something elaborate better, but I 
> think suppressing warnings should be super simple. Maybe even 
> something as simple as `// stfu`, but then something like `// 
> warning: text explaining the warning` that binds to a 
> declaration / statement using the same rules as Ddoc. D-Scanner 
> only looks for the 'warning:' part, and from context or the 
> explanation text it becomes clear what the raised warning would 
> be.
>
> You could mass-disable bindings in a module like this:
>
> ```
> // warning: bindings do not adhere to D-style and are 
> undocumented
> module my.windows.bindings;
> ```
>
> This scheme has a risk that a comment like this:
>
>> warning: does not match style guide because it's a UDA
>
> Would also suppress a valid 'missing documentation for public 
> symbol' warning.
> And disabling all warnings for an entire module is blunt; some 
> users _will_ request a way to have granular control over it. I 
> don't think you can escape that. But I won't be one of those 
> users, so I don't have much to say there.
>
> I hope some other people respond to this thread, it's pretty 
> quiet so far. Maybe few users actually use D scanner?

I'm mostly in favour of simple `// @suppress` comments. You 
talked about it cluttering up code and making it ugly which is 
true, but this shouldn't even be used that often since there are 
few cases where you will want to suppress warnings. And about the 
use of multiple linters, is there even another linter for D 
available?

And the warning comments with an explanation have an issue like 
you mentioned that they will mute every warning on a line, even 
the ones you would like to have, with the simpler suppress 
comments you could have:

```
// warning is suppressed here because of blahblah
int a = 5; // @suppress(dscanner.suspicious.unmodified)
foo(a);
```

It does look a bit ugly, but you're doing something against 
standards so it should catch your eye I guess...

And muting warnings for the whole module could be done by adding 
a `// @suppress(dscanner)` on the module declaration.


More information about the Digitalmars-d mailing list