Skip to content
Draft
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
4 changes: 2 additions & 2 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@
"def reformat_too_long_line(li, max_len=82):\n",
" \"Reformat too long line `li` if it is longer than `max_len` characters after stripping\"\n",
" if len(li.strip()) > max_len:\n",
" function_re = re.compile(\"[\\w\\d]+\\(\")\n",
" function_re = re.compile(r\"[\\w\\d]+\\(\")\n",
" if function_re.search(li):\n",
" out_list = []\n",
" in_function = False # indicator for reformatting line with function\n",
Expand Down Expand Up @@ -3307,7 +3307,7 @@
" if len(split_c) == 1:\n",
" split_s[-1] = last_line + \";\"\n",
" else:\n",
" split_c[0][\"string\"] = re.sub(\"(.*[\\w\\d]+)(\\s*)$\", r\"\\1;\\2\", split_c[0][\"string\"])\n",
" split_c[0][\"string\"] = re.sub(r\"(.*[\\w\\d]+)(\\s*)$\", r\"\\1;\\2\", split_c[0][\"string\"])\n",
" split_s[-1] = \"\".join([d[\"string\"] for d in split_c])\n",
" return \"\\n\".join(split_s)"
]
Expand Down
2 changes: 1 addition & 1 deletion nbs/02_utils.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2473,7 +2473,7 @@
" # add comment to it and replace [C] by empty string and [CS] by newline + proper indentation\n",
" whitespace = \"\" if match_beginn_cs.match(d[\"comment\"]) else \" \"\n",
" fsplit_s_out[line_number] += whitespace + re.sub(\n",
" \"\\[CS\\]\", \n",
" r\"\\[CS\\]\", \n",
" \"\\n\" + \" \" * indentation, \n",
" replace_c.sub(\"\", d[\"comment\"])\n",
" ) \n",
Expand Down
6 changes: 3 additions & 3 deletions sql_formatter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def format_case_when(s):
def reformat_too_long_line(li, max_len=82):
"Reformat too long line `li` if it is longer than `max_len` characters after stripping"
if len(li.strip()) > max_len:
function_re = re.compile("[\w\d]+\(")
function_re = re.compile(r"[\w\d]+\(")
if function_re.search(li):
out_list = []
in_function = False # indicator for reformatting line with function
Expand Down Expand Up @@ -440,7 +440,7 @@ def add_semicolon(s):
if len(split_c) == 1:
split_s[-1] = last_line + ";"
else:
split_c[0]["string"] = re.sub("(.*[\w\d]+)(\s*)$", r"\1;\2", split_c[0]["string"])
split_c[0]["string"] = re.sub(r"(.*[\w\d]+)(\s*)$", r"\1;\2", split_c[0]["string"])
split_s[-1] = "".join([d["string"] for d in split_c])
return "\n".join(split_s)

Expand Down Expand Up @@ -482,4 +482,4 @@ def format_sql(s, semicolon=False, max_len=82):
subquery_pos = extract_outer_subquery(s)
# remove whitespace between word and parenthesis
s = re.sub(r"\s*\)", ")", s)
return s
return s
4 changes: 2 additions & 2 deletions sql_formatter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,9 @@ def assign_comment(fs, cds):
# add comment to it and replace [C] by empty string and [CS] by newline + proper indentation
whitespace = "" if match_beginn_cs.match(d["comment"]) else " "
fsplit_s_out[line_number] += whitespace + re.sub(
"\[CS\]",
r"\[CS\]",
"\n" + " " * indentation,
replace_c.sub("", d["comment"])
)
s_out = "\n".join(fsplit_s_out)
return s_out
return s_out