diff --git a/src/validateConfig.ts b/src/validateConfig.ts index 8789fe63d7..ac21e91413 100644 --- a/src/validateConfig.ts +++ b/src/validateConfig.ts @@ -5,17 +5,23 @@ import { ParamTypes } from './lexer/TokenizerOptions.js'; export class ConfigError extends Error {} export function validateConfig(cfg: FormatOptions): FormatOptions { - const removedOptions = [ - 'multilineLists', - 'newlineBeforeOpenParen', - 'newlineBeforeCloseParen', - 'aliasAs', - 'commaPosition', - 'tabulateAlias', - ]; - for (const optionName of removedOptions) { + // Options removed in past major versions, mapped to their replacement when one exists. + const removedOptions: Record = { + indent: 'tabWidth', + uppercase: 'keywordCase', + multilineLists: undefined, + newlineBeforeOpenParen: undefined, + newlineBeforeCloseParen: undefined, + aliasAs: undefined, + commaPosition: undefined, + tabulateAlias: undefined, + }; + for (const [optionName, replacement] of Object.entries(removedOptions)) { if (optionName in cfg) { - throw new ConfigError(`${optionName} config is no more supported.`); + throw new ConfigError( + `${optionName} config is no longer supported.` + + (replacement ? ` Use ${replacement} instead.` : '') + ); } } diff --git a/test/sqlFormatter.test.ts b/test/sqlFormatter.test.ts index 87e9cca082..ed223fa1cc 100644 --- a/test/sqlFormatter.test.ts +++ b/test/sqlFormatter.test.ts @@ -47,40 +47,52 @@ describe('sqlFormatter', () => { ); }); + it('throws error when indent config option used', () => { + expect(() => { + format('SELECT *', { indent: ' ' } as any); + }).toThrow('indent config is no longer supported. Use tabWidth instead.'); + }); + + it('throws error when uppercase config option used', () => { + expect(() => { + format('SELECT *', { uppercase: true } as any); + }).toThrow('uppercase config is no longer supported. Use keywordCase instead.'); + }); + it('throws error when multilineLists config option used', () => { expect(() => { format('SELECT *', { multilineLists: 'always' } as any); - }).toThrow('multilineLists config is no more supported.'); + }).toThrow('multilineLists config is no longer supported.'); }); it('throws error when newlineBeforeOpenParen config option used', () => { expect(() => { format('SELECT *', { newlineBeforeOpenParen: true } as any); - }).toThrow('newlineBeforeOpenParen config is no more supported.'); + }).toThrow('newlineBeforeOpenParen config is no longer supported.'); }); it('throws error when newlineBeforeCloseParen config option used', () => { expect(() => { format('SELECT *', { newlineBeforeCloseParen: true } as any); - }).toThrow('newlineBeforeCloseParen config is no more supported.'); + }).toThrow('newlineBeforeCloseParen config is no longer supported.'); }); it('throws error when aliasAs config option used', () => { expect(() => { format('SELECT *', { aliasAs: 'always' } as any); - }).toThrow('aliasAs config is no more supported.'); + }).toThrow('aliasAs config is no longer supported.'); }); it('throws error when tabulateAlias config option used', () => { expect(() => { format('SELECT *', { tabulateAlias: false } as any); - }).toThrow('tabulateAlias config is no more supported.'); + }).toThrow('tabulateAlias config is no longer supported.'); }); it('throws error when commaPosition config option used', () => { expect(() => { format('SELECT *', { commaPosition: 'before' } as any); - }).toThrow('commaPosition config is no more supported.'); + }).toThrow('commaPosition config is no longer supported.'); }); describe('formatDialect()', () => {