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 0.0.14 to 0.0.15

4

lib/formatter/ExpressionFormatter.d.ts

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

inline?: boolean;
escapeOperatorSpace?: boolean;
}

@@ -34,3 +35,4 @@ export interface DialectFormatOptions {

private index;
constructor({ cfg, dialectCfg, params, layout, inline }: ExpressionFormatterParams);
private escapeOperatorSpace;
constructor({ cfg, dialectCfg, params, layout, inline, escapeOperatorSpace }: ExpressionFormatterParams);
format(nodes: AstNode[]): Layout;

@@ -37,0 +39,0 @@ private formatNode;

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

index = -1;
escapeOperatorSpace = false;
constructor({

@@ -27,3 +28,4 @@ cfg,

layout,
inline = false
inline = false,
escapeOperatorSpace = false
}) {

@@ -35,2 +37,3 @@ this.cfg = cfg;

this.layout = layout;
this.escapeOperatorSpace = escapeOperatorSpace;
}

@@ -119,3 +122,5 @@ format(nodes) {

// format parenthesis after function name token
this.escapeOperatorSpace = true;
this.formatNode(node.parenthesis);
this.escapeOperatorSpace = false;
}

@@ -173,5 +178,8 @@ formatArraySubscript(node) {

// console.log('case', isTabularStyle(this.cfg));
// TODO 判断node.expr是否存在,不存在时when可以使用tabular风格如Select
// 若存在则保留现有逻辑,换行缩进
if (isTabularStyle(this.cfg)) {
this.escapeOperatorSpace = true;
this.layout.indentation.increaseTabularBlockLevel();

@@ -181,2 +189,3 @@ this.layout = this.formatSubExpression(node.expr); // case后的表达式

this.layout.indentation.decreaseTabularBlockLevel();
this.escapeOperatorSpace = false;
} else {

@@ -188,2 +197,3 @@ this.layout.indentation.increaseBlockLevel();

}
console.log('case', this.layout.getItems());
this.layout.add(WS.NEWLINE, WS.INDENT);

@@ -366,3 +376,4 @@ this.formatNode(node.endKw);

layout: this.layout,
inline: this.inline
inline: this.inline,
escapeOperatorSpace: this.escapeOperatorSpace
}).format(nodes);

@@ -373,3 +384,3 @@ }

try {
// inlinelayou, when longer than the preset size。throw InlineLayoutError
// inlinelayout, when longer than the preset size。throw InlineLayoutError
// 行内模式,expression。inlineLayout内部处理超出配置项后,抛出InlineLayoutError,后继续使用换行模式

@@ -428,4 +439,15 @@ return new ExpressionFormatter({

this.layout.indentation.decreaseTopLevel();
this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node), WS.SPACE);
this.layout.indentation.increaseTopLevel();
// 函数内、casewhen内AND作为普通文本处理,仅处理超长换行的逻辑
if (this.escapeOperatorSpace) {
if (!this.inline) {
// 由formatParenthesis判断是否超长
// newline before AND
this.layout.add(WS.NEWLINE, WS.INDENT, node.text, WS.SPACE);
} else {
this.layout.add(node.text, WS.SPACE);
}
} else {
this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node), WS.SPACE);
this.layout.indentation.increaseTopLevel();
}
} else {

@@ -432,0 +454,0 @@ this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node), WS.SPACE);

{
"name": "bravo-formatter",
"version": "0.0.14",
"version": "0.0.15",
"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

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