Describe the bug
validateConfig keeps a removedOptions list and throws a ConfigError for the
options dropped in version 10, but the options dropped in version 5 are absent
from it. Passing those has no effect and raises nothing.
const { format } = require('sql-formatter')
format('select 1', { commaPosition: 'before' }) // ConfigError: commaPosition config is no more supported.
format('select 1', { tabulateAlias: true }) // ConfigError: tabulateAlias config is no more supported.
format('select 1', { indent: ' ' }) // no error, option ignored
format('select 1', { uppercase: true }) // no error, option ignored
Expected behavior
indent and uppercase rejected with a ConfigError, the same as the version 10
removals, ideally naming the replacement, for example
indent config is no more supported. Use tabWidth instead.
Actual behavior
Both are silently ignored and formatting proceeds with the defaults, so a config
written against version 4 keeps working while quietly disregarding what it asked
for.
indent and uppercase were among the most used options in version 4, replaced
by tabWidth and keywordCase, which makes this the upgrade path most likely to
be hit. It is what happened to the Trino query editor: its format button passed
uppercase: true and returned lowercase keywords, with nothing in the console to
explain it. The fix on our side is
trinodb/trino-query-ui#78.
TypeScript does catch it when the options are annotated with
FormatOptionsWithLanguage, reporting 'indent' does not exist in type, but not
when they are passed as an unannotated object literal, which is the common shape
in JavaScript and in loosely typed call sites.
Suggested fix
Add the version 5 removals to the existing removedOptions list. Rejecting every
unrecognized key would be more thorough, but it is a larger behavior change that
could break callers passing extra properties. Extending the existing list covers
the upgrade path that actually breaks and reuses the mechanism already there.
I am happy to send a pull request if you agree with the approach.
Usage
- Calling
format(sql, options) from a TypeScript React component, the
Trino query editor.
- Applies to every SQL language, since config validation is language independent.
- Reproduced on 15.6.10 and 15.9.0, on Node 26.
Describe the bug
validateConfigkeeps aremovedOptionslist and throws aConfigErrorfor theoptions dropped in version 10, but the options dropped in version 5 are absent
from it. Passing those has no effect and raises nothing.
Expected behavior
indentanduppercaserejected with aConfigError, the same as the version 10removals, ideally naming the replacement, for example
indent config is no more supported. Use tabWidth instead.Actual behavior
Both are silently ignored and formatting proceeds with the defaults, so a config
written against version 4 keeps working while quietly disregarding what it asked
for.
indentanduppercasewere among the most used options in version 4, replacedby
tabWidthandkeywordCase, which makes this the upgrade path most likely tobe hit. It is what happened to the Trino query editor: its format button passed
uppercase: trueand returned lowercase keywords, with nothing in the console toexplain it. The fix on our side is
trinodb/trino-query-ui#78.
TypeScript does catch it when the options are annotated with
FormatOptionsWithLanguage, reporting'indent' does not exist in type, but notwhen they are passed as an unannotated object literal, which is the common shape
in JavaScript and in loosely typed call sites.
Suggested fix
Add the version 5 removals to the existing
removedOptionslist. Rejecting everyunrecognized key would be more thorough, but it is a larger behavior change that
could break callers passing extra properties. Extending the existing list covers
the upgrade path that actually breaks and reuses the mechanism already there.
I am happy to send a pull request if you agree with the approach.
Usage
format(sql, options)from a TypeScript React component, theTrino query editor.