pgjones / flake8-sql

Flake8 plugin that checks SQL code against opinionated style rules
MIT License
26 stars 4 forks source link

Q449 confusion #14

Open ghost opened 4 years ago

ghost commented 4 years ago

Hey @pgjones I have this query

SELECT EXISTS(SELECT 1
                FROM table
               WHERE condition1
                 AND condition2)

and getting this Q449 warning: Q449 token FROM should be aligned to the right of the river

Is there any problem in my query formatting or i am not able to understand it or the lib is confused? Can you please point it out? I am using the latest version.

I'll be suppressing it for now until i get a replay from you. Thanks

ghost commented 4 years ago

Previously it was fine, with the latest version i'm getting same warning for similar queries from all over the code base.

ghost commented 4 years ago

There is another query on which it is throwing Q449 token FROM should be aligned to the right of the river

SELECT col1
  FROM table1
 WHERE NOT EXISTS(SELECT col2
                    FROM table2
                   WHERE condtion)

Could that be due to this EXISTS statement?

pgjones commented 4 years ago

Hmm, I'm not sure here - it could be. Could you confirm which version it worked in, and which version you are using now?

ghost commented 4 years ago

Previously 0.2.0 and now 0.4.0. The case is with every exists query of the same nature.

pgjones commented 4 years ago

I think it is the exists (and also this https://github.com/pgjones/flake8-sql/commit/d1a1000e870db0c3fd88cf5e5c7a62c33aad51d8) - as the exists isn't being recognized as a function.

ghost commented 4 years ago

So is this going to be fixed soon? Or if you can point me i might be able to send a fix.

pgjones commented 4 years ago

Very happy for you to send a fix, at the moment I can only point to d1a1000.

ghost commented 4 years ago

I had a look at the function you pointed out, seems like it is working fine (had it debugged). I think the problem is here on this line or below it: https://github.com/pgjones/flake8-sql/blob/ba92c22c2b5a94605b7be10f223d1c1e5d3d706a/flake8_sql/linter.py#L150

Debugged this one as well, the values (token col, depth, and previous root values) seems fine to me ( i might not be correct).

Could there be any issue with this condition? https://github.com/pgjones/flake8-sql/blob/ba92c22c2b5a94605b7be10f223d1c1e5d3d706a/flake8_sql/linter.py#L152

Values (debugged):

token: FROM token.col: 27 token.depth: 1 previous_root: SELECT previous_root.col: 25 previous_root len+1: 7

By adding the root_keyword condition is not working (failing other scenarios), can you help me out a bit here?