extend lint checks to several column lists

This commit is contained in:
Sean Corfield 2021-12-03 13:06:34 -08:00
parent dc37852024
commit e0cafbd434
3 changed files with 7 additions and 1 deletions

View file

@ -2,6 +2,7 @@
* 2.1.next in progress * 2.1.next in progress
* Fix #372 by merging `:select-distinct-on` differently. * Fix #372 by merging `:select-distinct-on` differently.
* Add empty column list check for `SELECT` and several other clauses, when `:checking :basic` (or `:strict`) is provided.
* Update `build-clj` to v0.6.0. * Update `build-clj` to v0.6.0.
* 2.1.829 -- 2021-11-27 * 2.1.829 -- 2021-11-27

View file

@ -364,7 +364,8 @@ was wrapped in `[:inline `..`]`:
* everything else is just turned into a string (by calling `str`) and added to the SQL string. * everything else is just turned into a string (by calling `str`) and added to the SQL string.
The `:checking` option defaults to `:none`. If `:checking :basic` is The `:checking` option defaults to `:none`. If `:checking :basic` is
specified, certain obvious errors -- such as `IN` with an empty collection -- specified, certain obvious errors -- such as `IN` with an empty collection
or `SELECT` with an empty list of columns --
are treated as an error and an exception is thrown. If `:checking :strict` are treated as an error and an exception is thrown. If `:checking :strict`
is specified, certain dubious constructs -- such as `IN` with a collection is specified, certain dubious constructs -- such as `IN` with a collection
containing `NULL` values -- are also treated as an error and an exception is containing `NULL` values -- are also treated as an error and an exception is

View file

@ -372,6 +372,10 @@
[(conj sql sql') (if params' (into params params') params)]) [(conj sql sql') (if params' (into params params') params)])
[[] []] [[] []]
(map #(format-selectable-dsl % {:as as}) xs))] (map #(format-selectable-dsl % {:as as}) xs))]
(when-not (= :none *checking*)
(when (empty? xs)
(throw (ex-info (str prefix " empty column list is illegal")
{:clause (into [prefix] xs)}))))
(into [(str prefix " " (str/join ", " sqls))] params)) (into [(str prefix " " (str/join ", " sqls))] params))
(let [[sql & params] (format-selectable-dsl xs {:as as})] (let [[sql & params] (format-selectable-dsl xs {:as as})]
(into [(str prefix " " sql)] params)))) (into [(str prefix " " sql)] params))))