HaxeCheckstyle / haxe-checkstyle

Haxe Checkstyle
http://haxecheckstyle.github.io/docs
MIT License
124 stars 27 forks source link

`UnusedImport` false positive when enum abstract var is using #523

Open T1mL3arn opened 1 year ago

T1mL3arn commented 1 year ago

Example

// file BaseMenu.hx
package menu;

enum abstract MenuCommand(String) to String {
    var EXIT_GAME;
}

// file Main.hx
import menu.BaseMenu.MenuCommand;

var abc = '123';
switch (abc) {
  case EXIT_GAME:  trace('exit');
  default: 0;
}

gives UnusedImport - Unused import "menu.BaseMenu.MenuCommand" detected.

If I change case EXIT_GAME to case MenuCommand.EXIT_GAME there is no detection, so I guess checkstyle does not know EXIT_GAME is from MenuCommand (though in vscode really unused imports are grayed-out).

AlexHaxe commented 1 year ago

there's not much checkstyle can do here. vscode can gray out those imports because of languageserver - and diagnostics from Haxe compiler telling it to. checkstyle doesn't have that source of information. so it cannot make that connection.

your sample is also flawed, since you just assign a string to abc and then use it to switch over fields of an unrelated enum abstract. if you wanted to profit from exhaustiveness checks you would need to declare var abc:MenuCommand and then everything would be fine.