Linter Python for Sublime

For a better code, in your IDE or editor, you can add a Linter who highlight your mistakes. Sublime has one by default, but it is limited. You can add another one, more powerfull !

For Python, PyLint exists !

Install

You can simply type :

 

sudo pip install pylint
// or
sudo apt-get install pylint

There is some dependencies

The following extra packages will be installed:
python-astroid python-logilab-common
Suggested packages:
pyro
The following NEW packages will be installed:
pylint python-astroid python-logilab-common
0 upgraded, 3 newly installed, 0 to remove and 114 not upgraded.
Need to get 565 kB of archives.
After this operation, 7.811 kB of additional disk space will be used.

Config

Please use Package Control to install the linter plugin. This will ensure that the plugin will be updated when new versions are available. If you want to install from source so you can modify the source code, you probably know what you are doing so we won’t cover that here.

To install via Package Control, do the following:

  1. Within Sublime Text, bring up the Command Palette and type install. Among the commands you should see Package Control: Install Package. If that command is not highlighted, use the keyboard or mouse to select it. There will be a pause of a few seconds while Package Control fetches the list of available plugins.
  2. When the plugin list appears, type pylint. Among the entries you should see SublimeLinter-pylint. If that entry is not highlighted, use the keyboard or mouse to select it.

Open a Python file : OMG, everything is highlighted !!! My eyes are bleeding !!

Now, you can set up your linter ; for example, disabled some mistake (that you don’t care). Go to Preferences > Package Settings > PyLinter > Settings – Default (on Linux). A JSON dict open. In the ‘disable’ entry, you can add the code of the error you don’t want to see.

"disable": [
"C0103", // Invalid name convention
"C0301", // Too Long line
"C0111", // Missing docstring (documentation for all method)
"E1101", // %s %r has no %r member
"F0401", // Unable to import %s
"R0201", // Method could be a function
"W0232", // Class has no __init__ method
"W0212", // Access to a protected member %s of a client class
],

Tips : comment each error code, it could be easier !

Usefull links
  • https://sublime.wbond.net/packages/SublimeLinter-pylint
  • https://github.com/SublimeLinter/SublimeLinter-for-ST2
  • http://sublimelinter.readthedocs.org/en/latest/settings.html
  • http://pylint-messages.wikidot.com/all-codes