Skip to content

Commit

Permalink
Throw error when commaPosition or tabulateAlias option used
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Nov 13, 2023
1 parent dc8c551 commit 6a7d080
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 394 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ All fields are optional and all fields that are not specified will be filled wit
- [**`identifierCase`**](docs/identifierCase.md) uppercases or lowercases identifiers. (**experimental!**)
- [**`indentStyle`**](docs/indentStyle.md) defines overall indentation style.
- [**`logicalOperatorNewline`**](docs/logicalOperatorNewline.md) newline before or after boolean operator (AND, OR, XOR).
- [**`commaPosition`**](docs/commaPosition.md) where to place the comma in column lists (**deprecated!**).
- [**`expressionWidth`**](docs/expressionWidth.md) maximum number of characters in parenthesized expressions to be kept on single line.
- [**`linesBetweenQueries`**](docs/linesBetweenQueries.md) how many newlines to insert between queries.
- [**`denseOperators`**](docs/denseOperators.md) packs operators densely without spaces.
Expand Down
66 changes: 0 additions & 66 deletions docs/commaPosition.md

This file was deleted.

3 changes: 0 additions & 3 deletions src/FormatOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export type KeywordCase = 'preserve' | 'upper' | 'lower';

export type IdentifierCase = 'preserve' | 'upper' | 'lower';

export type CommaPosition = 'before' | 'after' | 'tabular';

export type LogicalOperatorNewline = 'before' | 'after';

export interface FormatOptions {
Expand All @@ -19,7 +17,6 @@ export interface FormatOptions {
identifierCase: IdentifierCase;
indentStyle: IndentStyle;
logicalOperatorNewline: LogicalOperatorNewline;
commaPosition: CommaPosition;
expressionWidth: number;
linesBetweenQueries: number;
denseOperators: boolean;
Expand Down
13 changes: 1 addition & 12 deletions src/formatter/Formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { createParser } from '../parser/createParser.js';
import { StatementNode } from '../parser/ast.js';
import { Dialect } from '../dialect.js';

import formatCommaPositions from './formatCommaPositions.js';
import ExpressionFormatter from './ExpressionFormatter.js';
import Layout, { WS } from './Layout.js';
import Indentation from './Indentation.js';
Expand All @@ -31,9 +30,7 @@ export default class Formatter {
public format(query: string): string {
const ast = this.parse(query);
const formattedQuery = this.formatAst(ast);
const finalQuery = this.postFormat(formattedQuery);

return finalQuery.trimEnd();
return formattedQuery.trimEnd();
}

private parse(query: string): StatementNode[] {
Expand Down Expand Up @@ -63,12 +60,4 @@ export default class Formatter {
}
return layout.toString();
}

private postFormat(query: string): string {
if (this.cfg.commaPosition === 'before' || this.cfg.commaPosition === 'tabular') {
query = formatCommaPositions(query, this.cfg.commaPosition, indentString(this.cfg));
}

return query;
}
}
106 changes: 0 additions & 106 deletions src/formatter/formatCommaPositions.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export type {
IndentStyle,
KeywordCase,
IdentifierCase,
CommaPosition,
LogicalOperatorNewline,
FormatOptions,
} from './FormatOptions.js';
Expand Down
1 change: 0 additions & 1 deletion src/sqlFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const defaultOptions: FormatOptions = {
identifierCase: 'preserve',
indentStyle: 'standard',
logicalOperatorNewline: 'before',
commaPosition: 'after',
expressionWidth: 50,
linesBetweenQueries: 1,
denseOperators: false,
Expand Down
12 changes: 6 additions & 6 deletions src/validateConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ export function validateConfig(cfg: FormatOptions): FormatOptions {
if ('aliasAs' in cfg) {
throw new ConfigError('aliasAs config is no more supported.');
}
if ('commaPosition' in cfg) {
throw new ConfigError('commaPosition config is no more supported.');
}
if ('tabulateAlias' in cfg) {
throw new ConfigError('tabulateAlias config is no more supported.');
}

if (cfg.expressionWidth <= 0) {
throw new ConfigError(
`expressionWidth config must be positive number. Received ${cfg.expressionWidth} instead.`
);
}

if (cfg.commaPosition === 'before' && cfg.useTabs) {
throw new ConfigError(
'commaPosition: before does not work when tabs are used for indentation.'
);
}

if (cfg.params && !validateParams(cfg.params)) {
// eslint-disable-next-line no-console
console.warn('WARNING: All "params" option values should be strings.');
Expand Down
8 changes: 0 additions & 8 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ <h3 style="margin: 0.5rem 0">Options</h3>
<option value="after">after</option>
</select>
</article>
<article class="config">
<label for="commaPosition">Comma position:</label>
<select id="commaPosition">
<option value="after">After</option>
<option value="before">Before</option>
<option value="tabular">Tabular</option>
</select>
</article>
<article class="config">
<label for="expressionWidth">Expression width:</label>
<input
Expand Down
3 changes: 0 additions & 3 deletions static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const attachFormat = () => {
const keywordCase = document.getElementById('keywordCase');
const indentStyle = document.getElementById('indentStyle');
const logicalOperatorNewline = document.getElementById('logicalOperatorNewline');
const commaPosition = document.getElementById('commaPosition');
const expressionWidth = document.getElementById('expressionWidth');
const lineBetweenQueries = document.getElementById('lineBetweenQueries');
const denseOperators = document.getElementById('denseOperators');
Expand Down Expand Up @@ -37,7 +36,6 @@ const attachFormat = () => {
indentStyle: indentStyle.options[indentStyle.selectedIndex].value,
logicalOperatorNewline:
logicalOperatorNewline.options[logicalOperatorNewline.selectedIndex].value,
commaPosition: commaPosition.options[commaPosition.selectedIndex].value,
expressionWidth: expressionWidth.value,
lineBetweenQueries: lineBetweenQueries.value,
denseOperators: denseOperators.checked,
Expand Down Expand Up @@ -72,7 +70,6 @@ const attachFormat = () => {
keywordCase,
indentStyle,
logicalOperatorNewline,
commaPosition,
expressionWidth,
lineBetweenQueries,
denseOperators,
Expand Down
2 changes: 0 additions & 2 deletions test/behavesLikeSqlFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import supportsExpressionWidth from './options/expressionWidth.js';
import supportsKeywordCase from './options/keywordCase.js';
import supportsIdentifierCase from './options/identifierCase.js';
import supportsIndentStyle from './options/indentStyle.js';
import supportsCommaPosition from './options/commaPosition.js';
import supportsLinesBetweenQueries from './options/linesBetweenQueries.js';
import supportsNewlineBeforeSemicolon from './options/newlineBeforeSemicolon.js';
import supportsLogicalOperatorNewline from './options/logicalOperatorNewline.js';
Expand All @@ -34,7 +33,6 @@ export default function behavesLikeSqlFormatter(format: FormatFn) {
supportsLinesBetweenQueries(format);
supportsExpressionWidth(format);
supportsNewlineBeforeSemicolon(format);
supportsCommaPosition(format);
supportsLogicalOperatorNewline(format);
supportsParamTypes(format);
supportsWindowFunctions(format);
Expand Down
Loading

0 comments on commit 6a7d080

Please sign in to comment.