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

The imports are not sorted in alphabetical order within version

Open belka-ew opened this issue 5 years ago • 5 comments

$ cat dscanner.ini 
imports_sortedness="skip-unittest"
$ cat test.d                                                               
import c;

version (Windows)
{
    import e;
}
else
{
    import d;
}
$ ~/.dub/packages/dscanner-0.5.9/dscanner/bin/dscanner --styleCheck test.d 
test.d(9:12)[warn]: The imports are not sorted in alphabetical order

It is on Linux.

belka-ew avatar Aug 31 '18 05:08 belka-ew

A workaround is to write the else-version explicitely:

else version (Posix)

belka-ew avatar Aug 31 '18 05:08 belka-ew

It would be possible to skip the check when imports are found within a version but then everything in the current scope would be skipped i think. It's a matter of false positive VS false negative. Maybe @wilzbach you can handle this issue since you wrote the check IIRC ?

ghost avatar Aug 31 '18 10:08 ghost

I think every version-block should have its own scope, so I can put all platform-specific imports together.

This one doesn't produce a warning:

version (Windows)
{
}
else
{
    import d;
}
import c;

Only if there is a Windows import and it is > c an error occurres.

belka-ew avatar Aug 31 '18 10:08 belka-ew

Yes this would work. Technically version bodies are not scopes but a kind of scope can be pushed in the check.

ghost avatar Aug 31 '18 10:08 ghost

@BBasile I can have a look at it, but I will continue to be away from my workstation for at least another week. Sorry.

wilzbach avatar Sep 05 '18 01:09 wilzbach