krdln / shelly

Shelly — very dumb PowerShell script analyzer
MIT License
3 stars 1 forks source link

Make shelly understand class-dependencies and how to import them #24

Open krdln opened 5 years ago

krdln commented 5 years ago

Consider:

A.ps1

class A {}

B.ps1

class B {
    [A] $Field
}

If B.ps1 would just dot-import A.ps1, it wouldn't work (because powershell parses classes before sourcing files). However, if there was:

C.ps1

. $PSScriptRoot/A.ps1
. $PSScriptRoot/B.ps1

both A and B would be happily imported. I've noticed such a pattern started occurring in the wild – A.ps1 and B.ps1 are never imported directly, but only through a C.ps1 "import wrapper". When using class A through such a wrapper, shelly currently does weird things:

I have no idea what to do about it. It would be nice to detect such a pattern, disable stupid warnings, and perhaps emit a lint if dependent class is used without a wrapper.

For now, I think I'm going to just disable indirect-imports and unused-imports on classes.

cc @m-kostrzewa @sodar

m-kostrzewa commented 5 years ago

yup, @sodar gave up when I showed him this :)

sodar commented 5 years ago

That puts it mildly.

krdln commented 5 years ago

@sodar @m-kostrzewa Can you verify if the current version is free of false warnings in winci?

m-kostrzewa commented 5 years ago

@krdln sure, tomorrow