Socket
Socket
Sign inDemoInstall

bravo-formatter

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bravo-formatter - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

3

lib/dialect.js

@@ -37,4 +37,5 @@ /**

alwaysDenseOperators: options.alwaysDenseOperators || [],
onelineClauses: Object.fromEntries(options.onelineClauses.map(name => [name, true]))
onelineClauses: Object.fromEntries(options.onelineClauses.map(name => [name, true])),
preserveClauses: Object.fromEntries((options.preserveClauses ?? []).map(name => [name, true]))
});
//# sourceMappingURL=dialect.js.map

@@ -21,2 +21,3 @@ import { ParamItems } from './formatter/Params.js';

forceNewlineCaseWhen: boolean;
newlineBeforeSet: boolean;
/**

@@ -23,0 +24,0 @@ * 特殊符号定义,如@{XXX} 将被识别为普通文本

@@ -20,2 +20,3 @@ /**

onelineClauses: string[];
preserveClauses?: string[];
}

@@ -25,2 +26,3 @@ export interface ProcessedDialectFormatOptions {

onelineClauses: Record<string, boolean>;
preserveClauses: Record<string, boolean>;
}

@@ -51,4 +53,6 @@ /** Formats a generic SQL expression */

private isOnelineClause;
private isPreserveClause;
private formatClauseInIndentedStyle;
private formatClauseInOnelineStyle;
private formatClauseInPreserveStyle;
private formatClauseInTabularStyle;

@@ -55,0 +59,0 @@ private formatSetOperation;

@@ -220,3 +220,5 @@ /**

formatClause(node) {
if (this.isOnelineClause(node)) {
if (this.isPreserveClause(node)) {
this.formatClauseInPreserveStyle(node);
} else if (this.isOnelineClause(node)) {
this.formatClauseInOnelineStyle(node);

@@ -232,2 +234,5 @@ } else if (isTabularStyle(this.cfg)) {

}
isPreserveClause(node) {
return this.dialectCfg.preserveClauses[node.nameKw.text];
}
formatClauseInIndentedStyle(node) {

@@ -244,2 +249,7 @@ this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node.nameKw), WS.NEWLINE);

}
formatClauseInPreserveStyle(node) {
// preserve clause不处理。保留原来的大小写
this.layout.add(WS.NEWLINE, WS.INDENT, node.nameKw.raw, WS.SPACE);
this.layout = this.formatSubExpression(node.children);
}
formatClauseInTabularStyle(node) {

@@ -246,0 +256,0 @@ this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node.nameKw), WS.SPACE);

@@ -35,2 +35,9 @@ import { indentString } from './config.js';

formatAst(statements) {
// return statements.reduce((sum, stat, i) => {
// const sql = this.formatStatement(stat); // 格式化SQL
// const escapeStas = /^set/i.test(sql) || i === 0; // set语句,不需要添加额外空行。TODO 可以增加配置项 DML均可以配置
// const lines = escapeStas ? '\n' : '\n'.repeat(this.cfg.linesBetweenQueries + 1);
// return lines + sum + sql;
// }, '');
return statements.map(stat => this.formatStatement(stat)).join('\n'.repeat(this.cfg.linesBetweenQueries + 1));

@@ -64,2 +71,5 @@ }

}
if (!this.cfg.newlineBeforeSet) {
query = query.replace(/\n+(set)/gi, '\n$1');
}
if (this.cfg.commaPosition === 'before' || this.cfg.commaPosition === 'tabular') {

@@ -66,0 +76,0 @@ query = formatCommaPositions(query, this.cfg.commaPosition, indentString(this.cfg));

@@ -18,4 +18,2 @@ import { expandPhrases } from '../../expandPhrases.js';

'INSERT INTO [TABLE] [FUNCTION]',
// - update:
'SET', 'SET [DEFAULT] ROLE',
// Data definition

@@ -39,3 +37,3 @@ 'CREATE DATABASE', 'CREATE [OR REPLACE | LIVE | WINDOW] VIEW [IF NOT EXISTS]', 'REPLACE TABLE', 'CREATE [OR REPLACE] TABLE [IF NOT EXISTS]', 'CREATE [OR REPLACE] DICTIONARY [IF NOT EXISTS]']);

// other
'ALTER', 'CREATE', '{DESCRIBE | DESC}', 'DROP', 'SHOW', 'PARTITIONED [BY]', 'TBLPROPERTIES'
'ALTER', 'CREATE', '{DESCRIBE | DESC}', 'DROP', 'PARTITIONED [BY]', 'TBLPROPERTIES'
// 'ENGINE',

@@ -45,2 +43,5 @@ // 'FORMAT'

const preserveClauses = expandPhrases([
// - update:
'SET', 'SET [DEFAULT] ROLE', 'SHOW']);
const reservedSetOperations = expandPhrases(['UNION [ALL | DISTINCT]', 'EXCEPT', 'INTERSECT', 'INTO OUTFILE']);

@@ -64,3 +65,3 @@

reservedSelect,
reservedClauses: [...reservedClauses, ...onelineClauses],
reservedClauses: [...reservedClauses, ...onelineClauses, ...preserveClauses],
reservedSetOperations,

@@ -85,5 +86,6 @@ reservedJoins,

formatOptions: {
onelineClauses
onelineClauses,
preserveClauses
}
};
//# sourceMappingURL=clickhouse.formatter.js.map

@@ -12,3 +12,3 @@ import { expandPhrases } from '../../expandPhrases.js';

// 'WITH', 对齐dorado,暂时移除
'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'WINDOW', 'PARTITION BY', 'ORDER BY', 'SORT BY', 'CLUSTER BY', 'DISTRIBUTE BY', 'LIMIT', 'SET',
'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'WINDOW', 'PARTITION BY', 'ORDER BY', 'SORT BY', 'CLUSTER BY', 'DISTRIBUTE BY', 'LIMIT',
// Data manipulation

@@ -43,3 +43,6 @@ // - insert:

// other
'ALTER', 'CREATE', 'DESCRIBE', 'DROP', 'FETCH', 'SHOW', 'STORED AS', 'STORED BY', 'ROW FORMAT', 'TBLPROPERTIES']);
'ALTER', 'CREATE', 'DESCRIBE', 'DROP', 'FETCH', 'STORED AS', 'STORED BY', 'ROW FORMAT', 'TBLPROPERTIES']);
const preserveClauses = expandPhrases([
// set
'SET', 'SHOW']);
const reservedSetOperations = expandPhrases(['UNION [ALL | DISTINCT]']);

@@ -57,3 +60,3 @@

reservedSelect,
reservedClauses: [...reservedClauses, ...onelineClauses],
reservedClauses: [...reservedClauses, ...onelineClauses, ...preserveClauses],
reservedSetOperations,

@@ -75,5 +78,6 @@ reservedJoins,

formatOptions: {
onelineClauses
onelineClauses,
preserveClauses
}
};
//# sourceMappingURL=hive.formatter.js.map

@@ -555,2 +555,5 @@ // Generated automatically by nearley, version 2.20.1

}, {
"name": "property_access$subexpression$1",
"symbols": ["parameter"]
}, {
"name": "property_access",

@@ -557,0 +560,0 @@ "symbols": ["expression", "_", lexer.has("DOT") ? {

@@ -40,3 +40,4 @@ import * as allDialects from './allDialects.js';

functionCase: 'preserve',
forceNewlineCaseWhen: true
forceNewlineCaseWhen: true,
newlineBeforeSet: false
};

@@ -43,0 +44,0 @@

{
"name": "bravo-formatter",
"version": "1.0.4",
"version": "1.0.5",
"description": "Format whitespace in a SQL query to make it more readable",

@@ -5,0 +5,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc