Skip to content
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

[FIX] line comments with -- cancel further formatting #152

Merged
merged 2 commits into from
Apr 5, 2021
Merged
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: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,6 @@ token

.gh-credentials
conda-recipe/*
conda-bld/*
conda-bld/*

test_sql/
107 changes: 102 additions & 5 deletions docs/core.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ <h2 id="General-formatting">General formatting<a class="anchor-link" href="#Gene
<span class="s2">create or replace table mytable as -- Mytable example</span>
<span class="s2">/* multi line</span>
<span class="s2"> comment */</span>
<span class="s2">seLecT a.asdf,b.qwer, -- some comment here</span>
<span class="s2">seLecT a.asdf,</span>
<span class="s2">-- some line comment</span>
<span class="s2">b.qwer, -- some comment here</span>
<span class="s2">/* and here is a line comment inside select */</span>
<span class="s2">substr(c.asdf,1,2) as substr_asdf, </span>
<span class="s2">/* some commenT </span>
Expand Down Expand Up @@ -106,6 +108,7 @@ <h2 id="General-formatting">General formatting<a class="anchor-link" href="#Gene
<span class="s2">/* multi line</span>
<span class="s2"> comment */</span>
<span class="s2">SELECT a.asdf,</span>
<span class="s2"> -- some line comment</span>
<span class="s2"> b.qwer, -- some comment here</span>
<span class="s2"> /* and here is a line comment inside select */</span>
<span class="s2"> substr(c.asdf, 1, 2) as substr_asdf,</span>
Expand Down Expand Up @@ -180,7 +183,7 @@ <h2 id="General-formatting">General formatting<a class="anchor-link" href="#Gene
<div class="output_markdown rendered_html output_subarea ">
<h4 id="clean_query" class="doc_header"><code>clean_query</code><a href="https://github.com/PabloRMira/sql_formatter/tree/master/sql_formatter/core.py#L33" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>clean_query</code>(<strong><code>s</code></strong>)</p>
</blockquote>
<p>Remove redundant whitespaces and mark comments boundaries and remove newlines afterwards in query <code>s</code></p>
<p>Remove redundant whitespaces, mark comments boundaries and remove newlines afterwards in query <code>s</code></p>

</div>

Expand Down Expand Up @@ -339,7 +342,7 @@ <h4 id="clean_query" class="doc_header"><code>clean_query</code><a href="https:/
<span class="n">clean_query</span><span class="p">(</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">SELECT asdf, qwer, /* another comment */</span>
<span class="sd">qwer1, </span>
<span class="sd">qwer1,</span>
<span class="sd">/* inline comment */</span>
<span class="sd">qwer2</span>
<span class="sd">FROM table1</span>
Expand Down Expand Up @@ -376,6 +379,49 @@ <h4 id="clean_query" class="doc_header"><code>clean_query</code><a href="https:/
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">assert_and_print</span><span class="p">(</span>
<span class="n">clean_query</span><span class="p">(</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">SELECT asdf,</span>
<span class="sd">qwer1, -- comment 1</span>
<span class="sd">-- inline comment</span>
<span class="sd">qwer2</span>
<span class="sd">FROM table1</span>
<span class="sd">WHERE asdf=1</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="p">),</span>
<span class="s2">&quot;SELECT asdf, qwer1, -- comment 1[C][CS]-- inline comment[C]qwer2 FROM table1 WHERE asdf=1&quot;</span>
<span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>SELECT asdf, qwer1, -- comment 1[C][CS]-- inline comment[C]qwer2 FROM table1 WHERE asdf=1
</pre>
</div>
</div>

</div>
</div>

</div>
{% endraw %}

{% raw %}

<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">assert_and_print</span><span class="p">(</span>
Expand Down Expand Up @@ -477,7 +523,7 @@ <h4 id="clean_query" class="doc_header"><code>clean_query</code><a href="https:/
<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>create or replace table mytable as -- Mytable example[C][CS]/* multi line[CI]comment */[C]seLecT a.asdf, b.qwer, -- some comment here[C][CS]/* and here is a line comment inside select */[C]substr(c.asdf, 1, 2) as substr_asdf,[CS]/* some commenT[CI]there */[C]case when a.asdf= 1 then &#39;b&#39; /* here a case comment */[C]when b.qwer =2 then &#39;c&#39; else &#39;d&#39; end as new_field, -- Some comment[C][CS]/* and here some inline comment */[C]b.asdf2 frOm table1 as a leFt join table2 as b -- and here a comment[C]on a.asdf = b.asdf /* joiN this way */[C]inner join table3 as c on a.asdf=c.asdf and a.qwer= b.qwer whEre a.asdf= 1 -- comment this[C]anD b.qwer =2 and a.asdf&lt;=1 --comment that[C]or b.qwer&gt;=5 groUp by a.asdf
<pre>create or replace table mytable as -- Mytable example[C][CS]/* multi line[CI]comment */[C]seLecT a.asdf,[CS]-- some line comment[C]b.qwer, -- some comment here[C][CS]/* and here is a line comment inside select */[C]substr(c.asdf, 1, 2) as substr_asdf,[CS]/* some commenT[CI]there */[C]case when a.asdf= 1 then &#39;b&#39; /* here a case comment */[C]when b.qwer =2 then &#39;c&#39; else &#39;d&#39; end as new_field, -- Some comment[C][CS]/* and here some inline comment */[C]b.asdf2 frOm table1 as a leFt join table2 as b -- and here a comment[C]on a.asdf = b.asdf /* joiN this way */[C]inner join table3 as c on a.asdf=c.asdf and a.qwer= b.qwer whEre a.asdf= 1 -- comment this[C]anD b.qwer =2 and a.asdf&lt;=1 --comment that[C]or b.qwer&gt;=5 groUp by a.asdf
</pre>
</div>
</div>
Expand Down Expand Up @@ -1082,7 +1128,7 @@ <h4 id="preformat_statements" class="doc_header"><code>preformat_statements</cod

<div class="output_subarea output_stream output_stdout output_text">
<pre>CREATE OR REPLACE TABLE mytable AS -- Mytable example[C][CS]/* multi line[CI]comment */[C]
SELECT a.asdf, b.qwer, -- some comment here[C][CS]/* and here is a line comment inside select */[C]substr(c.asdf, 1, 2) as substr_asdf,[CS]/* some commenT[CI]there */[C]case when a.asdf= 1 then &#39;b&#39; /* here a case comment */[C]when b.qwer =2 then &#39;c&#39; else &#39;d&#39; end as new_field, -- Some comment[C][CS]/* and here some inline comment */[C]b.asdf2
SELECT a.asdf,[CS]-- some line comment[C]b.qwer, -- some comment here[C][CS]/* and here is a line comment inside select */[C]substr(c.asdf, 1, 2) as substr_asdf,[CS]/* some commenT[CI]there */[C]case when a.asdf= 1 then &#39;b&#39; /* here a case comment */[C]when b.qwer =2 then &#39;c&#39; else &#39;d&#39; end as new_field, -- Some comment[C][CS]/* and here some inline comment */[C]b.asdf2
FROM table1 as a
LEFT JOIN table2 as b -- and here a comment[C]
ON a.asdf = b.asdf /* joiN this way */[C]
Expand Down Expand Up @@ -2303,6 +2349,55 @@ <h4 id="format_select" class="doc_header"><code>format_select</code><a href="htt
</div>
</div>

</div>
{% endraw %}

<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Line comment with --</p>

</div>
</div>
</div>
{% raw %}

<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">assert_and_print</span><span class="p">(</span>
<span class="n">format_select</span><span class="p">(</span><span class="s2">&quot;SELECT a.asdf, b.qwer, -- some comment here[C][CS]-- and here is a line comment inside select[C]qwer2&quot;</span><span class="p">),</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">SELECT a.asdf,</span>
<span class="sd"> b.qwer, -- some comment here</span>
<span class="sd"> -- and here is a line comment inside select</span>
<span class="sd"> qwer2</span>
<span class="sd">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
<span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>SELECT a.asdf,
b.qwer, -- some comment here
-- and here is a line comment inside select
qwer2
</pre>
</div>
</div>

</div>
</div>

</div>
{% endraw %}

Expand Down Expand Up @@ -4471,6 +4566,7 @@ <h4 id="format_simple_sql" class="doc_header"><code>format_simple_sql</code><a h
/* multi line
comment */
SELECT a.asdf,
-- some line comment
b.qwer, -- some comment here
/* and here is a line comment inside select */
substr(c.asdf, 1, 2) as substr_asdf,
Expand Down Expand Up @@ -4749,6 +4845,7 @@ <h4 id="format_sql" class="doc_header"><code>format_sql</code><a href="https://g
/* multi line
comment */
SELECT a.asdf,
-- some line comment
b.qwer, -- some comment here
/* and here is a line comment inside select */
substr(c.asdf, 1, 2) as substr_asdf,
Expand Down
Loading