D-Scanner icon indicating copy to clipboard operation
D-Scanner copied to clipboard

Warn about accessing private members in documented `unittest`s

Open Bolpat opened this issue 2 years ago • 3 comments

This was suggested to me by @Geod24 in https://issues.dlang.org/show_bug.cgi?id=21462

A unit test should not be accessing private members when it is documented; the same sequence of instructions won’t compile for a user of the module. If the documentation comment for the unit test starts with Private. (case insensitive) or is ditto and the referred documentation starts with Private., the warning is suppressed.

Bolpat avatar Feb 22 '23 14:02 Bolpat

Actually, I'll add one condition: If the documented unittest is for a private symbol, no warning should be emitted.

Geod24 avatar Feb 22 '23 15:02 Geod24

If you like this, it can be extended to protected and/or package symbols. I’d strongly suggest to include protected with Protected. as the documentation keyword to mark this as intentional. Package is probably harder because package visibility can be qualified, and while it’s pretty clear what Private and Protected as part of the unit test documentation means, Package isn’t as clear.

Bolpat avatar Feb 23 '23 09:02 Bolpat

I would not extend it to protected. Remember we want to minimize the amount of boilerplate here. protected is, to some extent, closer to public than to private (if the class is public). Let's start with private and see how well it works first.

Geod24 avatar Feb 23 '23 09:02 Geod24