diff --git a/CHANGES.md b/CHANGES.md index 7e40c43d0d..39bfdb1f3a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Add `versionCatalog` step for formatting and sorting Gradle version catalog (`.toml`) files. ([#2916](https://github.com/diffplug/spotless/issues/2916)) - Add `javaparserVersion` option to the Cleanthat step, allowing callers to override the JavaParser version pulled in transitively by Cleanthat. ([#2903](https://github.com/diffplug/spotless/pull/2903)) ### Fixed +- Preserve case of JDBI named bind params that collide with SQL keywords (e.g. `:limit`, `:offset`) in the DBeaver SQL formatter. ([#2899](https://github.com/diffplug/spotless/pull/2899)) - Fix non-idempotent formatting when `importOrder()` is combined with `greclipse()`: a single catch-all group no longer strips blank lines that `greclipse()` independently inserted between import groups. ([#2914](https://github.com/diffplug/spotless/pull/2914)) ### Changes - Bump default `cleanthat` version `2.24` -> `2.25`. ([#2903](https://github.com/diffplug/spotless/pull/2903)) diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java index 52665bf716..bad5d4a64a 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2025 DiffPlug + * Copyright 2016-2026 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,9 +95,13 @@ private List format(final List argList) { } final KeywordCase keywordCase = formatterCfg.getKeywordCase(); - for (FormatterToken anArgList : argList) { - token = anArgList; + for (int index = 0; index < argList.size(); index++) { + token = argList.get(index); if (token.getType() == TokenType.KEYWORD) { + // Do not transform case for JDBI named bind params (e.g. :limit, :offset) + if (index > 0 && isEmbeddedToken(argList.get(index - 1))) { + continue; + } token.setString(keywordCase.transform(token.getString())); } } @@ -323,8 +327,10 @@ private List format(final List argList) { continue; } if (token.getType() == TokenType.SYMBOL && isEmbeddedToken(token) + && (!":".equals(token.getString()) || prev.getType() == TokenType.SYMBOL) || prev.getType() == TokenType.SYMBOL && isEmbeddedToken(prev)) { - // Do not insert spaces around colons + // Do not insert spaces around embedded tokens (colons, dots), + // except before JDBI named bind params (e.g. :limit) preceded by a keyword or name continue; } if (token.getType() == TokenType.SYMBOL && prev.getType() == TokenType.SYMBOL) { diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index bf711feb06..e2b8d5471e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Add `javaparserVersion(...)` to `cleanthat`, allowing users to override the JavaParser version pulled in transitively by Cleanthat. ([#2903](https://github.com/diffplug/spotless/pull/2903)) ### Fixed - Fix `tableTestFormatter` editorconfig cache not honoring `.editorconfig` changes across Gradle daemon runs due to a shared static `EditorConfigProvider`. ([#2893](https://github.com/diffplug/spotless/pull/2893)) +- Preserve case of JDBI named bind params that collide with SQL keywords (e.g. `:limit`, `:offset`) in the DBeaver SQL formatter. ([#2899](https://github.com/diffplug/spotless/pull/2899)) - Fix non-idempotent formatting when `importOrder()` is combined with `greclipse()`: a single catch-all group no longer strips blank lines that `greclipse()` independently inserted between import groups. ([#2914](https://github.com/diffplug/spotless/pull/2914)) - Fix `predeclareDepsFromBuildscript()` on Gradle 9 by avoiding mutation of the root buildscript configuration container. ([#2929](https://github.com/diffplug/spotless/pull/2929), fixes [#2599](https://github.com/diffplug/spotless/issues/2599)) ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 315a2d951a..9a82841ea5 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Add `` format type with `` step for formatting and sorting Gradle version catalog files. ([#2916](https://github.com/diffplug/spotless/issues/2916)) - Add `` option to ``, allowing users to override the JavaParser version pulled in transitively by Cleanthat. ([#2903](https://github.com/diffplug/spotless/pull/2903)) ### Fixed +- Preserve case of JDBI named bind params that collide with SQL keywords (e.g. `:limit`, `:offset`) in the DBeaver SQL formatter. ([#2899](https://github.com/diffplug/spotless/pull/2899)) - The `-Dspotless.ratchetFrom=...` user property now takes priority over `` configured in the plugin or in individual formatters, instead of being overridden by them. ([#2896](https://github.com/diffplug/spotless/pull/2896), fixes [#2842](https://github.com/diffplug/spotless/issues/2842)) - Fix non-idempotent formatting when `importOrder()` is combined with `greclipse()`: a single catch-all group no longer strips blank lines that `greclipse()` independently inserted between import groups. ([#2914](https://github.com/diffplug/spotless/pull/2914)) ### Changes diff --git a/testlib/src/main/resources/sql/dbeaver/jdbi-params.clean b/testlib/src/main/resources/sql/dbeaver/jdbi-params.clean index be0934772a..fb00272a51 100644 --- a/testlib/src/main/resources/sql/dbeaver/jdbi-params.clean +++ b/testlib/src/main/resources/sql/dbeaver/jdbi-params.clean @@ -5,3 +5,10 @@ FROM WHERE id IN() AND user_id =:user_id; + +SELECT + * +FROM + TABLE + WHERE + id =:id LIMIT :limit OFFSET :offset; diff --git a/testlib/src/main/resources/sql/dbeaver/jdbi-params.dirty b/testlib/src/main/resources/sql/dbeaver/jdbi-params.dirty index 3193e724a9..b94db0fdb3 100644 --- a/testlib/src/main/resources/sql/dbeaver/jdbi-params.dirty +++ b/testlib/src/main/resources/sql/dbeaver/jdbi-params.dirty @@ -1 +1,2 @@ SELECT * FROM table WHERE id IN () AND user_id = :user_id; +SELECT * FROM table WHERE id = :id LIMIT :limit OFFSET :offset;