From a166ce883b5bdf62f7950d93407368e5523e48e9 Mon Sep 17 00:00:00 2001 From: toyeshhm Date: Tue, 10 Nov 2026 14:41:36 -0600 Subject: [PATCH] Fix DBeaver SQL formatter adding spaces inside backtick-quoted identifiers --- CHANGES.md | 1 + .../com/diffplug/spotless/sql/dbeaver/SQLDialect.java | 4 ++-- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + testlib/src/main/resources/sql/dbeaver/backticks.clean | 7 +++++++ testlib/src/main/resources/sql/dbeaver/backticks.dirty | 1 + .../spotless/sql/DBeaverSQLFormatterStepTest.java | 8 ++++++++ 7 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 testlib/src/main/resources/sql/dbeaver/backticks.clean create mode 100644 testlib/src/main/resources/sql/dbeaver/backticks.dirty diff --git a/CHANGES.md b/CHANGES.md index 733abfd3d9..793add5493 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed - GrEclipse no longer leaves a `file%3A...` directory in the working directory. ([#2019](https://github.com/diffplug/spotless/issues/2019)) - DBeaver SQL formatter no longer prints an `IndexOutOfBoundsException` when a file starts with a keyword like `SET`. ([#1552](https://github.com/diffplug/spotless/issues/1552)) +- DBeaver SQL formatter no longer adds spaces inside backtick-quoted identifiers such as `` `MyCol.1` ``. ([#2250](https://github.com/diffplug/spotless/issues/2250)) - `ExpandWildcardImportsStep` no longer fails with `Symbol resolution not configured` on records and other syntax newer than Java 11, and leaves files JavaParser cannot validate unchanged. ([#2946](https://github.com/diffplug/spotless/issues/2946)) - `removeSemicolons()` no longer removes semicolons inside dollar-slashy strings (`$/ ... /$`), after escaped triple quotes in multiline strings, or in multi-line `for (init; cond; update)` headers. ([#2780](https://github.com/diffplug/spotless/issues/2780)) - `RemoveUnusedImportsStep` and `GoogleJavaFormatStep` no longer remove imports that are only used by links in Markdown doc comments (`///`, JDK 23+). ([#3161](https://github.com/diffplug/spotless/issues/3161)) diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLDialect.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLDialect.java index 08b4e1a46c..7fb5089760 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLDialect.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLDialect.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. @@ -36,7 +36,7 @@ final class SQLDialect { private static final String[] DEFAULT_LINE_COMMENTS = {SQLConstants.SL_COMMENT}; private static final String[] EXEC_KEYWORDS = new String[0]; - private static final String[][] DEFAULT_QUOTE_STRINGS = {{"\"", "\""}}; + private static final String[][] DEFAULT_QUOTE_STRINGS = {{"\"", "\""}, {"`", "`"}}; // Keywords private final TreeMap allKeywords = new TreeMap<>(); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 27c78dde65..beadf79779 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed - GrEclipse no longer leaves a `file%3A...` directory in the working directory. ([#2019](https://github.com/diffplug/spotless/issues/2019)) - DBeaver SQL formatter no longer prints an `IndexOutOfBoundsException` when a file starts with a keyword like `SET`. ([#1552](https://github.com/diffplug/spotless/issues/1552)) +- DBeaver SQL formatter no longer adds spaces inside backtick-quoted identifiers such as `` `MyCol.1` ``. ([#2250](https://github.com/diffplug/spotless/issues/2250)) - `expandWildcardImports()` no longer fails with `Symbol resolution not configured` on records and other syntax newer than Java 11, and leaves files JavaParser cannot validate unchanged. ([#2946](https://github.com/diffplug/spotless/issues/2946)) - String `targetExclude` patterns ending in `/**` (e.g. `**/build/**`) are now applied as exclude patterns on String `target`s, so excluded directories are skipped while walking the target instead of walking the whole project directory, which made configuration cache store and reuse scale with the size of the project. ([#3147](https://github.com/diffplug/spotless/issues/3147)) - `removeSemicolons()` no longer removes semicolons inside dollar-slashy strings (`$/ ... /$`), after escaped triple quotes in multiline strings, or in multi-line `for (init; cond; update)` headers. ([#2780](https://github.com/diffplug/spotless/issues/2780)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 7120684723..2f99ff4f59 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed - GrEclipse no longer leaves a `file%3A...` directory in the working directory. ([#2019](https://github.com/diffplug/spotless/issues/2019)) - DBeaver SQL formatter no longer prints an `IndexOutOfBoundsException` when a file starts with a keyword like `SET`. ([#1552](https://github.com/diffplug/spotless/issues/1552)) +- DBeaver SQL formatter no longer adds spaces inside backtick-quoted identifiers such as `` `MyCol.1` ``. ([#2250](https://github.com/diffplug/spotless/issues/2250)) - `` no longer fails with `Symbol resolution not configured` on records and other syntax newer than Java 11, and leaves files JavaParser cannot validate unchanged. ([#2946](https://github.com/diffplug/spotless/issues/2946)) - `` no longer removes semicolons inside dollar-slashy strings (`$/ ... /$`), after escaped triple quotes in multiline strings, or in multi-line `for (init; cond; update)` headers. ([#2780](https://github.com/diffplug/spotless/issues/2780)) - `` and `` no longer remove imports that are only used by links in Markdown doc comments (`///`, JDK 23+). ([#3161](https://github.com/diffplug/spotless/issues/3161)) diff --git a/testlib/src/main/resources/sql/dbeaver/backticks.clean b/testlib/src/main/resources/sql/dbeaver/backticks.clean new file mode 100644 index 0000000000..1302ae1040 --- /dev/null +++ b/testlib/src/main/resources/sql/dbeaver/backticks.clean @@ -0,0 +1,7 @@ +SELECT + `MyCol.1` AS MY_COLUMN_1, + t.`MyCol.2` AS MY_COLUMN_2 +FROM + `my table` t +WHERE + `MyCol.1` = 1; diff --git a/testlib/src/main/resources/sql/dbeaver/backticks.dirty b/testlib/src/main/resources/sql/dbeaver/backticks.dirty new file mode 100644 index 0000000000..bef3b4e589 --- /dev/null +++ b/testlib/src/main/resources/sql/dbeaver/backticks.dirty @@ -0,0 +1 @@ +select `MyCol.1` as MY_COLUMN_1, t.`MyCol.2` as MY_COLUMN_2 from `my table` t where `MyCol.1` = 1; diff --git a/testlib/src/test/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStepTest.java index 24c6be0b19..296098507b 100644 --- a/testlib/src/test/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStepTest.java @@ -59,6 +59,14 @@ void keywordAtStartOfFileDoesNotThrow() { assertThat(err.toString()).isEmpty(); } + @Test + void backtickQuotedIdentifiers() { + // https://github.com/diffplug/spotless/issues/2250 + FormatterStep step = DBeaverSQLFormatterStep.create(Collections.emptySet()); + StepHarness.forStep(step) + .testResource("sql/dbeaver/backticks.dirty", "sql/dbeaver/backticks.clean"); + } + @Test void behaviorWithConfigFile() { FormatterStep step = DBeaverSQLFormatterStep.create(createTestFiles("sql/dbeaver/sqlConfig.properties"));