prettier-plugin-sql-cst 0.12.3 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/options.d.ts CHANGED
@@ -4,6 +4,7 @@ export interface SqlPluginOptions {
4
4
  sqlKeywordCase: "preserve" | "upper" | "lower";
5
5
  sqlParamTypes: NonNullable<CstParserOptions["paramTypes"]>;
6
6
  sqlCanonicalSyntax: boolean;
7
+ sqlFinalSemicolon: boolean;
7
8
  sqlAcceptUnsupportedGrammar: boolean;
8
9
  }
9
10
  export type AllPrettierOptions<T = Node> = ParserOptions<T> & SqlPluginOptions;
package/dist/options.js CHANGED
@@ -41,6 +41,13 @@ exports.options = {
41
41
  description: "Enforces one true style of SQL syntax (adds and removes keywords)",
42
42
  // Since 0.11.0
43
43
  },
44
+ sqlFinalSemicolon: {
45
+ type: "boolean",
46
+ category: "SQL",
47
+ default: true,
48
+ description: "Enforces a semicolon at the end of last SQL statement",
49
+ // Since 0.13.0
50
+ },
44
51
  sqlAcceptUnsupportedGrammar: {
45
52
  type: "boolean",
46
53
  category: "SQL",
@@ -45,7 +45,9 @@ exports.exprMap = {
45
45
  return print("expr");
46
46
  }
47
47
  var parent = path.getParentNode();
48
- var lineStyle = (0, node_utils_1.isCreateTableStmt)(parent) ? print_utils_1.hardline : print_utils_1.softline;
48
+ var lineStyle = (0, node_utils_1.isCreateTableStmt)(parent) && print.dynamicLine() === print_utils_1.hardline
49
+ ? print_utils_1.hardline
50
+ : print_utils_1.softline;
49
51
  return (0, print_utils_1.group)(["(", (0, print_utils_1.indent)([lineStyle, print("expr")]), lineStyle, ")"]);
50
52
  },
51
53
  binary_expr: function (print, node) {
@@ -5,7 +5,9 @@ var print_utils_1 = require("../print_utils");
5
5
  exports.programMap = {
6
6
  program: function (print, node, path, options) {
7
7
  return print("statements").map(function (doc, i) {
8
- return printStatement(doc, i, node.statements, options);
8
+ return i === node.statements.length - 1
9
+ ? printFinalStatement(doc, i, node.statements, options)
10
+ : printStatement(doc, i, node.statements, options);
9
11
  });
10
12
  },
11
13
  };
@@ -27,3 +29,18 @@ var printStatement = function (doc, i, statements, options) {
27
29
  return [";", print_utils_1.hardline, doc];
28
30
  }
29
31
  };
32
+ var printFinalStatement = function (doc, i, statements, options) {
33
+ var stmtDoc = printStatement(doc, i, statements, options);
34
+ if (statements[i].type === "empty") {
35
+ // When the final statement is an empty statement,
36
+ // this means we have inserted a semicolon and newline before it.
37
+ // So nothing else is needed.
38
+ return stmtDoc;
39
+ }
40
+ else {
41
+ // If the last statement is not empty,
42
+ // this means sqlFinalSemicolon option is false,
43
+ // so we need to add an empty line after it.
44
+ return [stmtDoc, print_utils_1.hardline];
45
+ }
46
+ };
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sequenceMap = void 0;
4
4
  var print_utils_1 = require("../print_utils");
5
5
  exports.sequenceMap = {
6
- create_sequence_stmt: function (print) {
6
+ create_sequence_stmt: function (print, node) {
7
7
  return (0, print_utils_1.group)([
8
8
  print.spaced(["createKw", "kind", "sequenceKw", "ifNotExistsKw", "name"]),
9
- (0, print_utils_1.indent)([print.dynamicLine(), (0, print_utils_1.join)(print_utils_1.line, print("options"))]),
9
+ node.options.length > 0
10
+ ? (0, print_utils_1.indent)([print.dynamicLine(), (0, print_utils_1.join)(print_utils_1.line, print("options"))])
11
+ : [],
10
12
  ]);
11
13
  },
12
14
  alter_sequence_stmt: function (print) {
@@ -13,8 +13,10 @@ var transformCst = function (cst, originalText, options) {
13
13
  // so we don't need to worry about comments interfering with other transforms
14
14
  comments_1.moveCommentsToRoot,
15
15
  stripTrailingCommas_1.stripTrailingCommas,
16
- addFinalSemicolon_1.addFinalSemicolon,
17
16
  ];
17
+ if (options.sqlFinalSemicolon) {
18
+ transforms.push(addFinalSemicolon_1.addFinalSemicolon);
19
+ }
18
20
  if (options.sqlCanonicalSyntax) {
19
21
  transforms.push(aliasAs_1.processAliasAs, canonicOperators_1.canonicOperators, canonicKeywords_1.canonicKeywords);
20
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-sql-cst",
3
- "version": "0.12.3",
3
+ "version": "0.13.0",
4
4
  "description": "Prettier plugin for SQL",
5
5
  "contributors": [
6
6
  "Barna Magyarkuti <bmagyarkuti@gmail.com>",
@@ -37,7 +37,7 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "prettier": "^3.0.3",
40
- "sql-parser-cst": "^0.33.0"
40
+ "sql-parser-cst": "^0.33.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/jest": "^29.2.5",