bravo-formatter
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -15,3 +15,3 @@ /** | ||
inline?: boolean; | ||
escapeOperatorSpace?: boolean; | ||
escapeOperatorSpace?: number; | ||
} | ||
@@ -18,0 +18,0 @@ export interface DialectFormatOptions { |
@@ -21,3 +21,3 @@ /** | ||
index = -1; | ||
escapeOperatorSpace = false; | ||
escapeOperatorSpace = 0; | ||
constructor({ | ||
@@ -29,3 +29,3 @@ cfg, | ||
inline = false, | ||
escapeOperatorSpace = false | ||
escapeOperatorSpace = 0 | ||
}) { | ||
@@ -121,5 +121,5 @@ this.cfg = cfg; | ||
// format parenthesis after function name token | ||
this.escapeOperatorSpace = true; | ||
this.escapeOperatorSpace++; | ||
this.formatNode(node.parenthesis); | ||
this.escapeOperatorSpace = false; | ||
this.escapeOperatorSpace--; | ||
} | ||
@@ -180,3 +180,3 @@ formatArraySubscript(node) { | ||
if (isTabularStyle(this.cfg)) { | ||
this.escapeOperatorSpace = true; | ||
this.escapeOperatorSpace++; | ||
this.layout.indentation.increaseTabularBlockLevel(); | ||
@@ -195,3 +195,3 @@ this.layout = this.formatSubExpression(node.expr); // case后的表达式 | ||
!inlineLayout && this.layout.add(WS.NEWLINE, WS.INDENT); | ||
this.escapeOperatorSpace = false; | ||
this.escapeOperatorSpace--; | ||
} else { | ||
@@ -211,5 +211,5 @@ this.layout.indentation.increaseBlockLevel(); | ||
this.formatNode(node.whenKw); | ||
this.escapeOperatorSpace = true; | ||
this.escapeOperatorSpace++; | ||
this.layout = this.formatSubExpression(node.condition); | ||
this.escapeOperatorSpace = false; | ||
this.escapeOperatorSpace--; | ||
this.formatNode(node.thenKw); | ||
@@ -418,3 +418,4 @@ this.layout = this.formatSubExpression(node.result); | ||
layout: new InlineLayout(this.cfg.expressionWidth), | ||
inline: true | ||
inline: true, | ||
escapeOperatorSpace: this.escapeOperatorSpace | ||
}).format(nodes); | ||
@@ -474,9 +475,2 @@ } catch (e) { | ||
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); | ||
@@ -483,0 +477,0 @@ } else { |
@@ -32,3 +32,3 @@ import { maxLength } from '../utils.js'; | ||
line, | ||
matches: line.match(/(^.*?\S) (AS )?(\S+,?$)/i) | ||
matches: line.match(/(^.*?\S) (AS )?([\w$]+,?$)/i) | ||
})).map(({ | ||
@@ -35,0 +35,0 @@ line, |
@@ -35,9 +35,2 @@ 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)); | ||
@@ -44,0 +37,0 @@ } |
@@ -27,3 +27,3 @@ import nearley from 'nearley'; | ||
} = parser.feed(sql); | ||
// console.log('results', results); | ||
// console.log('results', JSON.stringify(results)); | ||
@@ -30,0 +30,0 @@ if (results.length === 1) { |
{ | ||
"name": "bravo-formatter", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2374500
9723