sql-formatter
Advanced tools
Comparing version 12.0.4 to 12.0.5
@@ -26,3 +26,3 @@ import { maxLength } from '../utils.js'; | ||
* ' foo,', | ||
* ' bar,', | ||
* ' bar, --comment', | ||
* ' baz', | ||
@@ -36,3 +36,3 @@ * 'FROM' | ||
* ['SELECT'], | ||
* [' foo,', ' bar,', ' baz'], | ||
* [' foo,', ' bar, --comment', ' baz'], | ||
* ['FROM'] | ||
@@ -50,3 +50,3 @@ * ] | ||
while (lines[i].match(/.*,$/)) { | ||
while (lines[i].match(/.*,(\s*(--.*)?$)/)) { | ||
i++; | ||
@@ -64,4 +64,4 @@ group.push(lines[i]); | ||
function formatTabular(commaLines) { | ||
const maxLineLength = maxLength(commaLines); | ||
return trimTrailingCommas(commaLines).map((line, i) => { | ||
const commaPosition = maxLength(trimTrailingComments(commaLines)) - 1; | ||
return commaLines.map((line, i) => { | ||
if (i === commaLines.length - 1) { | ||
@@ -71,6 +71,12 @@ return line; // do not add comma for last item | ||
return line + ' '.repeat(maxLineLength - line.length - 1) + ','; | ||
return indentComma(line, commaPosition); | ||
}); | ||
} | ||
function indentComma(line, commaPosition) { | ||
const [, code, comment] = line.match(/^(.*?),(\s*--.*)?$/) || []; | ||
const spaces = ' '.repeat(commaPosition - code.length); | ||
return `${code}${spaces},${comment ?? ''}`; | ||
} | ||
function formatBefore(commaLines, indent) { | ||
@@ -93,4 +99,8 @@ return trimTrailingCommas(commaLines).map((line, i) => { | ||
function trimTrailingCommas(lines) { | ||
return lines.map(line => line.replace(/,$/, '')); | ||
return lines.map(line => line.replace(/,(\s*(--.*)?$)/, '$1')); | ||
} | ||
function trimTrailingComments(lines) { | ||
return lines.map(line => line.replace(/\s*--.*/, '')); | ||
} | ||
//# sourceMappingURL=formatCommaPositions.js.map |
{ | ||
"name": "sql-formatter", | ||
"version": "12.0.4", | ||
"version": "12.0.5", | ||
"description": "Format whitespace in a SQL query to make it more readable", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
<a href='https://github.com/sql-formatter-org/sql-formatter'><img src="static/prettier-sql-clean.svg" width="128"/></a> | ||
# SQL Formatter [![NPM version](https://img.shields.io/npm/v/sql-formatter.svg)](https://npmjs.com/package/sql-formatter) ![Build status](https://img.shields.io/github/workflow/status/sql-formatter-org/sql-formatter/coveralls/master?label=Build&logo=Github) [![Coverage Status](https://coveralls.io/repos/github/sql-formatter-org/sql-formatter/badge.svg?branch=master)](https://coveralls.io/github/sql-formatter-org/sql-formatter?branch=master) | ||
# SQL Formatter [![NPM version](https://img.shields.io/npm/v/sql-formatter.svg)](https://npmjs.com/package/sql-formatter) ![Build status](https://img.shields.io/github/actions/workflow/status/sql-formatter-org/sql-formatter/coveralls.yaml) [![Coverage Status](https://coveralls.io/repos/github/sql-formatter-org/sql-formatter/badge.svg?branch=master)](https://coveralls.io/github/sql-formatter-org/sql-formatter?branch=master) | ||
@@ -5,0 +5,0 @@ **SQL Formatter** is a JavaScript library for pretty-printing SQL queries. |
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
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
2150148
8136