Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import com.intellij.psi.impl.source.codeStyle.PostFormatProcessor
import org.domaframework.doma.intellij.common.util.StringUtil

abstract class SqlPostProcessor : PostFormatProcessor {
companion object {
private const val FILE_END_PADDING = " ${StringUtil.LINE_SEPARATE}"
}

private val trailingSpacesRegex = Regex(" +(\r?\n)")

override fun processElement(
Expand Down Expand Up @@ -55,5 +51,5 @@ abstract class SqlPostProcessor : PostFormatProcessor {
isEndSpace: Boolean,
): String =
text.trimEnd() +
if (isEndSpace) FILE_END_PADDING else ""
if (isEndSpace) StringUtil.LINE_SEPARATE else ""
}
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/CreateTable_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ CREATE TABLE departments
id INT PRIMARY KEY
, name VARCHAR(100)
, loc INT NOT NULL
)
)
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/CreateView_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ AS
, lastname
, hiredate
FROM employee
WHERE salary > 50000
WHERE salary > 50000
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/DeleteReturning_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ DELETE FROM x
WHERE id > /* id */101
AND div = 't' )
RETURNING id
, name
, name
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/Delete_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ DELETE FROM x
WHERE id IN ( SELECT id
FROM x2
WHERE id > /* id */101
AND div = 't' )
AND div = 't' )
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ INSERT INTO employee
VALUES ( /* employees.id */0
, /* employees.name */'name' )
ON CONFLICT (username) ON CONSTRAINT
DO NOTHING
DO NOTHING
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ INSERT INTO users
ON CONFLICT ON CONSTRAINT
DO UPDATE
SET email = EXCLUDED.email
, created_at = CURRENT_TIMESTAMP
, created_at = CURRENT_TIMESTAMP
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ DO UPDATE
WHERE employees.name IS DISTINCT FROM EXCLUDED.name
RETURNING id
, manager_id
, name
, name
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/InsertReturning_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ INSERT INTO /*# tableName */
, 1
, /* @maxDateTime() */'9999-12-31' )
RETURNING x1
, x2
, x2
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ INSERT INTO /*# tableName */
, /* @userId() */1
, x6
, 1
, /* @maxDateTime() */'9999-12-31' )
, /* @maxDateTime() */'9999-12-31' )
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/Insert_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ INSERT INTO /*# tableName */
, /* @userId() */1
, x6
, 1
, /* @maxDateTime() */'9999-12-31' )
, /* @maxDateTime() */'9999-12-31' )
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ SELECT e.id
/*%end */ -- END2
/*%else */ -- ELSE1
e.id ASC
/*%end */ -- END1
/*%end */ -- END1
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ SELECT CASE WHEN div = 'A' THEN 'AAA'
/*%end*/
ELSE 'CCC'
END AS divName
FROM users
FROM users
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/SelectCaseEnd_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ SELECT CASE WHEN div = 'A' THEN 'AAA'
WHEN div = 'B' THEN 'BBB'
ELSE 'CCC'
END AS divName
FROM users
FROM users
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ DELETE FROM x "div"
, id
FROM x2
WHERE id > 101
AND `div`."age$a" = 't' )
AND `div`."age$a" = 't' )
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ SELECT u.name
, LATERAL ( SELECT *
FROM post
WHERE content = 'XXX' ) AS tag
, employee
, employee
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ SELECT u.name
, ( SELECT tag
FROM post
WHERE u.usr_id = auther ) AS tag
, employee
, employee
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ SELECT user_id
FROM employee emp
, ( VALUES
/*# usersList */
) T (user_id, name) ) u
) T (user_id, name) ) u
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ SELECT user_id
(20000000001, 'John')
, (20000000002 'Tom')
, (20000000003, 'Anna')
) T (user_id, name) ) u
) T (user_id, name) ) u
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SELECT u.user_id
ORDER BY o.order_date DESC
LIMIT 1 ) o
ON true
AND false
AND false
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/Select_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ SELECT COUNT(DISTINCT x) AS count_x
OR x.modelmag_g BETWEEN 10 AND 21)
GROUP BY n.objid ) AS nbor
ON o.objid = nbor.objid
WHERE o.objid IN /* params */(1, 2, 3)
WHERE o.objid IN /* params */(1, 2, 3)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ UPDATE /*# tableName */
/*%for entity : entities */
, /*# entity.itemIdentifier */ = /* entity.value */'abc'
/*%end*/
WHERE X = /* reportId */1
WHERE X = /* reportId */1
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ UPDATE /*# tableName */
/*%for entity : entities */
, /* entity.value */'abc'
/*%end*/ )
WHERE x = /* reportId */1
WHERE x = /* reportId */1
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/UpdateReturning_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ UPDATE user
WHERE id = /* user.id */1
RETURNING id
, name
, rank
, rank
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/Update_format.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
UPDATE user
SET name = /* user.name */'name'
, rank = /*user.rank */3
WHERE id = /* user.id */1
WHERE id = /* user.id */1
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/WithDelete_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ WITH deleted_posts AS (
RETURNING id
)
SELECT *
FROM deleted_posts
FROM deleted_posts
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/WithInsert_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ INSERT INTO user_profiles
, bio)
SELECT id
, name
FROM new_user
FROM new_user
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/WithMultiQuery_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ SELECT user_id
FROM users
WHERE suspended = TRUE
ORDER BY name ASC
LIMIT 100 OFFSET 10
LIMIT 100 OFFSET 10
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/WithOptional_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ WITH RECURSIVE org_tree (emp_id
)
SEARCH BREADTH FIRST BY emp_id SET order_seq
CYCLE emp_id SET is_cycle TO TRUE DEFAULT FALSE USING path_ids
SELECT * FROM org_tree;
SELECT * FROM org_tree
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/WithRecursive_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ WITH RECURSIVE org_tree (emp_id
ON e.manager_id = ot.emp_id
)
SELECT *
FROM org_tree
FROM org_tree
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/WithSelect_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ WITH users AS (
SELECT user_id
, name
FROM users
WHERE suspended = TRUE
WHERE suspended = TRUE
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/WithUnionAll_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ SELECT query.id3
AND query.pre_as3 = q2.sub_id
WHERE query.id3 = /* id */1
ORDER BY query.id3
, query.pre_as3
, query.pre_as3
2 changes: 1 addition & 1 deletion src/test/testData/sql/formatter/WithUpdate_format.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ WITH recent_activity AS (
RETURNING id
)
SELECT *
FROM updated_users
FROM updated_users
Loading