summaryrefslogtreecommitdiff
path: root/sqlparse/formatter.py
diff options
context:
space:
mode:
authorVik <vmuriart@gmail.com>2016-06-06 07:45:06 -0700
committerVik <vmuriart@gmail.com>2016-06-06 07:45:06 -0700
commitd296ead1ddd5373ccac5e03279c782d538f30f98 (patch)
tree95e887de388e5f6f1516b1ea862e9d48a4d174eb /sqlparse/formatter.py
parentb9d81ac4fe49114f57dc33c0d635f99ff56e62f2 (diff)
parenta7c7d9586208516de372cb01203b48a53f7095fb (diff)
downloadsqlparse-d296ead1ddd5373ccac5e03279c782d538f30f98.tar.gz
Merge pull request #252 from vmuriart/rb-aligned-format
Rebased and Updated Aligned-Indent Format
Diffstat (limited to 'sqlparse/formatter.py')
-rw-r--r--sqlparse/formatter.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/sqlparse/formatter.py b/sqlparse/formatter.py
index 7441313..069109b 100644
--- a/sqlparse/formatter.py
+++ b/sqlparse/formatter.py
@@ -30,6 +30,11 @@ def validate_options(options):
raise SQLParseError('Invalid value for strip_comments: %r'
% strip_comments)
+ space_around_operators = options.get('use_space_around_operators', False)
+ if space_around_operators not in [True, False]:
+ raise SQLParseError('Invalid value for use_space_around_operators: %r'
+ % space_around_operators)
+
strip_ws = options.get('strip_whitespace', False)
if strip_ws not in [True, False]:
raise SQLParseError('Invalid value for strip_whitespace: %r'
@@ -55,6 +60,13 @@ def validate_options(options):
elif reindent:
options['strip_whitespace'] = True
+ reindent_aligned = options.get('reindent_aligned', False)
+ if reindent_aligned not in [True, False]:
+ raise SQLParseError('Invalid value for reindent_aligned: %r'
+ % reindent)
+ elif reindent_aligned:
+ options['strip_whitespace'] = True
+
indent_tabs = options.get('indent_tabs', False)
if indent_tabs not in [True, False]:
raise SQLParseError('Invalid value for indent_tabs: %r' % indent_tabs)
@@ -114,6 +126,10 @@ def build_filter_stack(stack, options):
stack.preprocess.append(filters.TruncateStringFilter(
width=options['truncate_strings'], char=options['truncate_char']))
+ if options.get('use_space_around_operators', False):
+ stack.enable_grouping()
+ stack.stmtprocess.append(filters.SpacesAroundOperatorsFilter())
+
# After grouping
if options.get('strip_comments'):
stack.enable_grouping()
@@ -130,6 +146,11 @@ def build_filter_stack(stack, options):
width=options['indent_width'],
wrap_after=options['wrap_after']))
+ if options.get('reindent_aligned', False):
+ stack.enable_grouping()
+ stack.stmtprocess.append(
+ filters.AlignedIndentFilter(char=options['indent_char']))
+
if options.get('right_margin'):
stack.enable_grouping()
stack.stmtprocess.append(