Socket
Socket
Sign inDemoInstall

@sqltools/formatter

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 1.2.1

lib/core/escapeRegExp.js

20

lib/core/Formatter.js

@@ -18,2 +18,3 @@ "use strict";

this.previousReservedWord = { type: null, value: null };
this.previousNonWhiteSpace = { type: null, value: null };
this.index = 0;

@@ -57,2 +58,5 @@ this.indentation = new Indentation_1["default"](this.cfg.indent);

}
else if (token.type === types_1.TokenTypes.NO_SPACE_OPERATOR) {
formattedQuery = _this.formatWithoutSpaces(token, formattedQuery);
}
else if (token.type === types_1.TokenTypes.PLACEHOLDER || token.type === types_1.TokenTypes.SERVERVARIABLE) {

@@ -76,4 +80,4 @@ formattedQuery = _this.formatPlaceholder(token, formattedQuery);

}
if (_this.previousToken().type === types_1.TokenTypes.RESERVED_TOP_LEVEL) {
_this.indentation.increaseTopLevel();
if (token.type !== types_1.TokenTypes.WHITESPACE) {
_this.previousNonWhiteSpace = token;
}

@@ -129,5 +133,11 @@ });

Formatter.prototype.formatTopLevelReservedWord = function (token, query) {
this.indentation.decreaseTopLevel();
query = this.addNewline(query);
return query + this.equalizeWhitespace(this.formatReservedWord(token.value)) + ' ';
var shouldChangeTopLevel = (this.previousNonWhiteSpace.value !== ',' && !['GRANT'].includes(("" + this.previousNonWhiteSpace.value).toUpperCase()));
if (shouldChangeTopLevel) {
this.indentation.decreaseTopLevel();
query = this.addNewline(query);
}
query = query + this.equalizeWhitespace(this.formatReservedWord(token.value)) + ' ';
if (shouldChangeTopLevel)
this.indentation.increaseTopLevel();
return query;
};

@@ -134,0 +144,0 @@ Formatter.prototype.formatNewlineReservedWord = function (token, query) {

@@ -6,4 +6,3 @@ "use strict";

exports.__esModule = true;
var repeat_1 = __importDefault(require("lodash/repeat"));
var last_1 = __importDefault(require("lodash/last"));
var last_1 = __importDefault(require("./last"));
var INDENT_TYPE_TOP_LEVEL = 'top-level';

@@ -18,3 +17,3 @@ var INDENT_TYPE_BLOCK_LEVEL = 'block-level';

Indentation.prototype.getIndent = function () {
return repeat_1["default"](this.indent, this.indentTypes.length);
return new Array(this.indentTypes.length).fill(this.indent).join('');
};

@@ -21,0 +20,0 @@ Indentation.prototype.increaseTopLevel = function () {

@@ -6,4 +6,3 @@ "use strict";

exports.__esModule = true;
var isEmpty_1 = __importDefault(require("lodash/isEmpty"));
var escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
var escapeRegExp_1 = __importDefault(require("../core/escapeRegExp"));
var types_1 = require("./types");

@@ -14,3 +13,5 @@ var Tokenizer = (function () {

this.NUMBER_REGEX = /^((-\s*)?[0-9]+(\.[0-9]+)?|0x[0-9a-fA-F]+|0b[01]+|([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}))\b/u;
this.OPERATOR_REGEX = /^(!=|<>|>>|<<|==|<=|>=|!<|!>|\|\|\/|\|\/|\|\||::|->>|->|~~\*|~~|!~~\*|!~~|~\*|!~\*|!~|:=|&&|@|.)/u;
this.AMBIGUOS_OPERATOR_REGEX = /^(\?\||\?&)/u;
this.OPERATOR_REGEX = /^(!=|<>|>>|<<|==|<=|>=|!<|!>|\|\|\/|\|\/|\|\||~~\*|~~|!~~\*|!~~|~\*|!~\*|!~|:=|&&|@>|<@|#-|@|.)/u;
this.NO_SPACE_OPERATOR_REGEX = /^(::|->>|->|#>>|#>)/u;
this.BLOCK_COMMENT_REGEX = /^(\/\*[^]*?(?:\*\/|$))/u;

@@ -31,3 +32,3 @@ this.LINE_COMMENT_REGEX = this.createLineCommentRegex(cfg.lineCommentTypes);

Tokenizer.prototype.createLineCommentRegex = function (lineCommentTypes) {
return new RegExp("^((?:" + lineCommentTypes.map(function (c) { return escapeRegExp_1["default"](c); }).join('|') + ").*?(?:\r\n|\r|\n|$))", 'u');
return new RegExp("^((?:" + lineCommentTypes.map(function (c) { return escapeRegExp_1["default"](c); }).join('|') + ")[^>]*?(?:\r\n|\r|\n|$))", 'u');
};

@@ -67,3 +68,3 @@ Tokenizer.prototype.createReservedWordRegex = function (reservedWords) {

Tokenizer.prototype.createPlaceholderRegex = function (types, pattern) {
if (isEmpty_1["default"](types)) {
if (!types || types.length === 0) {
return null;

@@ -92,2 +93,4 @@ }

this.getCloseParenToken(input) ||
this.getAmbiguosOperatorToken(input) ||
this.getNoSpaceOperatorToken(input) ||
this.getServerVariableToken(input) ||

@@ -205,2 +208,16 @@ this.getPlaceholderToken(input) ||

};
Tokenizer.prototype.getAmbiguosOperatorToken = function (input) {
return this.getTokenOnFirstMatch({
input: input,
type: types_1.TokenTypes.OPERATOR,
regex: this.AMBIGUOS_OPERATOR_REGEX
});
};
Tokenizer.prototype.getNoSpaceOperatorToken = function (input) {
return this.getTokenOnFirstMatch({
input: input,
type: types_1.TokenTypes.NO_SPACE_OPERATOR,
regex: this.NO_SPACE_OPERATOR_REGEX
});
};
Tokenizer.prototype.getReservedWordToken = function (input, previousToken) {

@@ -207,0 +224,0 @@ if (previousToken && previousToken.value && previousToken.value === '.') {

"use strict";
exports.__esModule = true;
exports.TokenTypes = void 0;
var TokenTypes;

@@ -13,2 +14,3 @@ (function (TokenTypes) {

TokenTypes["OPERATOR"] = "operator";
TokenTypes["NO_SPACE_OPERATOR"] = "no-space-operator";
TokenTypes["OPEN_PAREN"] = "open-paren";

@@ -15,0 +17,0 @@ TokenTypes["CLOSE_PAREN"] = "close-paren";

@@ -135,3 +135,2 @@ "use strict";

'GLOBAL',
'GRANT',
'GRANTS',

@@ -299,2 +298,3 @@ 'GROUP_CONCAT',

'TRANSACTIONAL',
'TRIGGER',
'TRUE',

@@ -325,2 +325,3 @@ 'TRUNCATE',

'CREATE OR REPLACE',
'DECLARE',
'DELETE FROM',

@@ -331,2 +332,3 @@ 'EXCEPT',

'GO',
'GRANT',
'GROUP BY',

@@ -333,0 +335,0 @@ 'HAVING',

@@ -6,2 +6,3 @@ "use strict";

exports.__esModule = true;
exports.tokenize = exports.format = void 0;
var Db2Formatter_1 = __importDefault(require("./languages/Db2Formatter"));

@@ -8,0 +9,0 @@ var N1qlFormatter_1 = __importDefault(require("./languages/N1qlFormatter"));

{
"name": "@sqltools/formatter",
"version": "1.2.0",
"version": "1.2.1",
"description": "Formats SQL queries. Part of SQLTools",

@@ -33,3 +33,6 @@ "license": "MIT",

"compile": "./node_modules/.bin/tsc -p tsconfig.json",
"build": "yarn run compile"
"build": "yarn run compile",
"prepare": "yarn run build",
"prepack": "yarn run build",
"release": "npm pack && npm publish *.tgz --latest"
},

@@ -42,11 +45,7 @@ "repository": {

"bugs": {
"url": "https://github.com/mtxr/sqltools-formatter/issues"
"url": "https://github.com/mtxr/vscode-sqltools/labels/formatting"
},
"dependencies": {
"lodash": "^4.17.11"
},
"devDependencies": {
"@types/jest": "^24.0.11",
"dedent-js": "^1.0.1",
"husky": "^3.0.3",
"jest": "^24.7.0",

@@ -57,8 +56,3 @@ "jest-cli": "^24.7.0",

"typescript": "^3.4.1"
},
"husky": {
"hooks": {
"pre-commit": "yarn test"
}
}
}
# SQLTools Formatter
[![Build Status](https://github.com/mtxr/vscode-sqltools/workflows/Formatter%20Test%20&%20Build/badge.svg)](https://github.com/mtxr/vscode-sqltools/actions)
[![codecov](https://img.shields.io/codecov/c/gh/mtxr/sqltools-formatter.svg)](https://codecov.io/gh/mtxr/sqltools-formatter)
[![NPM version](https://img.shields.io/npm/v/@sqltools/formatter.svg)](https://npmjs.com/package/@sqltools/formatter)
[![GitHub](https://img.shields.io/github/license/mtxr/vscode-sqltools)](https://github.com/mtxr/vscode-sqltools/blob/master/LICENSE)

@@ -12,1 +9,11 @@

This package is part of [vscode-sqltools](https://github.com/mtxr/vscode-sqltools) extension.
## Changelog
#### v1.2.1
- Fixes JSON operators not inserting spaces. Issue [#605](https://github.com/mtxr/vscode-sqltools/issues/605)
- Fixes Grant type queries. Issue [#460](https://github.com/mtxr/vscode-sqltools/issues/460)
#### v1.2.1
- (Almost) first public version

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc