Disabling warnings in D-Scanner: looking for suggestions

WebFreak001 d.forum at webfreak.org
Tue Mar 24 21:58:43 UTC 2020


a few comments about your linter fixes:

On Tuesday, 24 March 2020 at 21:03:22 UTC, Dennis wrote:
> I know code-d supports the `// stfu` comment, which is almost 
> as simple and unobtrusive as it gets, but even then I don't 
> like the idea of someone else reading my code and wondering 
> where those random profanities come from.

well this is actually just supposed to be an easter egg :)

>> Line longer than 120 characters
>
> Split up the line.

sometimes this isn't possible very well (like long embedded 
strings)

>> Variable name does not match style guidelines
>
> Change the capitalization. You can make an alias to the symbol 
> with the original capitalization since aliases don't have a 
> style rule.

often this happens when you explicitly make something not match 
style guidelines (UDA struct, ABI/mangling compatibility for some 
binding, etc)

> There are a few warnings that can't easily be solved however, 
> like the 'dscanner.suspicious.unmodified' you mentioned.
> ```
> int x; // dscanner says: 'could be declared const'
> increment(x); // but this function takes arguments by ref!
> x += 0; // so should I just do some bogus 'modification'?
> ```
>
> Ideally, I would like to the language to support `increment(ref 
> x)` on the call site (similar to what you suggest:
> https://forum.dlang.org/thread/dhiwpttqeaxctdzczxlb@forum.dlang.org).
> Though we can't count on that.

Yep repeatedly falling into this one, really sucks.

> My most hated warning is:
>
>> Avoid subtracting from '.length' as it may be unsigned.
>
> Sometimes you can rewrite e.g. (x < a.length-1) to (x + 1 < 
> a.length), but other times there's simply no way around this, 
> and I need to access element `a.length-1`, and Dscanner can't 
> see it's in side an `if (a.length > 0)` block.

here is a "fix": a.length + -1

> Regarding your suggestions:
>
>> more fully featured comments to disable
>
> I don't know what 'fully featured' means. Can you elaborate 
> this one?

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.

We would need to specify all the possibilities what the dscanner 
lint ignores could do then (like if it should be possible to add 
some special comment before a block to disable a warning for the 
entire block body)



More information about the Digitalmars-d mailing list