Code Monkey home page Code Monkey logo

flake8-sql's Introduction

Flake8-SQL

Build Status

Flake8-SQL is a flake8 plugin that looks for SQL queries and checks then against an opinionated style. This style mostly follows SQL Style Guide, but differ in the two following ways. Firstly alignement should be with the INTO rather than INSERT keyword, i.e.

INSERT INTO table (columns)
     VALUES (values)

Secondly JOIN should be aligned to the left of the river, i.e.

SELECT *
  FROM table1
  JOIN table2 ON ...

Warnings

Q440 Keyword is not uppercase

All the SQL reserved keywords should be uppercase.

Q441 Name is not valid

All the non SQL keywords should be snake_case, start with a letter and not end with an _. Due to a limitation snake_case is checks ensure that the word is lowercase.

Q442 Avoid abbreviated keywords

Avoid using abbreviated keywords instead use the full length version.

Q443 Incorrect whitespace around comma

Commas should be followed by whitespace, but not preceded.

Q444 Incorrect whitespace around equals

Equals should be surrounded with whitespace.

Q445 Missing linespace between root keywords

The root keywords SELECT, FROM, INSERT, VALUES, DELETE FROM, WHERE, UPDATE, AND, OR and SET should be on separate lines (unless the entire query is on one line).

Q446 Missing newline after semicolon

Semicolons must be at the end of the line.

Q447 Root keywords should be right aligned

The root keywords SELECT, FROM, INSERT, VALUES, WHERE, UPDATE, AND, OR, JOIN and SET should be right aligned i.e.

SELECT *
  FROM table

Q448 subquery should be aligned to the right of the river

Any subquery should be aligned to the right of the river i.e.

SELECT *
  FROM table
 WHERE column IN
       (SELECT column
          FROM table)

Q449 tokens should be aligned to the right of the river

Any tokens should be aligned to the right of the river i.e

SELECT column1,
       column2
  FROM table

Configuration

At times it is simpler to use a reserved keyword as an identifier than go to the effort to avoid it. To allow for this set the sql-excepted-names option to a comma separated list of these names.

Limitations

String constants are sought out in the code and considered SQL if they contain select from, insert into values, update set or delete from in order. This may and is likely to lead to false positives, in which case simply add # noqa to have this plugin ignore the string.

F-Strings are formatted with the formatted values, {...}, replaced with the constant formatted_value before being linted. This leads to the error message referring to formatted_value rather than what was actually written.

flake8-sql's People

Contributors

agatti avatar jaimelennox avatar pgjones avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flake8-sql's Issues

Unable to run flake8_sql with flake8 on Ubuntu 14.04

pip install flake8_sql
Collecting flake8_sql
/usr/local/lib/python2.7/dist-packages/pip/vendor/requests/packages/urllib3/util/ssl.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/vendor/requests/packages/urllib3/util/ssl.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading flake8_SQL-0.2.0-py2.py3-none-any.whl
Collecting sqlparse (from flake8_sql)
Downloading sqlparse-0.2.3-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/lib/python2.7/dist-packages (from flake8_sql)
Collecting flake8 (from flake8_sql)
Downloading flake8-3.3.0-py2.py3-none-any.whl (66kB)
100% |████████████████████████████████| 71kB 3.2MB/s
Collecting pyflakes<1.6.0,>=1.5.0 (from flake8->flake8_sql)
Downloading pyflakes-1.5.0-py2.py3-none-any.whl (225kB)
100% |████████████████████████████████| 225kB 3.3MB/s
Requirement already satisfied (use --upgrade to upgrade): enum34; python_version < "3.4" in /usr/local/lib/python2.7/dist-packages (from flake8->flake8_sql)
Requirement already satisfied (use --upgrade to upgrade): configparser; python_version < "3.2" in /usr/local/lib/python2.7/dist-packages (from flake8->flake8_sql)
Collecting mccabe<0.7.0,>=0.6.0 (from flake8->flake8_sql)
Downloading mccabe-0.6.1-py2.py3-none-any.whl
Collecting pycodestyle<2.4.0,>=2.0.0 (from flake8->flake8_sql)
Downloading pycodestyle-2.3.1-py2.py3-none-any.whl (45kB)
100% |████████████████████████████████| 51kB 5.1MB/s
Installing collected packages: sqlparse, pyflakes, mccabe, pycodestyle, flake8, flake8-sql
Successfully installed flake8-3.3.0 flake8-sql-0.2.0 mccabe-0.6.1 pycodestyle-2.3.1 pyflakes-1.5.0 sqlparse-0.2.3
/usr/local/lib/python2.7/dist-packages/pip/vendor/requests/packages/urllib3/util/ssl.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

$ flake8 --help
Traceback (most recent call last):
File "/usr/local/bin/flake8", line 11, in
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/flake8/main/cli.py", line 16, in main
app.run(argv)
File "/usr/local/lib/python2.7/dist-packages/flake8/main/application.py", line 328, in run
self._run(argv)
File "/usr/local/lib/python2.7/dist-packages/flake8/main/application.py", line 315, in _run
self.initialize(argv)
File "/usr/local/lib/python2.7/dist-packages/flake8/main/application.py", line 297, in initialize
self.find_plugins()
File "/usr/local/lib/python2.7/dist-packages/flake8/main/application.py", line 147, in find_plugins
self.check_plugins.load_plugins()
File "/usr/local/lib/python2.7/dist-packages/flake8/plugins/manager.py", line 392, in load_plugins
plugins = list(self.manager.map(load_plugin))
File "/usr/local/lib/python2.7/dist-packages/flake8/plugins/manager.py", line 284, in map
yield func(self.plugins[name], *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flake8/plugins/manager.py", line 390, in load_plugin
return plugin.load_plugin()
File "/usr/local/lib/python2.7/dist-packages/flake8/plugins/manager.py", line 183, in load_plugin
raise failed_to_load
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "Q4" due to invalid syntax (linter.py, line 25).

TypeError NoneType - int

Running flake8 with flake8-sql on pre-commit CI is giving me the following error:

multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/checker.py", line 687, in _run_checks
    return checker.run_checks()
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/checker.py", line 597, in run_checks
    self.run_ast_checks()
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/checker.py", line 500, in run_ast_checks
    for (line_number, offset, text, _) in runner:
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8_sql/linter.py", line 49, in run
    initial_offset = _get_initial_offset(node, self.lines)
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8_sql/linter.py", line 178, in _get_initial_offset
    first_physical_line = physical_lines[query_end_lineno - len(logical_lines)]
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/bin/flake8", line 8, in <module>
    sys.exit(main())
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/main/application.py", line 375, in run
    self._run(argv)
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/main/application.py", line 364, in _run
    self.run_checks()
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/main/application.py", line 271, in run_checks
    self.file_checker_manager.run()
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/checker.py", line 309, in run
    self.run_parallel()
  File "/pc/clone/xmjboxSjQ1inMpIIGAKj3w/py_env-python3/lib/python3.10/site-packages/flake8/checker.py", line 275, in run_parallel
    for ret in pool_map:
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 448, in <genexpr>
    return (item for chunk in result for item in chunk)
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 870, in next
    raise value
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

It appears that the problem is on this line:

first_physical_line = physical_lines[query_end_lineno - len(logical_lines)]

where the result of _get_query_end_lineno may be None.

Should ABS trigger Q442?

Hi there,

I'm wondering why ABS is in the abbreviated keywords list, as (to the best of my knowledge) it is not really an abbreviation but a proper function. I'm using PostgreSQL but from what I've seen both SQL Server and MySQL do have that function (PostgreSQL also has an abbreviated form of that function, @ <number>, but that's even worse...).

Are there any plans to remove that from such list or should I stick with # noqa: Q442?

Thanks!

Python 3.8 changes behaviour and makes noqa for multiline strings impossible

When upgrading to python 3.8, flake8-sql suddenly started complaining about queries which before were passing fine. Some examples:

from sqlalchemy.sql import text

# passes the flake8 linter in python 3.8
sql = text(
    """
       UPDATE entry
          SET helpful = :helpful
        WHERE id = :entry_id
    """
)


# passes the flake8 linter in python 3.7, but fails in 3.8 
# due to complaining about alignment of root_keywords
# Q447 root_keywords UPDATE and SET are not right aligned
# Q447 root_keywords UPDATE and WHERE are not right aligned
sql = text(
    """UPDATE entry
          SET helpful = :helpful
        WHERE id = :entry_id"""
)


# fails the linter in python 3.8, as DATE_TRUNC is not valid, but noqa isn't picked up.
# It looks at the line of the opening """, not the closing one as before.
sql = text(
    """
       UPDATE entry
          SET processed = DATE_TRUNC(:processed)
        WHERE id = :entry_id
    """  # noqa
)


# passes the flake8 linter in python 3.7, due to noqa being picked up
sql = text(
    """UPDATE entry
          SET processed = DATE_TRUNC(:processed)
        WHERE id = :entry_id"""  # noqa
)

The second issue this brought up, as mentioned in the 3rd example, is that when using multiline strings like the ones above, the flake8-sql error is now registered to the first line of the query (the opening """). This means there's nowhere to place the # noqa comment to ignore the errors. Before the error was registered to the line of the close """, so the comment could go after there (as in the 4th example). I imagine this is something to do with python changing how the AST looks like for multiline strings, but it's preventing us from upgrading to python 3.8 as there's some errors we have to ignore.

I realise 3.8 only just released, so it might be worth waiting until the 3.8.1 release for stability before tackling the issue, but I thought it'd be worth raising the issue now.

Q447 root_keywords SELECT and FROM are not right aligned

Hi!
I have this query:

CREATE OR REPLACE VIEW registration_list AS
         SELECT col1, col2, col3, col4, col5, col6, col7,
                col8, col9, SUBSTRING(col1 FROM 1 FOR 8) AS col10
              FROM table
           WHERE col5 IS NULL WITH CHECK OPTION

and the flake-8 kept giving me the error:
Q447 root_keywords SELECT and FROM are not right aligned
I tried many possibilities but i'm not able to remove the error, i would appreciate if you can help me in pointing the issue.

Support f-strings

It looks like flake8-sql fails to parse queries built with f-strings (the same string with .format() works)

Below is a compact example tested with: python -m flake8 flake8_sql_check.py

columns = 'col1,col2'
view = 'View1'

# Works, catches Q440
query = 'select {columns} From [{view}]'.format(columns=columns, view=view)

# Throws "TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'"
# query = f'select {columns} From [{view}]'

Full traceback:

C:\Users\king.kyle\Developer\project>poetry run python -m flake8 flake8_sql_check.py
Traceback (most recent call last):
  File "c:\users\king.kyle\miniconda3\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\king.kyle\miniconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8\__main__.py", line 4, in <module>
    cli.main()
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8\main\cli.py", line 22, in main 
    app.run(argv)
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8\main\application.py", line 363, in run
    self._run(argv)
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8\main\application.py", line 351, in _run
    self.run_checks()
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8\main\application.py", line 264, in run_checks
    self.file_checker_manager.run()
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8\checker.py", line 323, in run  
    self.run_serial()
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8\checker.py", line 307, in run_serial
    checker.run_checks()
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8\checker.py", line 589, in run_checks
    self.run_ast_checks()
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8\checker.py", line 494, in run_ast_checks
    for (line_number, offset, text, _) in runner:
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8_sql\linter.py", line 49, in run    initial_offset = _get_initial_offset(node, self.lines)
  File "C:\Users\king.kyle\Developer\project\.venv\lib\site-packages\flake8_sql\linter.py", line 178, in _get_initial_offset
    first_physical_line = physical_lines[query_end_lineno - len(logical_lines)]
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

I can possibly look into a PR later, but wanted to report the error since I've run into it a few times.

I just want to live dangerously:

Good old Bobby Tables

Q447 a Q449 do not work well with group by and having

This piece of code:

SELECT acfc.adcategoryid, acfc.targetmetadatadefinitionid
  FROM [adcategoryfiltercondition] acfc
 GROUP BY acfc.adcategoryid, acfc.targetmetadatadefinitionid
HAVING acfc.targetmetadatadefinitionid IS NOT NULL

should be fine according to the style guide that is linked in the docs: https://www.sqlstyle.guide/

But running flake8-sql gives two errors: Q447 and Q449:

Q447 root_keywords SELECT and GROUP BY are not right aligned
Q449 token HAVING should be aligned to the right of the river

Speaking of GROUP BY, an example in the style guide is here: https://www.sqlstyle.guide/#spaces, i.e. only GROUP is aligned to the right of the river, but flake8-sql requires the whole GROUP BY to be aligned to the right of the river, i.e. this doesn't give an error:

  SELECT acfc.adcategoryid, acfc.targetmetadatadefinitionid
    FROM [adcategoryfiltercondition] acfc
GROUP BY acfc.adcategoryid, acfc.targetmetadatadefinitionid

In terms of HAVING, there's no example in the style guide, but I believe it should be just like WHERE, that is it should be a root_keyword and required to be aligned to the right of the river. Such an approach is mentioned for example in here.

The syntax for disabling multiple warnings in one line is too strict

As of now, the # noqa: ... statement disables only the first warning when the corresponding codes are separated by ', ' (with a space), e.g. the following will only disable Q440:

# noqa: Q440, Q447, Q448, Q449

-- which might be confusing if you don't know that spaces are not allowed (they probably should be). The following still disables all the warnings:

# noqa: Q440,Q447,Q448,Q449

False positive on docstring

If flake8 is run on a file containing following code, errors listed below will get raised

def test():
    """
    Request osmcha analysis for changeset ids and update edits table with flags.

    All cs ids are passed as a parameter to the api request (in case of a large
    number of changesets,they will be split into multiple lists, i.e. this will
    result in multiple requests).
    The flags of each changeset are aggregated and uploaded into the db.

    To see possible values of reasons look at osmcha_reasons.md.
    :param settings:
    :return:
    """
    pass
test.py:3:80: E501 line too long (80 > 79 characters)
test.py:13:5: Q441 name Request is not valid, must be snake_case, and cannot end with `_`
test.py:13:5: Q440 keyword for is not uppercase
test.py:13:5: Q440 keyword and is not uppercase
test.py:13:5: Q440 keyword update is not uppercase
test.py:13:5: Q440 keyword table is not uppercase
test.py:13:5: Q440 keyword with is not uppercase
test.py:13:5: Q440 keyword All is not uppercase
test.py:13:5: Q440 keyword are is not uppercase
test.py:13:5: Q440 keyword as is not uppercase
test.py:13:5: Q440 keyword parameter is not uppercase
test.py:13:5: Q440 keyword to is not uppercase
test.py:13:5: Q440 keyword case is not uppercase
test.py:13:5: Q440 keyword of is not uppercase
test.py:13:5: Q440 keyword large is not uppercase
test.py:13:5: Q440 keyword of is not uppercase
test.py:13:5: Q440 keyword split is not uppercase
test.py:13:5: Q440 keyword into is not uppercase
test.py:13:5: Q440 keyword lists is not uppercase
test.py:13:5: Q440 keyword result is not uppercase
test.py:13:5: Q441 name The is not valid, must be snake_case, and cannot end with `_`
test.py:13:5: Q440 keyword of is not uppercase
test.py:13:5: Q440 keyword each is not uppercase
test.py:13:5: Q440 keyword are is not uppercase
test.py:13:5: Q440 keyword and is not uppercase
test.py:13:5: Q440 keyword into is not uppercase
test.py:13:5: Q440 keyword To is not uppercase
test.py:13:5: Q440 keyword values is not uppercase
test.py:13:5: Q440 keyword of is not uppercase
test.py:13:5: Q440 keyword at is not uppercase
test.py:13:5: Q444 incorrect whitespace around equals
test.py:13:5: Q443 incorrect whitespace around comma
test.py:13:5: Q445 missing linespace between root_keywords and and update
test.py:13:5: Q449 token All should be aligned to the right of the river
test.py:13:5: Q449 token cs should be aligned to the right of the river
test.py:13:5: Q449 token ids should be aligned to the right of the river
test.py:13:5: Q449 token are should be aligned to the right of the river
test.py:13:5: Q449 token passed should be aligned to the right of the river
test.py:13:5: Q449 token as should be aligned to the right of the river
test.py:13:5: Q449 token a should be aligned to the right of the river
test.py:13:5: Q449 token parameter should be aligned to the right of the river
test.py:13:5: Q449 token to should be aligned to the right of the river
test.py:13:5: Q449 token the should be aligned to the right of the river
test.py:13:5: Q449 token api should be aligned to the right of the river
test.py:13:5: Q449 token number should be aligned to the right of the river
test.py:13:5: Q449 token of should be aligned to the right of the river
test.py:13:5: Q449 token changesets should be aligned to the right of the river
test.py:13:5: Q449 token , should be aligned to the right of the river
test.py:13:5: Q449 token they should be aligned to the right of the river
test.py:13:5: Q449 token will should be aligned to the right of the river
test.py:13:5: Q449 token be should be aligned to the right of the river
test.py:13:5: Q449 token split should be aligned to the right of the river
test.py:13:5: Q447 root_keywords and and into are not right aligned
test.py:13:5: Q449 token multiple should be aligned to the right of the river
test.py:13:5: Q449 token result should be aligned to the right of the river
test.py:13:5: Q449 token in should be aligned to the right of the river
test.py:13:5: Q449 token multiple should be aligned to the right of the river
test.py:13:5: Q449 token requests should be aligned to the right of the river
test.py:13:5: Q449 token ) should be aligned to the right of the river
test.py:13:5: Q449 token . should be aligned to the right of the river
test.py:13:5: Q449 token The should be aligned to the right of the river
test.py:13:5: Q449 token flags should be aligned to the right of the river
test.py:13:5: Q449 token of should be aligned to the right of the river
test.py:13:5: Q449 token each should be aligned to the right of the river
test.py:13:5: Q449 token changeset should be aligned to the right of the river
test.py:13:5: Q449 token are should be aligned to the right of the river
test.py:13:5: Q449 token aggregated should be aligned to the right of the river
test.py:13:5: Q447 root_keywords and and and are not right aligned
test.py:13:5: Q447 root_keywords and and into are not right aligned
test.py:13:5: Q449 token To should be aligned to the right of the river
test.py:13:5: Q449 token see should be aligned to the right of the river
test.py:13:5: Q449 token possible should be aligned to the right of the river
test.py:13:5: Q447 root_keywords and and values are not right aligned
test.py:13:5: Q449 token of should be aligned to the right of the river
test.py:13:5: Q449 token reasons should be aligned to the right of the river
test.py:13:5: Q449 token look should be aligned to the right of the river
test.py:13:5: Q449 token at should be aligned to the right of the river
test.py:13:5: Q449 token osmcha_reasons should be aligned to the right of the river
test.py:13:5: Q449 token :param should be aligned to the right of the river
test.py:13:5: Q449 token settings should be aligned to the right of the river
test.py:13:5: Q449 token : should be aligned to the right of the river
test.py:13:5: Q449 token :return should be aligned to the right of the river
test.py:13:5: Q449 token : should be aligned to the right of the river

Python version and installed depdencies (venv) are:

python = "3.10"
flake8 = "4.0.1"
flake8-SQL = "0.4.1"

Q449 confusion

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

Q440 keyword type / key is not uppercase

Hey there, really cool extension to flake8 😄

I believe it is reporting some false positives when table field names are type or key.

e.g.

./elite/libraries/launchpad_builder.py:195:0: Q440 keyword type is not uppercase
./elite/libraries/launchpad_builder.py:222:0: Q440 keyword type is not uppercase
./elite/libraries/launchpad_builder.py:247:0: Q440 keyword type is not uppercase
./elite/libraries/launchpad_builder.py:271:0: Q440 keyword type is not uppercase
./elite/libraries/launchpad_builder.py:296:0: Q440 keyword type is not uppercase
./elite/libraries/launchpad_builder.py:343:0: Q440 keyword type is not uppercase
./elite/libraries/launchpad_builder.py:352:0: Q440 keyword key is not uppercase
./elite/libraries/launchpad_builder.py:372:0: Q440 keyword type is not uppercase
./elite/libraries/launchpad_builder.py:396:0: Q440 keyword key is not uppercase
./elite/libraries/launchpad_builder.py:472:0: Q440 keyword key is not uppercase
./elite/libraries/launchpad_builder.py:472:0: Q440 keyword key is not uppercase

And here are some related lines:

Lines 192 - 196:

            cursor.execute('''
                INSERT INTO items (rowid, uuid, flags, type, parent_id, ordering)
                     VALUES (?, ?, 2, ?, ?, ?)
            ''', (group_id, generate_uuid(), Types.PAGE, root_parent_id, page_ordering + 1)
            )

Lines 348 - 353:

        cursor.execute('''
            UPDATE dbinfo
               SET value = 1
             WHERE key = 'ignore_items_update_triggers'
        ''')
        self.conn.commit()

Any help is greatly appreciated 😄
Fotis

SQL queries inside f-strings (Python 3.6+) are not being checked

Hey there, another little issue I discovered is that SQL inside f-strings are not being checked:

e.g.

Lines 61 - 65:

        for item_id, title, uuid, flags in self.conn.execute(f'''
            SELECT {table}.item_id, {table}.title, items.uuid, items.flags
            FROM {table}
            JOIN items ON items.rowid = {table}.item_id
        '''):

These show no errors, but if I remove the f prior to the string starting, I see:

./elite/libraries/launchpad_builder.py:65:0: Q447 root_keywords SELECT and FROM are not right aligned
./elite/libraries/launchpad_builder.py:65:0: Q449 token { should be aligned to the right of the river
./elite/libraries/launchpad_builder.py:65:0: Q449 token table should be aligned to the right of the river
./elite/libraries/launchpad_builder.py:65:0: Q447 root_keywords SELECT and JOIN are not right aligned
./elite/libraries/launchpad_builder.py:65:0: Q449 token items should be aligned to the right of the river

Kindest Regards
Fotis

Failed to run Flake8-sql

Hey @pgjones, How do I run this plugin so that Linting can take place fo specifically SQL?

When I run using flake8 and put the rule e.g Q440 linting does not take place.

I have tried and searched around but failed to get the correct commands.

Can you please update the readme for guidance on this issue?

from confusion

            SELECT year, AVG(price)
            FROM table
            WHERE table.foo=$5 AND table.bar=$6 AND
                table.day >= ($3::DATE + ((extract(year from table."day") - 2 || ' year')::INTERVAL))::DATE AND

and get errors like: Q447 root_keywords FROM and from are not right aligned

presumably due to the year from table section

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.