mirror of
https://github.com/sqlfluff/sqlfluff
synced 2025-12-17 19:31:32 +00:00
* Add yamllint checks * Update to ture/false instead of True/False * Reinstate all rules * Extend default * Add ignore direcotries
241 lines
6.8 KiB
YAML
241 lines
6.8 KiB
YAML
rule: L016
|
|
|
|
test_pass_line_too_long_config_override:
|
|
# Long lines (with config override)
|
|
pass_str: "SELECT COUNT(*) FROM tbl\n"
|
|
configs:
|
|
rules:
|
|
max_line_length: 30
|
|
|
|
test_fail_line_too_long_with_comments_1:
|
|
# Check we move comments correctly
|
|
fail_str: "SELECT 1 -- Some Comment\n"
|
|
|
|
fix_str: "-- Some Comment\nSELECT 1\n"
|
|
configs:
|
|
rules:
|
|
max_line_length: 18
|
|
|
|
test_fail_line_too_long_with_comments_2:
|
|
# Check we can add newlines after dedents (with an indent)
|
|
fail_str: " SELECT COUNT(*) FROM tbl\n"
|
|
fix_str: " SELECT\n COUNT(*)\n FROM tbl\n"
|
|
configs:
|
|
rules:
|
|
max_line_length: 20
|
|
|
|
test_fail_line_too_long_with_comments_3:
|
|
# Check priority of fixes
|
|
fail_str: "SELECT COUNT(*) FROM tbl -- Some Comment\n"
|
|
fix_str: "-- Some Comment\nSELECT\n COUNT(*)\nFROM tbl\n"
|
|
configs:
|
|
rules:
|
|
max_line_length: 18
|
|
|
|
test_fail_line_too_long_with_comments_4:
|
|
# In this case, the inline comment is NOT on a line by itself (note the
|
|
# leading comma), but even if we move it onto a line by itself, it's still
|
|
# too long. In this case, the rule should do nothing, otherwise it triggers
|
|
# an endless cycle of "fixes" that simply keeps adding blank lines.
|
|
fail_str: |
|
|
SELECT
|
|
c1
|
|
,-- the "y variable" and uses_small_subject_line to be the "x variable" in terms of the regression line.
|
|
c2
|
|
fix_str: |
|
|
SELECT
|
|
c1
|
|
,-- the "y variable" and uses_small_subject_line to be the "x variable" in terms of the regression line.
|
|
c2
|
|
configs:
|
|
rules:
|
|
max_line_length: 80
|
|
|
|
test_pass_line_too_long_with_comments_ignore_comment_lines:
|
|
# Same case as above, but should pass as ignore_comment_lines is set to true
|
|
pass_str: |
|
|
SELECT
|
|
c1
|
|
,-- the "y variable" and uses_small_subject_line to be the "x variable" in terms of the regression line.
|
|
c2
|
|
configs:
|
|
rules:
|
|
max_line_length: 80
|
|
L016:
|
|
ignore_comment_lines: true
|
|
|
|
test_fail_line_too_long_only_comments:
|
|
# Check long lines that are only comments are linted correctly
|
|
fail_str: "-- Some really long comments on their own line\n\nSELECT 1"
|
|
configs:
|
|
rules:
|
|
max_line_length: 18
|
|
|
|
test_fail_line_too_long_handling_indents:
|
|
# Check we handle indents nicely
|
|
fail_str: "SELECT 12345\n"
|
|
fix_str: "SELECT\n 12345\n"
|
|
configs:
|
|
rules:
|
|
max_line_length: 10
|
|
|
|
test_pass_line_too_long_ignore_comments_true:
|
|
# Check we can ignore comments if we want
|
|
pass_str: "SELECT 1\n-- Some long comment over 10 characters\n"
|
|
configs:
|
|
rules:
|
|
max_line_length: 10
|
|
L016:
|
|
ignore_comment_lines: true
|
|
|
|
test_pass_line_too_long_ignore_comments_false:
|
|
# Check we still pick up long comments if we don't want to ignore
|
|
fail_str: "SELECT 1\n-- Some long comment over 10 characters\n"
|
|
configs:
|
|
rules:
|
|
max_line_length: 10
|
|
L016:
|
|
ignore_comment_lines: false
|
|
|
|
test_compute_line_length_before_template_expansion_1:
|
|
# Line 3 is fine before expansion. Too long after expansion is NOT considered
|
|
# a violation.
|
|
pass_str: |
|
|
SELECT user_id
|
|
FROM
|
|
`{{bi_ecommerce_orders}}` {{table_at_job_start}}
|
|
configs:
|
|
core:
|
|
dialect: bigquery
|
|
templater:
|
|
jinja:
|
|
context:
|
|
table_at_job_start: FOR SYSTEM_TIME AS OF CAST('2021-03-02T01:22:59+00:00' AS TIMESTAMP)
|
|
bi_ecommerce_orders: bq-business-intelligence.user.ecommerce_orders
|
|
|
|
|
|
test_compute_line_length_before_template_expansion_2:
|
|
# Line 3 is too long before expansion. It's fine after expansion, but the rule
|
|
# does not look at that.
|
|
fail_str: |
|
|
SELECT user_id
|
|
FROM
|
|
`{{bi_ecommerce_orders_bi_ecommerce_orders}}` AS {{table_alias_table_alias_table_alias_table_alias_table_alias_table_alias}}
|
|
configs:
|
|
core:
|
|
dialect: bigquery
|
|
templater:
|
|
jinja:
|
|
context:
|
|
bi_ecommerce_orders_bi_ecommerce_orders: bq-business-intelligence.user.ecommerce_orders
|
|
table_alias_table_alias_table_alias_table_alias_table_alias_table_alias: t
|
|
|
|
|
|
test_long_jina_comment:
|
|
fail_str: |
|
|
SELECT *
|
|
{# comment #}
|
|
{# ........................................................................... #}
|
|
FROM table
|
|
configs:
|
|
rules:
|
|
max_line_length: 80
|
|
L016:
|
|
ignore_comment_lines: false
|
|
|
|
|
|
test_long_jina_comment_ignore:
|
|
# A Jinja comment is not seen as a SQL comment (perhaps it should be?) so should still fail
|
|
fail_str: |
|
|
SELECT *
|
|
{# comment #}
|
|
{# ........................................................................... #}
|
|
FROM table
|
|
configs:
|
|
rules:
|
|
max_line_length: 80
|
|
L016:
|
|
ignore_comment_lines: true
|
|
|
|
|
|
test_for_loop:
|
|
# A Jinja for loop
|
|
pass_str: |
|
|
{% for elem in 'foo' %}
|
|
SELECT '{{ elem }}' FROM table1;
|
|
SELECT '{{ elem }}' FROM table2;
|
|
{% endfor %}
|
|
|
|
|
|
test_for_loop_repeating_elements_starts_with_literal:
|
|
# A Jinja for loop with repeating elements (that are difficult to match)
|
|
# but starting with a literal that can be used to match
|
|
pass_str: |
|
|
{% set elements = 'foo' %}
|
|
SELECT
|
|
CASE
|
|
{% for elem in elements %}
|
|
WHEN '{{ elem }}' = '' THEN 1
|
|
WHEN '{{ elem }}' = '' THEN 1
|
|
{% endfor %}
|
|
END
|
|
|
|
|
|
test_for_loop_starting_with_templated_piece:
|
|
# A Jinja for loop starting with non-literals
|
|
# But unique parts can be used to match
|
|
pass_str: |
|
|
{% set elements = 'foo' %}
|
|
{% set when = 'WHEN' %}
|
|
SELECT
|
|
CASE
|
|
{% for elem in elements %}
|
|
{{ when }} '{{ elem }}' = '' THEN 1
|
|
{{ when }} '{{ elem }}' = '' THEN 2
|
|
{% endfor %}
|
|
END
|
|
|
|
test_for_loop_fail_complex_match:
|
|
# A Jinja for loop starting with non-literals
|
|
# But non-unique parts which therefore cannot
|
|
# be used to match
|
|
pass_str: |
|
|
{% set elements = 'foo' %}
|
|
{% set when = 'WHEN' %}
|
|
SELECT
|
|
CASE
|
|
{% for elem in elements %}
|
|
{{ when }} '{{ elem }}' = '' THEN 1
|
|
{{ when }} '{{ elem }}' = '' THEN 1
|
|
{% endfor %}
|
|
END
|
|
|
|
test_for_loop_fail_simple_match:
|
|
# If for loop only contains literals it should still pass
|
|
pass_str: |
|
|
{% set elements = 'foo' %}
|
|
SELECT
|
|
CASE
|
|
{% for elem in elements %}
|
|
WHEN 'f' THEN a
|
|
{% endfor %}
|
|
END
|
|
|
|
|
|
test_set_statement:
|
|
# A Jinja set statement
|
|
pass_str: |
|
|
{% set statement = "SELECT 1 from table1;" %}
|
|
{{ statement }}{{ statement }}
|
|
configs:
|
|
rules:
|
|
max_line_length: 80
|
|
|
|
|
|
test_issue_1666_line_too_long_unfixable_jinja:
|
|
# Note the trailing space at the end of line 1. This is a necessary part of
|
|
# the test, because the space (which is passed through to the output) was
|
|
# "tricking" L016 into trying to split the line, then encountering an internal
|
|
# error.
|
|
fail_str: "{{ config (schema='bronze', materialized='view', sort =['id','number'], dist = 'all', tags =['longlonglonglonglong']) }} \n\nselect 1\n"
|