• Stars
    star
    235
  • Rank 171,079 (Top 4 %)
  • Language
    Python
  • Created about 12 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sublime Text plugin for lint Python files

Python Flake8 Lint

⚠️ IMPORTANT NOTE: unfortunately, I have no time now to maintain this project. I am really sorry. Please, contact me if you want to be a maintaner or use another plugins like SublimeLinter-flake8.

Python Flake8 Lint is a Sublime Text 2/3 plugin for check Python files against some of the style conventions in PEP8, pydocstyle, PyFlakes, mccabe, pep8-naming, flake8-debugger and flake8-import-order.

Based on bitbucket.org/tarek/flake8.

Lint tools

Flake8 (used in "Python Flake8 Lint") is a wrapper around these tools:

  • pep8 is a tool to check your Python code against some of the style conventions in PEP8.

  • PyFlakes checks only for logical errors in programs; it does not perform any check on style.

  • mccabe is a code complexity checker. It is quite useful to detect over-complex code. According to McCabe, anything that goes beyond 10 is too complex. See Cyclomatic_complexity.

There are additional tools used to lint Python files:

  • pydocstyle is a static analysis tool for checking compliance with Python PEP257.

  • pep8-naming is a naming convention checker for Python.

  • flake8-debugger is a flake8 debug statement checker.

  • flake8-import-order is a flake8 plugin that checks import order in the fashion of the Google Python Style Guide (turned off by default).

Install

With the Package Control plug-in: The easiest way to install Python Flake8 Lint is through Package Control, which can be found at this site: http://wbond.net/sublime_packages/package_control

Once you install Package Control, restart Sublime Text and bring up the Command Palette (Command+Shift+P on OS X, Control+Shift+P on Linux/Windows). Select "Package Control: Install Package", wait while Package Control fetches the latest package list, then select Python Flake8 Lint when the list appears. The advantage of using this method is that Package Control will automatically keep Python Flake8 Lint up to date with the latest version.

Manual installation: Download the latest source from GitHub, unzip it and rename the folder to "Python Flake8 Lint". Put this folder into your Sublime Text "Packages" directory.

Or clone the repository to your Sublime Text "Packages" directory:

git clone git://github.com/dreadatour/Flake8Lint.git "Python Flake8 Lint"

The "Packages" directory is located at:

  • Sublime Text 2
    • OS X: ~/Library/Application Support/Sublime Text 2/Packages/
    • Linux: ~/.config/sublime-text-2/Packages/
    • Windows: %APPDATA%/Sublime Text 2/Packages/
  • Sublime Text 3
    • OS X: ~/Library/Application Support/Sublime Text 3/Packages/
    • Linux: ~/.config/sublime-text-3/Packages/
    • Windows: %APPDATA%/Sublime Text 3/Packages/

Plugin config

Default "Python Flake8 Lint" plugin config: Preferences->Package Settings->Python Flake8 Lint->Settings - Default

{
	// run flake8 lint on file saving
	"lint_on_save": true,
	// run flake8 lint on file loading
	"lint_on_load": false,

	// run lint in live mode: lint file (without popup) every XXX ms
	// please, be careful: this may cause performance issues on ST2
	"live_mode": false,
	// set live mode lint delay, in milliseconds
	"live_mode_lint_delay": 1000,

	// set ruler guide based on max line length setting
	"set_ruler_guide": false,

	// popup a dialog of detected conditions?
	"popup": true,
	// highlight detected conditions?
	"highlight": true,

	// highlight type:
	// - "line" to highlight whole line
	// - "error" to highlight error only
	"highlight_type": "error",

	// color values to highlight detected conditions
	"highlight_color_critical": "#981600",
	"highlight_color_error": "#DA2000",
	"highlight_color_warning": "#EDBA00",

	// show a mark in the gutter on all lines with errors/warnings:
	// - "dot", "circle" or "bookmark" to show marks
	// - "theme-alpha", "theme-bright", "theme-dark", "theme-hard" or "theme-simple" to show icon marks
	// - "" (empty string) to do not show marks
	"gutter_marks": "theme-simple",

	// report successfull (passed) lint
	"report_on_success": false,

    // blink gutter marks on success (will not blink with live mode check)
    // this icon is not depends on 'gutter_marks' settings
    // please, be careful: this may cause performance issues on ST2
    "blink_gutter_marks_on_success": true,

	// load global flake8 config ("~/.config/flake8")
	"use_flake8_global_config": true,
	// load per-project config (i.e. "tox.ini", "setup.cfg" and ".pep8" files)
	"use_flake8_project_config": true,

	// set python interpreter (lint files for python >= 2.7):
	// - 'internal' for use internal Sublime Text interpreter (2.6)
	// - 'auto' for search default system python interpreter (default value)
	// - absolute path to python interpreter for define another one
	//   use platform specific notation, i.e. "C:\\Anaconda\\envs\\py33\\python.exe"
	//   for Windows or then "/home/whatever/pythondist/python" for Unix
	"python_interpreter": "auto",

	// list of python built-in functions (like '_')
	"builtins": [],

	// turn on pyflakes error lint
	"pyflakes": true,
	// turn on pep8 error lint
	"pep8": true,
	// turn on pydocstyle error lint
	"pydocstyle": true,
	// turn on naming error lint
	"naming": true,
	// turn on debugger error lint
	"debugger": true,
	// turn on import order error lint
	"import-order": false,
	// import order style: "cryptography" or "google"
	// See also: https://github.com/public/flake8-import-order#configuration
	"import-order-style": "cryptography",
	// turn off complexity check (set number > 0 to check complexity level)
	"complexity": -1,

	// set desired max line length
	"pep8_max_line_length": 79,

	// select errors and warnings (e.g. ["E", "W6"])
	"select": [],
	// skip errors and warnings (e.g. ["E303", "E4", "W"])
	"ignore": [],

	// files to ignore, for example: ["*.mako", "test*.py"]
	"ignore_files": []
}

To change default settings, go to Preferences->Package Settings->Python Flake8 Lint->Settings - User and paste default config to the opened file and make your changes.

Flake8 config

"Python Flake8 Lint" plugin will load config in this order:

  1. ST plugin global settings.
  2. ST plugin user settings.
  3. ST project settings.
  4. Global flake8 settings (see also: Flake8 docs: global config):
    • ~/.config/flake8
  5. Flake8 project settings (see also: Flake8 docs: per-project config):
    • tox.ini
    • setup.cfg
    • .pep8

All settings are inherited, e.g. you can define only one setting in project config file, all other will be inherited from plugin config. If one of the options (e.g. 'ignore' param) will be defined in several config files, only last one will be taken.

There are few "Python Flake8 Lint" plugin options to control flake8 configs:

  • "use_flake8_global_config" option is used to enable or disable global flake8 config (i.e. "~/.config/flake8" file)
  • "use_flake8_project_config" option is used to enable or disable local (project) config (i.e. "tox.ini", "setup.cfg" and ".pep8" files)

Project Flake8 config

You could define per-project config for "Python Flake8 Lint". Use Project->Edit Project menu and add the flake8lint section in settings as shown below:

{
	"folders":
	[
		{
			"path": "/path/to/project"
		}
	],
	"settings": {
		"flake8lint": {
			"python_interpreter": "auto",
			"builtins": [],
			"pyflakes": true,
			"pep8": true,
			"pydocstyle": true,
			"naming": true,
			"import-order": true,
			"import-order-style": "google",
			"complexity": -1,
			"pep8_max_line_length": 79,
			"select": [],
			"ignore": [],
			"ignore_files": []
		}
	}
}

Note 1

Pep8 ignores "E121", "E123", "E126", "E226", "E24" and "E704" errors by default. This plugin will not ignore them.

If you're not agree with this plugin, please, add next string in your config:

"ignore": ["E121", "E123", "E126", "E226", "E24", "E704"]

Note 2

Pydocstyle's errors "D203 1 blank line required before class docstring" and "D211 No blank lines allowed before class docstring" are in conflict with each other. By default error "D203" is disabled. If you want to ignore "D203" error and use old-style class docstring ("D211"), add next string in your config:

"ignore": ["D203"]

More info about old-style and new-style class docstrings:

Features / Usage

Automatically check Python files with flake8 lint tool and show window with error list:

Error list

And move to error line/char on select.

Use these keys (by default) to run lint:

  • OS X: Ctrl+Super+8
  • Linux: Ctrl+Alt+8
  • Windows: Ctrl+Alt+Shift+8

Use these keys (by default) to jump to next lint error:

  • OS X: Ctrl+Super+9
  • Linux: Ctrl+Alt+9
  • Windows: Ctrl+Alt+Shift+9

Use these keys (by default) to disable current file linting:

  • OS X: Ctrl+Super+0
  • Linux: Ctrl+Alt+0
  • Windows: Ctrl+Alt+Shift+0

Commands list

More Repositories

1

dotfiles

dotfiles
Vim Script
80
star
2

pidgin-mra

Mail.ru Agent protocol plugin for Pidgin IM
C
42
star
3

sentry-statsd

A Sentry extension which send errors stats to StatsD
Python
24
star
4

rxvt-tabbed-new

New tabs perl plugin for rxvt-unicode.
21
star
5

mefodica-birmana

Раскладка для Mac OS X, основанная на раскладках «Мефодица» Лебедева и «Типографской раскладке» Бирмана
19
star
6

lazy

Lazy token
Python
18
star
7

Pep8Lint

Sublime Text 2 plugin / check Python files against some of the style conventions in PEP8
Python
16
star
8

RPMSpec

RPM Spec files syntax definition for Sublime Text 2
14
star
9

tarantool-locksmith

Locksmith: locks implementation for Tarantool
Lua
9
star
10

go-cli-template

Go command line templates
Go
6
star
11

alfred-adium-workflow

Alfred 2 Workflow - Adium contact search
5
star
12

mrad

Mail.Ru Agent Daemon
C
4
star
13

graylog2-specs

GrayLog2 SPECS for CentOS
D
3
star
14

weather

weather monitor
Perl
3
star
15

pidgin-hide-menu

Pidgin IM plugin for hide menubar by keypress
C
3
star
16

scrst

Аплоад скриншотов в Amazon S3 и красивое отображение их на странице.
Python
3
star
17

django-fest

django-fest
Python
2
star
18

tarantool-locksmith-python

Python bindings for Tarantool locksmith script
Python
1
star
19

tarantool-deque

Tarantool 1.6 delayed queue
Lua
1
star
20

gossip

Log files proccessing
Python
1
star
21

SublimeTabSwitcher

Tab Switcher plugin for Sublime Text 3
JavaScript
1
star
22

adium-find

Find Adium contact and open chat window.
Objective-C
1
star
23

tarantool-deque-python

Python bindings for Tarantool 1.6 delayed queue
Python
1
star
24

Serpentarium

Sublime Text 2 plugin / python + ctags
Python
1
star
25

mailru-session-manager

Manage mail.ru sessions for Firefox
JavaScript
1
star
26

mailru-favicon-count

Show unreaded emails count in mail.ru tabs favicon
JavaScript
1
star