tonybaloney / perflint

Python Linter for performance anti patterns
MIT License
666 stars 10 forks source link

Linter crashes when run via VS Code #19

Open debonte opened 2 years ago

debonte commented 2 years ago

Perflint works on the command line against the file below, but crashes when run via VS Code.

Here's the command line output:

>perflint src\CursesRenderer.py
************* Module CursesRenderer
src\CursesRenderer.py:57:46: W8201: Consider moving this expression outside of the loop. (loop-invariant-statement)

-----------------------------------
Your code has been rated at 9.75/10

And here's the output I see in the Python log when opening the file in VS Code:

> .\.venv\Scripts\python.exe ~\.vscode\extensions\ms-python.python-2022.5.10891003\pythonFiles\linter.py -m pylint --load-plugins perflint --rcfile ./.pylintrc .\src\CursesRenderer.py
cwd: .
> ./.venv/Scripts/activate.bat && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2022.5.10891003/pythonFiles/printEnvVariables.py
##########Linting Output - pylint##########

[ERROR 2022-2-30 15:2:44.986]: Linter 'pylint' failed to parse the output '. SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at s.parseMessages (c:\Users\erikd\.vscode\extensions\ms-python.python-2022.5.10891003\out\client\extension.js:2:526510)
    at s.run (c:\Users\erikd\.vscode\extensions\ms-python.python-2022.5.10891003\out\client\extension.js:2:507944)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at s.runLinter (c:\Users\erikd\.vscode\extensions\ms-python.python-2022.5.10891003\out\client\extension.js:2:526025)
import abc
import curses
from Engine import Game, Level, MapPoint, MapTileTypeHelper, UnitVector
from Keyboard import Keyboard

class Renderer(abc.ABC):
    def render(self, game: Game): ...

class CursesRenderer(Renderer, Keyboard):
    def __init__(self):
        self.console = curses.initscr()
        curses.curs_set(0)
        self.console.keypad(True)
        self.console.refresh()

    def render(self, game: Game):
        self._drawLevel(game.level)
        self.console.refresh()

    def readKey(self) -> str:
        return self.console.getch()

    def tryGetUnitVector(self, key: str) -> UnitVector | None:
        match key:
            case "7":
                return UnitVector.NW
            case curses.KEY_UP | "8":
                return UnitVector.N
            case "9":
                return UnitVector.NE
            case curses.KEY_RIGHT | "6":
                return UnitVector.E
            case "3":
                return UnitVector.SE
            case curses.KEY_DOWN | "2":
                return UnitVector.S
            case "1":
                return UnitVector.SW
            case curses.KEY_LEFT | "4":
                return UnitVector.W
            case _:
                return None

    def _drawLevel(self, level: Level):
        for pointAndTile in level.map.tiles:
            self._drawAt(MapTileTypeHelper.getGlyph(pointAndTile[1].type) if pointAndTile[1].isExplored else " ", pointAndTile[0])

        for obj in level.knownObjects:
            self._drawAt(obj.glyph, obj.position)

    def _drawAt(self, glyph: str, point: MapPoint):
        self.console.addch(point.y, point.x, glyph)

    def _drawLogString(self, logEntry: str):
        for i in range(0, self.console.width):
            charToRender = logEntry[i] if i < len(logEntry) else " "
            self._drawAt(charToRender, MapPoint(i, self.console.height - 1))