Skip to content

Add --no-visual flag to disallow visual indentation #642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Quick help is available on the command line::
--max-line-length=n set maximum allowed line length (default: 79)
--hang-closing hang closing bracket instead of matching indentation of
opening bracket's line
--no-visual force hanging indentation
--format=format set the error format [default|pylint|<custom>]
--diff report only lines changed according to the unified diff
received on STDIN
Expand Down
13 changes: 8 additions & 5 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def indentation(logical_line, previous_logical, indent_char,

@register_check
def continued_indentation(logical_line, tokens, indent_level, hang_closing,
indent_char, noqa, verbose):
indent_char, noqa, verbose, no_visual):
r"""Continuation lines indentation.

Continuation lines should align wrapped elements either vertically
Expand Down Expand Up @@ -595,7 +595,7 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
# closing bracket matches indentation of opening bracket's line
if hang_closing:
yield start, "E133 closing bracket is missing indentation"
elif indent[depth] and start[1] < indent[depth]:
elif indent[depth] and start[1] < indent[depth] and not no_visual:
if visual_indent is not True:
# visual indent is broken
yield (start, "E128 continuation line "
Expand All @@ -606,7 +606,7 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
yield (start, "E123 closing bracket does not match "
"indentation of opening bracket's line")
hangs[depth] = hang
elif visual_indent is True:
elif visual_indent is True and not no_visual:
# visual indent is verified
indent[depth] = start[1]
elif visual_indent in (text, str):
Expand All @@ -616,7 +616,7 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
# indent is broken
if hang <= 0:
error = "E122", "missing indentation or outdented"
elif indent[depth]:
elif indent[depth] and not no_visual:
error = "E127", "over-indented for visual indent"
elif not close_bracket and hangs[depth]:
error = "E131", "unaligned for hanging indent"
Expand Down Expand Up @@ -1561,6 +1561,7 @@ def __init__(self, filename=None, lines=None,
self.max_line_length = options.max_line_length
self.multiline = False # in a multiline string?
self.hang_closing = options.hang_closing
self.no_visual = options.no_visual
self.verbose = options.verbose
self.filename = filename
# Dictionary where a checker can store its custom state.
Expand Down Expand Up @@ -2124,7 +2125,7 @@ def get_parser(prog='pycodestyle', version=__version__):
usage="%prog [options] input ...")
parser.config_options = [
'exclude', 'filename', 'select', 'ignore', 'max-line-length',
'hang-closing', 'count', 'format', 'quiet', 'show-pep8',
'hang-closing', 'no-visual', 'count', 'format', 'quiet', 'show-pep8',
'show-source', 'statistics', 'verbose']
parser.add_option('-v', '--verbose', default=0, action='count',
help="print status messages, or debug with -vv")
Expand Down Expand Up @@ -2164,6 +2165,8 @@ def get_parser(prog='pycodestyle', version=__version__):
parser.add_option('--hang-closing', action='store_true',
help="hang closing bracket instead of matching "
"indentation of opening bracket's line")
parser.add_option('--no-visual', action='store_true',
help="force hanging indentation")
parser.add_option('--format', metavar='format', default='default',
help="set the error format [default|pylint|<custom>]")
parser.add_option('--diff', action='store_true',
Expand Down