首页 > 解决方案 > 让 SublimeLinter 显示错误代码

问题描述

如果我flake8在终端运行,它会为每个错误提供字母数字错误代码 - 例如 F401 用于未使用的导入:

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

但是,当我在 Sublime 中使用SublimeLinter-flake8对代码进行 lint 时,这些代码不包含在状态栏中显示的错误消息中:

在 Sublime 状态栏中显示上述消息的屏幕截图,但没有错误代码

如何使错误代码出现在状态托盘中,就像它们在终端上一样?

标签: pythonsublimetextsublimelinter

解决方案


SublimeLinter 的设置文件现在包含一个消息模板参数,默认只显示错误消息,在默认设置文件中记录如下:

// 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}",

那么,要显示错误代码,您需要:

  1. 打开 SublimeLinter 设置文件。(在 Mac 上的 Sublime Text 3 上,我可以通过Sublime Text -> Preferences -> Package Settings -> Sublime Linter -> Settings访问它;菜单在不同的环境中会略有不同。)

    显示以上菜单的屏幕截图

  2. 在打开的拆分窗口右侧窗格的“用户”设置中,添加一个"statusbar.messages_template"包含{code}占位符的参数。例如,我使用"{type} {code}: {message}"我的模板:

    在 SublimeLinter.sublime-settings - 用户文件中显示以下代码的屏幕截图:<code>{

  3. 保存,SublimeLinter 在状态栏中显示的消息将包含错误代码:

    状态栏截图显示


推荐阅读