selene icon indicating copy to clipboard operation
selene copied to clipboard

Feature request: add support for detecting invalid types

Open cassis163 opened this issue 4 years ago • 1 comments

Correct me if I am wrong, but it seems like every type is allowed. This code

local partInformationItem: nonsense = PartInformation:new(part)

is allowed, eventhough 'nonsense' is not a defined and valid type.

cassis163 avatar May 01 '21 07:05 cassis163

selene parses typed syntax, but completely ignores them in all lints. This is because creating a real type checker, or even just any form of type inference, is a hugely complicated problem that is far out of scope for selene.

That being said, I warily deem this within scope, since no inference or knowledge of types is actually required here. However, it is not totally trivial:

  1. The roblox standard library, or some external source, is going to have to keep a list of all possible types, to support natives.
  2. It will be unable to tell anything through imports, as selene is per file. This means that if you do local thing: Something.nonsense, selene will not attempt to see if it is wrong, assuming Something is a declared variable and not a native type.
  3. If there's any way to get a global type without requiring it (such as a .d.ts file), then this lint can't exist, as it will not be feasible for selene to get that information, and selene, as a general rule, can never be wrong.

Kampfkarren avatar May 01 '21 09:05 Kampfkarren