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

Ignore erroneous newline segments in L016 (e.g. Jinja for loops) #1494

Merged
merged 13 commits into from Oct 3, 2021

Conversation

tunetheweb
Copy link
Member

@tunetheweb tunetheweb commented Oct 3, 2021

Brief summary of the change made

Fixes #1456 by bailing out of checking rule 16 if segment contains a newline (which shouldn't happen but can happen for for loops)

Are there any other side effects of this change that we should be aware of?

Nope. Kept it simple after attempting (and failing!) the complex way.

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/parser (note YML files can be auto generated with python test/generate_parse_fixture_yml.py or by running tox locally).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@codecov
Copy link

codecov bot commented Oct 3, 2021

Codecov Report

Merging #1494 (d6d3871) into main (8267981) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              main     #1494    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          130       130            
  Lines         8849      9061   +212     
==========================================
+ Hits          8849      9061   +212     
Impacted Files Coverage Δ
src/sqlfluff/dialects/dialect_exasol_fs.py 100.00% <ø> (ø)
src/sqlfluff/dialects/dialect_postgres.py 100.00% <ø> (ø)
src/sqlfluff/core/parser/helpers.py 100.00% <100.00%> (ø)
src/sqlfluff/core/templaters/base.py 100.00% <100.00%> (ø)
src/sqlfluff/core/templaters/jinja.py 100.00% <100.00%> (ø)
src/sqlfluff/dialects/dialect_ansi.py 100.00% <100.00%> (ø)
src/sqlfluff/dialects/dialect_exasol.py 100.00% <100.00%> (ø)
src/sqlfluff/dialects/dialect_tsql.py 100.00% <100.00%> (ø)
src/sqlfluff/dialects/exasol_keywords.py 100.00% <100.00%> (ø)
src/sqlfluff/dialects/tsql_keywords.py 100.00% <100.00%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f2cdec...d6d3871. Read the comment docs.

src/sqlfluff/core/templaters/python.py Outdated Show resolved Hide resolved
test/core/templaters/jinja_test.py Outdated Show resolved Hide resolved
test/core/templaters/jinja_test.py Outdated Show resolved Hide resolved
@@ -18,7 +18,6 @@ file:
- newline: "\n"
- whitespace: ' '
- placeholder: '{% for action in actions %}'
- indent: ''
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix. These indents and dedents are not needed.

test/fixtures/templater/jinja_l_metas/002.yml Outdated Show resolved Hide resolved
Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small suggestions about comments or examples. Overall, looks like a great improvement. Huge contribution. 🎉😅

src/sqlfluff/core/templaters/python.py Outdated Show resolved Hide resolved
src/sqlfluff/core/templaters/python.py Outdated Show resolved Hide resolved
test/core/templaters/jinja_test.py Outdated Show resolved Hide resolved
test/fixtures/rules/std_rule_cases/L016.yml Outdated Show resolved Hide resolved
test/fixtures/templater/jinja_l_metas/002.yml Outdated Show resolved Hide resolved
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
@tunetheweb tunetheweb marked this pull request as draft October 3, 2021 14:28
@tunetheweb tunetheweb changed the title Better Jinja "for" loop handling Ignore erroneous newline segments in L016 (e.g. Jinja for loops) Oct 3, 2021
@tunetheweb
Copy link
Member Author

OK this is just impossible to fix. So I went with the plain and simple option of ignoring newline segments in rule L016.

Can you have a look @barrywhart ?

@tunetheweb tunetheweb marked this pull request as ready for review October 3, 2021 17:53
@barrywhart
Copy link
Member

Looks good!

@tunetheweb tunetheweb merged commit 4244cb5 into sqlfluff:main Oct 3, 2021
@tunetheweb tunetheweb deleted the better-jinja-for-loop-handling branch October 3, 2021 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Applying rule L016 threw an Exception: Is this possible?"
2 participants