How to Set Up SublimeLinter for Python Coding?

Estimated read time 3 min read

SublimeLinter is a plugin for the Sublime Text editor that provides linting capabilities for various programming languages, including Python. Here’s how to set up SublimeLinter for Python coding:

  1. Install SublimeLinter: Open Sublime Text and go to the Package Control command palette (Ctrl+Shift+P or Cmd+Shift+P on Mac). Type “Package Control: Install Package” and press Enter. Search for “SublimeLinter” and select it to install the package.
  2. Install a Python linter: SublimeLinter doesn’t come with a built-in Python linter, so you need to install a separate package for Python linting. There are several options available, but the most popular ones are pylint and flake8. To install pylint, go to the Package Control command palette again, type “Package Control: Install Package” and select “SublimeLinter-pylint”. To install flake8, select “SublimeLinter-flake8” instead.
  3. Configure the linter: Once you’ve installed the Python linter, you need to configure it to work with SublimeLinter. Open a Python file in Sublime Text and go to the SublimeLinter command palette (Ctrl+Shift+P or Cmd+Shift+P on Mac). Type “SublimeLinter: Open User Settings” and press Enter. This will open the SublimeLinter user settings file in a new tab.
  4. Add the linter configuration: In the user settings file, add a new section for the Python linter you installed (either pylint or flake8). Here’s an example configuration for pylint:
"linters": {
    "pylint": {
        "executable": "pylint",
        "args": ["--output-format", "parseable"],
        "disable": ["C0103"],
        "selector": "source.python"
    }
},

In this configuration, we specify the pylint executable, some arguments to pass to it (--output-format parseable), and a list of disabled error codes (C0103, which disables the “invalid-name” error). We also specify that this configuration should apply to Python source code (selector source.python).

If you’re using flake8, the configuration will look slightly different. Here’s an example:

"linters": {
    "flake8": {
        "executable": "flake8",
        "args": ["--ignore=E501"],
        "disable": [],
        "selector": "source.python"
    }
},

In this configuration, we specify the flake8 executable, some arguments to pass to it (--ignore E501, which ignores the “line too long” error), and an empty list of disabled error codes. We also specify that this configuration should apply to Python source code.

  1. Save the configuration: Save the user settings file and close it. SublimeLinter will automatically apply the new configuration to any Python files you open in Sublime Text.

With SublimeLinter set up, you can now see linting errors and warnings in your Python code as you write it. The errors will be highlighted in the editor, and you can view details about each error in the SublimeLinter tooltip by hovering over the highlighted text.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply