Skip to main content

Flake8 plugin that checks SQL code against opinionated style rules

Project description

Flake8-SQL
==========

|Build Status|

Flake8-SQL is a `flake8 <http://flake8.readthedocs.org/en/latest/>`__
plugin that looks for SQL queries and checks then against an
opinionated style. This style mostly follows `SQL Style Guide
<http://www.sqlstyle.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 <https://github.com/pgjones/flake8-sql/blob/master/flake8_sql/keywords.py>`__
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 <https://github.com/pgjones/flake8-sql/blob/master/flake8_sql/keywords.py>`__
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``s rather than
what was actually written.


.. |Build Status| image:: https://travis-ci.org/pgjones/flake8-sql.svg?branch=master
:target: https://travis-ci.org/pgjones/flake8-sql


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-SQL-0.3.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flake8_SQL-0.3.0-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file flake8-SQL-0.3.0.tar.gz.

File metadata

  • Download URL: flake8-SQL-0.3.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

File hashes

Hashes for flake8-SQL-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5c2ff2c45333a104ec52a05f64668839be9484c081ea8a9b4abe215b383cad2c
MD5 120b484e1986a4daad723f559c01d3ce
BLAKE2b-256 417d1d9cc003f2d9043802ecfb0d5142c260e4e2396cfcc28070f628c935d169

See more details on using hashes here.

File details

Details for the file flake8_SQL-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: flake8_SQL-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

File hashes

Hashes for flake8_SQL-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f1f8c08d87e81ef1ad6c135257045d9b4a0a20a73a29cf09e93c66559aa33689
MD5 b2ee467ba07277feabcb1361a53e2a30
BLAKE2b-256 946a3266f41dd59d67c9efa784178c1ebcdfbde2cacb8c8f0fe72925499b41d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page