Skip to content

Commit

Permalink
[FIX] Semicolon under line with comment not properly formatted (#139)
Browse files Browse the repository at this point in the history
* [fix-semicolon] add update master

* [fix-semicolon] fix semicolon under line not properly formatted
  • Loading branch information
PabloRMira authored Jan 22, 2021
1 parent 4ec4b93 commit f619279
Show file tree
Hide file tree
Showing 8 changed files with 473 additions and 37 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ clean:

prepush:
nbdev_build_lib && nbdev_test_nbs && nbdev_build_docs

update_master:
git checkout master && git pull
183 changes: 181 additions & 2 deletions docs/core.html
Original file line number Diff line number Diff line change
Expand Up @@ -3815,6 +3815,185 @@ <h4 id="format_multiline_comments" class="doc_header"><code>format_multiline_com

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

</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">
<h3 id="Add-semicolon-at-the-end-of-query">Add semicolon at the end of query<a class="anchor-link" href="#Add-semicolon-at-the-end-of-query"> </a></h3>
</div>
</div>
</div>
{% raw %}

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

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

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="add_semicolon" class="doc_header"><code>add_semicolon</code><a href="https://github.com/PabloRMira/sql_formatter/tree/master/sql_formatter/core.py#L346" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>add_semicolon</code>(<strong><code>s</code></strong>)</p>
</blockquote>
<p>Add a semicolon at the of query <code>s</code></p>

</div>

</div>

</div>
</div>

</div>
{% endraw %}

{% raw %}

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

</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>
<span class="n">add_semicolon</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2">CREATE OR REPLACE TABLE my_table AS</span>
<span class="s2">SELECT asdf,</span>
<span class="s2"> qwer</span>
<span class="s2">FROM table1 /* something */</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">strip</span><span class="p">()),</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">CREATE OR REPLACE TABLE my_table AS</span>
<span class="sd">SELECT asdf,</span>
<span class="sd"> qwer</span>
<span class="sd">FROM table1; /* something */</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>CREATE OR REPLACE TABLE my_table AS
SELECT asdf,
qwer
FROM table1; /* something */
</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>
<span class="n">add_semicolon</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2">CREATE OR REPLACE TABLE my_table AS</span>
<span class="s2">SELECT asdf,</span>
<span class="s2"> qwer</span>
<span class="s2">FROM table1 -- some thing</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">strip</span><span class="p">()),</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">CREATE OR REPLACE TABLE my_table AS</span>
<span class="sd">SELECT asdf,</span>
<span class="sd"> qwer</span>
<span class="sd">FROM table1; -- some thing</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>CREATE OR REPLACE TABLE my_table AS
SELECT asdf,
qwer
FROM table1; -- some thing
</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>
<span class="n">add_semicolon</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2">CREATE OR REPLACE TABLE my_table AS</span>
<span class="s2">SELECT asdf,</span>
<span class="s2"> qwer</span>
<span class="s2">FROM table1</span>
<span class="s2">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">strip</span><span class="p">()),</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">CREATE OR REPLACE TABLE my_table AS</span>
<span class="sd">SELECT asdf,</span>
<span class="sd"> qwer</span>
<span class="sd">FROM table1;</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>CREATE OR REPLACE TABLE my_table AS
SELECT asdf,
qwer
FROM table1;
</pre>
</div>
</div>

</div>
</div>

</div>
{% endraw %}

Expand All @@ -3836,7 +4015,7 @@ <h2 id="Putting-everything-together">Putting everything together<a class="anchor


<div class="output_markdown rendered_html output_subarea ">
<h4 id="format_simple_sql" class="doc_header"><code>format_simple_sql</code><a href="https://github.com/PabloRMira/sql_formatter/tree/master/sql_formatter/core.py#L346" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>format_simple_sql</code>(<strong><code>s</code></strong>)</p>
<h4 id="format_simple_sql" class="doc_header"><code>format_simple_sql</code><a href="https://github.com/PabloRMira/sql_formatter/tree/master/sql_formatter/core.py#L359" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>format_simple_sql</code>(<strong><code>s</code></strong>, <strong><code>semicolon</code></strong>=<em><code>False</code></em>)</p>
</blockquote>
<p>Format a simple SQL query without subqueries <code>s</code></p>

Expand Down Expand Up @@ -4060,7 +4239,7 @@ <h3 id="Main-function-handling-queries-with-subqueries">Main function handling q


<div class="output_markdown rendered_html output_subarea ">
<h4 id="format_sql" class="doc_header"><code>format_sql</code><a href="https://github.com/PabloRMira/sql_formatter/tree/master/sql_formatter/core.py#L360" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>format_sql</code>(<strong><code>s</code></strong>)</p>
<h4 id="format_sql" class="doc_header"><code>format_sql</code><a href="https://github.com/PabloRMira/sql_formatter/tree/master/sql_formatter/core.py#L375" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>format_sql</code>(<strong><code>s</code></strong>, <strong><code>semicolon</code></strong>=<em><code>False</code></em>)</p>
</blockquote>
<p>Format SQL query with subqueries <code>s</code></p>

Expand Down
72 changes: 61 additions & 11 deletions docs/format_file.html
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,56 @@ <h4 id="format_sql_commands" class="doc_header"><code>format_sql_commands</code>
<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_sql_commands</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2">create or replace table my_table As</span>
<span class="s2">Select asdf, qwer</span>
<span class="s2">From table2</span>
<span class="s2">group by asdf -- some comment</span>
<span class="s2">;</span>
<span class="s2">&quot;&quot;&quot;</span><span class="p">),</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">CREATE OR REPLACE TABLE my_table AS</span>
<span class="sd">SELECT asdf,</span>
<span class="sd"> qwer</span>
<span class="sd">FROM table2</span>
<span class="sd">GROUP BY asdf; -- some comment</span>
<span class="sd">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">lstrip</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>CREATE OR REPLACE TABLE my_table AS
SELECT asdf,
qwer
FROM table2
GROUP BY asdf; -- some comment

</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 @@ -760,7 +810,7 @@ <h3 id="Function-to-format-1-SQL-file">Function to format 1 SQL file<a class="an


<div class="output_markdown rendered_html output_subarea ">
<h4 id="format_sql_file" class="doc_header"><code>format_sql_file</code><a href="https://github.com/PabloRMira/sql_formatter/tree/master/sql_formatter/format_file.py#L91" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>format_sql_file</code>(<strong><code>f</code></strong>)</p>
<h4 id="format_sql_file" class="doc_header"><code>format_sql_file</code><a href="https://github.com/PabloRMira/sql_formatter/tree/master/sql_formatter/format_file.py#L103" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>format_sql_file</code>(<strong><code>f</code></strong>)</p>
</blockquote>
<p>Format file <code>f</code> with SQL commands and overwrite the file.</p>
<p>Return exit_code:</p>
Expand Down Expand Up @@ -896,11 +946,11 @@ <h4 id="format_sql_file" class="doc_header"><code>format_sql_file</code><a href=
<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>Something went wrong in file: /tmp/tmp9iqjtdct
<pre>Something went wrong in file: /tmp/tmpop4zflz2
[WARNING] Identified CREATE keyword more than twice within the same query at lines [(1, 7)]
You may have forgotten a semicolon (;) to delimit the queries
Aborting formatting for file /tmp/tmp9iqjtdct
Aborting formatting for file /tmp/tmp9iqjtdct
Aborting formatting for file /tmp/tmpop4zflz2
Aborting formatting for file /tmp/tmpop4zflz2
create or replace transient table my_table As
select asdf, Qwer, /* ; */
qwer2, -- ;
Expand Down Expand Up @@ -961,11 +1011,11 @@ <h4 id="format_sql_file" class="doc_header"><code>format_sql_file</code><a href=
<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>Something went wrong in file: /tmp/tmptxuyuw8q
<pre>Something went wrong in file: /tmp/tmp8t4q02ii
[WARNING] Identified unbalanced parenthesis at lines [[3], [8]]
You should check your parenthesis
Aborting formatting for file /tmp/tmptxuyuw8q
Aborting formatting for file /tmp/tmptxuyuw8q
Aborting formatting for file /tmp/tmp8t4q02ii
Aborting formatting for file /tmp/tmp8t4q02ii
create or replace transient table my_table As
select asdf, Qwer, /* ; */
(qwer2, -- ;
Expand Down Expand Up @@ -1026,13 +1076,13 @@ <h4 id="format_sql_file" class="doc_header"><code>format_sql_file</code><a href=
<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>Something went wrong in file: /tmp/tmpwoud5teg
<pre>Something went wrong in file: /tmp/tmp8ipv6ujr
[WARNING] Identified CREATE keyword more than twice within the same query at lines [(1, 7)]
You may have forgotten a semicolon (;) to delimit the queries
[WARNING] Identified unbalanced parenthesis at lines [[3, 8]]
You should check your parenthesis
Aborting formatting for file /tmp/tmpwoud5teg
Aborting formatting for file /tmp/tmpwoud5teg
Aborting formatting for file /tmp/tmp8ipv6ujr
Aborting formatting for file /tmp/tmp8ipv6ujr
create or replace transient table my_table As
select asdf, Qwer, /* ; */
(qwer2, -- ;
Expand Down Expand Up @@ -1071,7 +1121,7 @@ <h3 id="Function-to-format-many-SQL-files">Function to format many SQL files<a c


<div class="output_markdown rendered_html output_subarea ">
<h4 id="format_sql_files" class="doc_header"><code>format_sql_files</code><a href="https://github.com/PabloRMira/sql_formatter/tree/master/sql_formatter/format_file.py#L144" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>format_sql_files</code>(<strong><code>files</code></strong>:"(Relative) path to SQL files. You can also use wildcard using ".<em>sql"", <strong><code>recursive</code></strong>:"Should files also be searched in subfolders?"=</em><code>False</code>*)</p>
<h4 id="format_sql_files" class="doc_header"><code>format_sql_files</code><a href="https://github.com/PabloRMira/sql_formatter/tree/master/sql_formatter/format_file.py#L156" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>format_sql_files</code>(<strong><code>files</code></strong>:"(Relative) path to SQL files. You can also use wildcard using ".<em>sql"", <strong><code>recursive</code></strong>:"Should files also be searched in subfolders?"=</em><code>False</code>*)</p>
</blockquote>
<p>Format SQL <code>files</code></p>

Expand Down
Loading

0 comments on commit f619279

Please sign in to comment.