Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit c3d2f32

Browse files
Merge pull request #230 from Trivadis/feature/issue-229-supress-syntax-errors
Feature/issue 229 suppress syntax errors
2 parents 67472fb + 2833598 commit c3d2f32

12 files changed

Lines changed: 217 additions & 34 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This repository provides formatter settings for the [coding style rules](https:/
66

77
Settings are primarily provided for
88

9-
- [Oracle SQLcl, Version 22.2.0](https://www.oracle.com/tools/downloads/sqlcl-downloads.html)
9+
- [Oracle SQLcl, Version 22.2.1](https://www.oracle.com/tools/downloads/sqlcl-downloads.html)
1010
- [Oracle SQL Developer, Version 22.2.0](https://www.oracle.com/tools/downloads/sqldev-downloads.html)
1111

1212
These settings have been defined and tested with the product versions mentioned above. They might not work in other versions.

sqlcl/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ We recommend you download, clone, or fork this repository when you plan to use [
2828
However, [`format.js`](format.js) also works as a standalone script. Here's the usage:
2929

3030
```
31-
Trivadis PL/SQL & SQL Formatter (format.js), version 22.2.0
31+
Trivadis PL/SQL & SQL Formatter (format.js), version 22.2.1
3232
3333
usage: script format.js <rootPath> [options]
3434
@@ -48,6 +48,11 @@ options:
4848
ignore=<file> path to the file containing file patterns to ignore. Patterns are defined
4949
per line. Each line represent a glob pattern. Empty lines and lines starting
5050
with a hash sign (#) are ignored.
51+
serr=<scope> scope of syntax errors to be reported. By default all errors are reported.
52+
serr=none reports no syntax errors
53+
serr=all reports all syntax errors
54+
serr=ext reports syntax errors for files defined with ext option
55+
serr=mext reports syntax errors for files defined with mext option
5156
--help, -h, print this help screen and exit
5257
--version, -v print version and exit
5358
--register, -r register SQLcl command tvdformat and exit
@@ -64,7 +69,7 @@ script (...)/plsql-formatter-settings/sqlcl/format.js --register
6469
Afterwards you can type `tvdformat` to get this usage help:
6570

6671
```
67-
Trivadis PL/SQL & SQL Formatter (tvdformat), version 22.2.0
72+
Trivadis PL/SQL & SQL Formatter (tvdformat), version 22.2.1
6873
6974
usage: tvdformat <rootPath> [options]
7075
@@ -84,6 +89,11 @@ options:
8489
ignore=<file> path to the file containing file patterns to ignore. Patterns are defined
8590
per line. Each line represent a glob pattern. Empty lines and lines starting
8691
with a hash sign (#) are ignored.
92+
serr=<scope> scope of syntax errors to be reported. By default all errors are reported.
93+
serr=none reports no syntax errors
94+
serr=all reports all syntax errors
95+
serr=ext reports syntax errors for files defined with ext option
96+
serr=mext reports syntax errors for files defined with mext option
8797
--help, -h, print this help screen and exit
8898
--version, -v print version and exit
8999
```

sqlcl/format.js

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ var printUsage = function (asCommand, standalone) {
229229
ctx.write(" ignore=<file> path to the file containing file patterns to ignore. Patterns are defined\n");
230230
ctx.write(" per line. Each line represent a glob pattern. Empty lines and lines starting\n");
231231
ctx.write(" with a hash sign (#) are ignored.\n");
232+
ctx.write(" serr=<scope> scope of syntax errors to be reported. By default all errors are reported.\n");
233+
ctx.write(" serr=none reports no syntax errors\n");
234+
ctx.write(" serr=all reports all syntax errors\n");
235+
ctx.write(" serr=ext reports syntax errors for files defined with ext option\n");
236+
ctx.write(" serr=mext reports syntax errors for files defined with mext option\n");
232237
ctx.write(" --help, -h, print this help screen and exit\n")
233238
ctx.write(" --version, -v print version and exit\n")
234239
if (!asCommand && !standalone) {
@@ -302,6 +307,7 @@ var processAndValidateArgs = function (args) {
302307
var arboriPath = null;
303308
var ignorePath = null;
304309
var ignoreMatcher = null;
310+
var serr = null;
305311
var files = [];
306312
var result = function (valid) {
307313
return {
@@ -312,6 +318,7 @@ var processAndValidateArgs = function (args) {
312318
xmlPath: xmlPath,
313319
arboriPath: arboriPath,
314320
ignoreMatcher: ignoreMatcher,
321+
serr: serr,
315322
valid: valid
316323
};
317324
}
@@ -371,6 +378,9 @@ var processAndValidateArgs = function (args) {
371378
if (typeof configJson.ignore !== 'undefined') {
372379
ignorePath = configJson.ignore;
373380
}
381+
if (typeof configJson.serr !== 'undefined') {
382+
serr = configJson.serr.toLowerCase();
383+
}
374384
if (typeof configJson.files !== 'undefined') {
375385
if (!Array.isArray(configJson.files)) {
376386
ctx.write("files in " + rootPath + " is not an array.\n\n");
@@ -431,6 +441,10 @@ var processAndValidateArgs = function (args) {
431441
ignorePath = args[i].substring(7);
432442
continue;
433443
}
444+
if (args[i].toLowerCase().indexOf("serr=") === 0) {
445+
serr = args[i].substring(5).toLowerCase();
446+
continue;
447+
}
434448
ctx.write("invalid argument " + args[i] + ".\n\n");
435449
return result(false);
436450
}
@@ -482,6 +496,14 @@ var processAndValidateArgs = function (args) {
482496
}
483497
ignoreMatcher = createIgnoreMatcher(ignorePath);
484498
}
499+
if (serr == null) {
500+
serr = "all";
501+
} else {
502+
if (serr !== "all" && serr !== "none" && serr !== "ext" && serr != "mext") {
503+
ctx.write("invalid scope '" + serr + "' for serr. Valid are: all, none, ext, mext.\n\n");
504+
return result(false);
505+
}
506+
}
485507
return result(true);
486508
}
487509

@@ -511,17 +533,26 @@ var isMarkdownFile = function (file, markdownExtensions) {
511533
return false;
512534
}
513535

514-
var formatMarkdownFile = function (file, formatter) {
536+
var formatMarkdownFile = function (file, formatter, serr) {
515537
var original = readFile(file)
516538
var p = javaPattern.compile("(```\\s*sql\\s*\\n)(.+?)(\\n```)", javaPattern.DOTALL);
517539
var m = p.matcher(original);
518540
var result = "";
519541
var pos = 0;
542+
var consoleOutput = false;
543+
if (serr == "all" || serr == "mext") {
544+
consoleOutput = true;
545+
}
546+
var sqlBlock = 0;
520547
while (m.find()) {
548+
sqlBlock++;
549+
ctx.write("#" + sqlBlock + "... ");
521550
result += original.substring(pos, m.end(1));
522-
if (hasParseErrors(m.group(2), false)) {
551+
if (hasParseErrors(m.group(2), consoleOutput)) {
552+
ctx.write("skipped... ")
523553
result += original.substring(m.start(2), m.end(3));
524554
} else {
555+
ctx.write("done... ")
525556
result += formatter.format(m.group(2));
526557
result += original.substring(m.end(2), m.end(3));
527558
}
@@ -546,24 +577,28 @@ var getLineSeparator = function (input) {
546577
return lineSep;
547578
}
548579

549-
var formatFile = function (file, formatter) {
580+
var formatFile = function (file, formatter, serr) {
550581
var original = readFile(file)
551-
if (hasParseErrors(original, true)) {
582+
var consoleOutput = false;
583+
if (serr == "all" || serr == "ext") {
584+
consoleOutput = true;
585+
}
586+
if (hasParseErrors(original, consoleOutput)) {
552587
ctx.write("skipped.\n");
553588
} else {
554589
writeFile(file, formatter.format(original) + getLineSeparator(original));
555590
ctx.write("done.\n");
556591
}
557592
}
558593

559-
var formatFiles = function (files, formatter, markdownExtensions) {
594+
var formatFiles = function (files, formatter, markdownExtensions, serr) {
560595
for (var i = 0; i < files.length; i++) {
561596
ctx.write("Formatting file " + (i + 1) + " of " + files.length + ": " + files[i].toString() + "... ");
562597
ctx.getOutputStream().flush();
563598
if (isMarkdownFile(files[i], markdownExtensions)) {
564-
formatMarkdownFile(files[i], formatter);
599+
formatMarkdownFile(files[i], formatter, serr);
565600
} else {
566-
formatFile(files[i], formatter);
601+
formatFile(files[i], formatter, serr);
567602
}
568603
ctx.getOutputStream().flush();
569604
}
@@ -617,7 +652,7 @@ var run = function (args) {
617652
} else {
618653
files = getFiles(options.rootPath, options.extensions, options.ignoreMatcher);
619654
}
620-
formatFiles(files, formatter, options.markdownExtensions);
655+
formatFiles(files, formatter, options.markdownExtensions, options.serr);
621656
}
622657
}
623658
}

standalone/install_sqlcl_libs.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ if ! test -f "${SQLCL_LIBDIR}/dbtools-common.jar"; then
1515
fi
1616

1717
# define common Maven properties
18-
SQLCL_VERSION="22.2.0"
18+
SQLCL_VERSION="22.2.1"
1919

2020
# install JAR files in local Maven repository, these libs are not available in public Maven repositories
21-
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=$SQLCL_LIBDIR/dbtools-common.jar
22-
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=$SQLCL_LIBDIR/dbtools-sqlcl.jar
21+
mvn install:install-file -Dfile=$SQLCL_LIBDIR/dbtools-common.jar \
22+
-DgroupId=oracle.dbtools -DartifactId=dbtools-common -Dversion=$SQLCL_VERSION -Dpackaging=jar
23+
mvn install:install-file -Dfile=$SQLCL_LIBDIR/dbtools-sqlcl.jar \
24+
-DgroupId=oracle.dbtools -DartifactId=dbtools-sqlcl -Dversion=$SQLCL_VERSION -Dpackaging=jar
2325
mvn install:install-file -Dfile=$SQLCL_LIBDIR/xmlparserv2_sans_jaxp_services.jar \
2426
-DgroupId=oracle.xml -DartifactId=xmlparserv2-sans-jaxp-services -Dversion=$SQLCL_VERSION -Dpackaging=jar
2527
mvn install:install-file -Dfile=$SQLCL_LIBDIR/orai18n.jar \

standalone/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1313
<jdk.version>11</jdk.version>
1414
<jdk.test.version>17</jdk.test.version>
15-
<sqlcl.version>22.2.0</sqlcl.version>
15+
<sqlcl.version>22.2.1</sqlcl.version>
1616
<graalvm.version>22.2.0</graalvm.version>
1717
<native.maven.plugin.version>0.9.13</native.maven.plugin.version>
1818
<reflections.version>0.10.2</reflections.version>

0 commit comments

Comments
 (0)