Open demhadais opened 1 month ago
Strange, I can't reproduce that behavior in the playground.
PS C:\Users\gvozdvmozgu\Projects\sqruff> cat .\.sqlfluff
[.sqruff]
dialect = postgres
PS C:\Users\gvozdvmozgu\Projects\sqruff> cat .\pg.sql
grant some_role to a_user;
PS C:\Users\gvozdvmozgu\Projects\sqruff> cargo r --quiet -- lint .\pg.sql
The linter processed 1 file(s).
All Finished 📜 🎉
PS C:\Users\gvozdvmozgu\Projects\sqruff>
My apologies - I didn't test the case where it's the only line in the file, in which case the bug doesn't occur. I'm trying to figure out what triggers it in my actual script, I'll reply with what I find shortly.
then most likely the error is due to incorrect parsing of the SQL file
Okay, so it seems that
grant some_role to a_user with admin true;
grant some_role to a_user;
gets reformatted to
grant some_role to a_user with admin true ;
grant some_role to a_user ;
meaning that adding with [OPTION] [true/false]
triggers it, and then sqruff
just wants to apply that spacing to the rest of the statements in the file, including create table foo (bar text primary key);
The part "with admin" breaks the parser.
file:
- statement:
- access_statement:
- keyword: grant
- whitespace: ' '
- object_reference:
- naked_identifier: some_role
- whitespace: ' '
- keyword: to
- whitespace: ' '
- role_reference:
- naked_identifier: a_user
- whitespace: ' '
- file:
- word: with
- whitespace: ' '
- word: admin
- whitespace: ' '
- word: 'true'
- semicolon: ;
- newline: |2+
- word: grant
- whitespace: ' '
- word: some_role
- whitespace: ' '
- word: to
- whitespace: ' '
- word: a_user
- semicolon: ;
- end_of_file: ''
I wouldn't necessarily classify this as a bug, but it seems unexpected to me that the following line of SQL:
triggers the
layout.spacing
rule, causingsqruff
to reformat to:Is this behavior desired/expected? For reference, I'm running
sqruff
v0.20.2, and my.sqruff
file is just