Skip to content
Open
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
26 changes: 16 additions & 10 deletions src/validateConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string | undefined> = {
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.` : '')
);
}
}

Expand Down
24 changes: 18 additions & 6 deletions test/sqlFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down