Skip to main content

Tab indentation style checker for flake8

Project description

Tab Style Checker for flake8

Like tabs? So do I.

This module provides a smart indentation checking module for the awesome flake8 style checker suite, featuring pycodestyle, pyflakes and mccabe by default as well as a minimalist plugin architecture.

When loaded flake8-tabs will disable pycodestyle's “tabs_or_spaces”, “continued_indentation”, “tabs_obsolete” and “trailing_whitespace” checkers. Replacing them by its own more flexible checkers, that allow for the “tabs for indentation, spaces for alignment” paradgime to be applied to your source code.

(Note that flake8-tabs will currently not check spaces-indented source code, but adding this should be trivial. Please open an issue if you have a use-case for this.)

Useful Links:

Reported Error Codes

All error codes were borrowed from pycodestyle. You can detect that they were generated by flake8-tabs by them being followed by the word (flake8-tabs).

Error Code Meaning
E101 Mixed block of tabs and spaces detected where there as a least one tab following a space
E121, E122, E123, E126, E127, E128 Identation did not match what was expected (configurable)
W291 Extranous whitespace detected on end of line
W293 Whitespace that was not aligned with the next block or source code detected (configurable)

Also note that, due to the way we disable the relevant checkers from pycodestyle the following error code do not have an equivalent in this plugin: E124, E125, E129, E131, E133.

Options

Note that in the following indenting refers to the practice of adding new levels of indentation (usually using tab key whether you're using tabs or not) on a separate line, while aligning refers to the practice of adding spacing in front of the elements on the following line to make them visually match the elements on the previous line. Indentation may refer to any of the above.

Defaults tend to reflect recommendations from PEP-8.

tab-width

  • Default: 4
  • Allowed values: Any integer >= 1

The expected size of each tab in spaces. This is not really specific to this plugin, but used to properly calculate the required additional spaced indentation when indenting within an aligned section.

blank-lines-indent

  • Default: "maybe"
  • Allowed values: "maybe", "always", "never"

Whether to allow, properly aligned, indentation in blank lines. The default value will allow both aligned indentation and no indentation. "always" will require blank lines to contain indentation, "never" will prohibit it.

By properly aligned indentation we mean indentation that has the same value as the indentation of the next block of source code:

# This is OK:
def main():
	# … snip …
	do_something()
	
	do_something_else()
	# … snip …

# This is not OK:
def main():
	while True:
		# … snip …
		do_something()
	
		do_something_else()
		# … snip …

# This is by default OK as well (unindented):
def main():
	while True:
		# … snip …
		do_something()

		do_something_else()
		# … snip …

Enforcing indentation styles

The following options may be useful if you wish to enforce a more consistent for some language elements than what is enforced by default:

indent-style-call

  • Default: "auto"
  • Allowed values: "auto", "indent", "align"

Style of indentation for function and method calls:

# Using indents
x = long_function_name(
	param1,
	param2, param3)

# Using alignment
x = long_function_name(param1,
·······················param2, param3)

The default auto option will choose the style to apply in each case depending on whether there is at least one parameter provided on the first line of the function call (PEP-8).

indent-style-def

  • Default: "auto"
  • Allowed values: "auto", "indent", "align"

Style of indentation for function and class definitions:

# Using indents
def main(
		param1,
		param2, param3):
	# Contents

# Using alignment
def main(param1,
·········param2, param3):
	# Contents

The default auto option will choose the style to apply in each case depending on whether there is at least one parameter defined on the first line of the definition (PEP-8).

Minimal Tab Sizes when Indenting

indent-tabs-call

  • Default: 1
  • Allowed values: Any integer >= 1

The number of tabs to add when adding the first level of indentation using indenting within a function or method call:

# Example with: indent-tabs-call=3
x = long_function_name(
			{  # First level gets 3 levels of indenting
				"name": "value"  # Next level is indented as usual
			},
			param2, param3
)

Usually you should leave this at 1 (PEP-8) but some teams may prefer a value of 2 to function calls more easily distinguishable from blocks.

indent-tabs-def

  • Default: 2
  • Allowed values: Any integer >= 1

The number of tabs to add when adding the first level of indentation using indenting within a class of method definition:

# Example with the default of: indent-tabs-def=2
def main(
		param1, param2, param3,
		param4):
	initialize_something()
)

Notice in the example above how an indent level of 1 would make the elements of the parameter list hard to distingish from the first statement. Hence PEP8 recommends either indenting twice or using alignment instead.

indent-tabs-expr

  • Default: 1
  • Allowed values: Any integer >= 1

The number of tabs to add when adding the first level of indentation using indenting within any other kind of construct (such as a tuple, set, dict, …).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-tabs-1.0.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flake8_tabs-1.0.0-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

Details for the file flake8-tabs-1.0.0.tar.gz.

File metadata

  • Download URL: flake8-tabs-1.0.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.19.1

File hashes

Hashes for flake8-tabs-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e4acebf97c43be9431e598674431670f84a2fa6df17c3985a20fefe3760db33f
MD5 5f7430d80fc2d8c0727758a9b7de25f4
BLAKE2b-256 02832f64e5911fc9a532004975da47288a531af647b25ee52ac40df25aeaca2b

See more details on using hashes here.

File details

Details for the file flake8_tabs-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: flake8_tabs-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.19.1

File hashes

Hashes for flake8_tabs-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 778da30f817f065dcb5dd27d0c69bd121df46b6cbfc1e85c7a615a9cb0f19358
MD5 deef2450e54f566e562598e1cc44cfa3
BLAKE2b-256 049169bfc07d72b613bd6ee31b5aef0e99ec7004021b89a79b34f803b775b4ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page