Skip to content

Commit

Permalink
feat: upgrade to sql-formatter v14, remove tabulateAlias and `comma…
Browse files Browse the repository at this point in the history
…Position` options (#315)

Co-authored-by: JounQin <admin@1stg.me>
  • Loading branch information
karlhorky and JounQin committed Nov 27, 2023
1 parent a5f1aae commit ac2b2fb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-mayflies-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"prettier-plugin-sql": minor
---

feat: upgrade to sql-formatter v14, remove `tabulateAlias` and `commaPosition` options
3 changes: 1 addition & 2 deletions packages/sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ interface SqlOptions {
| 'trino'
// default `sql`
keywordCase: 'preserve' | 'upper' | 'lower' // default `preserve`
identifierCase: 'preserve' | 'upper' | 'lower' // default `preserve`, experimental
indentStyle: 'standard' | 'tabularLeft' | 'tabularRight' // default `standard`
logicalOperatorNewline: 'before' | 'after' // default `before`
tabulateAlias: boolean // default `false`
commaPosition: 'after' | 'before' | 'tabular' // default `after`
expressionWidth: number // default `50`
linesBetweenQueries: number // default `1`
denseOperators: boolean // default `false`
Expand Down
2 changes: 1 addition & 1 deletion packages/sql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"dependencies": {
"jsox": "^1.2.118",
"node-sql-parser": "^4.11.0",
"sql-formatter": "^13.1.0",
"sql-formatter": "^14.0.0",
"tslib": "^2.6.2"
},
"publishConfig": {
Expand Down
65 changes: 30 additions & 35 deletions packages/sql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { JSOX } from 'jsox'
import type { AST, Option } from 'node-sql-parser'
import nodeSqlParser from 'node-sql-parser'
import type { Options, ParserOptions, Plugin } from 'prettier'
import { format, type FormatOptions } from 'sql-formatter'
import { format, type FormatOptionsWithLanguage } from 'sql-formatter'

import { languages } from './languages.js'

Expand All @@ -21,8 +21,7 @@ const ENDINGS = {
} as const

export type SqlBaseOptions = Option &
Partial<FormatOptions> & {
language?: string
Partial<FormatOptionsWithLanguage> & {
formatter?: typeof NODE_SQL_PARSER | typeof SQL_CST | typeof SQL_FORMATTER
params?: string
paramTypes?: string
Expand Down Expand Up @@ -68,11 +67,15 @@ const SqlPlugin: Plugin<AST | string> = {
params:
params == null
? undefined
: (JSOX.parse(params) as FormatOptions['params']),
: (JSOX.parse(
params,
) as FormatOptionsWithLanguage['params']),
paramTypes:
paramTypes == null
? undefined
: (JSOX.parse(paramTypes) as FormatOptions['paramTypes']),
: (JSOX.parse(
paramTypes,
) as FormatOptionsWithLanguage['paramTypes']),
})
: parser.sqlify(value, { type, database })

Expand Down Expand Up @@ -219,6 +222,28 @@ const SqlPlugin: Plugin<AST | string> = {
},
],
},
identifierCase: {
// since: '0.17.0',
category: 'Output',
type: 'choice',
default: 'preserve',
description:
'Converts identifiers to upper- or lowercase for `sql-formatter`. Only unquoted identifiers are converted. (experimental)',
choices: [
{
value: 'preserve',
description: 'preserves the original case',
},
{
value: 'upper',
description: 'converts to uppercase',
},
{
value: 'lower',
description: 'converts to lowercase',
},
],
},
uppercase: {
// since: '0.1.0',
category: 'Output',
Expand Down Expand Up @@ -272,36 +297,6 @@ const SqlPlugin: Plugin<AST | string> = {
},
],
},
tabulateAlias: {
// since: '0.7.0',
category: 'Format',
type: 'boolean',
default: false,
description:
'Aligns column aliases into a single column for `sql-formatter`. Does not effect table name aliases.',
},
commaPosition: {
// since: '0.7.0',
category: 'Format',
type: 'choice',
default: 'after',
description:
'Defines where to place commas in lists of columns for `sql-formatter`',
choices: [
{
value: 'after',
description: 'places comma at the end of line',
},
{
value: 'before',
description: 'places comma at the start of line',
},
{
value: 'tabular',
description: 'aligns commas in a column at the end of line',
},
],
},
expressionWidth: {
// since: '0.7.0',
category: 'Format',
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ac2b2fb

Please sign in to comment.