pythonsublimetextsublimelinter

Make SublimeLinter show error codes


If I run flake8 at the terminal, it gives me alphanumeric error codes for every error - like F401 for an unused import:

$ flake8 ~/test.py
/Users/markamery/test.py:1:1: F401 'math' imported but unused

However, when I use SublimeLinter-flake8 to lint code in Sublime, these codes aren't included in the error message shown in the status bar:

Screenshot showing the message above in the Sublime status bar, but without an error code

How can I make the error codes appear in the status tray, like they do at the terminal?


Solution

  • SublimeLinter's settings file now contains a message template parameter which defaults to showing only the error message, documented as follows in the default settings file:

    // Show the messages for problems at your cursor position.
    // - {message} will be replaced by the actual messages.
    // - {linter} will be replaced by the linter reporting the error.
    // - {type} will be replaced by either warning or error.
    // - {code} will be replaced by the error code.
    // Set to "" to display nothing
    "statusbar.messages_template": "{message}",
    

    To show error codes, then, you need to:

    1. Open the SublimeLinter settings file. (On Sublime Text 3 on a Mac, I can access this via Sublime Text -> Preferences -> Package Settings -> Sublime Linter -> Settings; the menus will be slightly different in different environments.)

      Screenshot showing the menus above

    2. In the "User" settings in the right-hand-pane of the split window that opens, add a "statusbar.messages_template" parameter that contains a {code} placeholder. For example, I use "{type} {code}: {message}" as my template:

      Screenshot showing the following code in the SublimeLinter.sublime-settings - User file: <code>{"statusbar.messages_template": "{type} {code}: {message}"}</code>. Sorry, I can't format this sensibly within alt-text!

    3. Save, and the messages shown in the status bar by SublimeLinter will henceforth contain the error code:

      Status bar screenshot showing "flake8(1|0), warning F401: 'math' imported but unused, Line 1, Column 12