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

Commit 68831f8

Browse files
Merge pull request #202 from Trivadis/feature/issue-193-os-independent-exclusion-list
Feature/issue 193 os independent exclusion list
2 parents e495d13 + 91d166c commit 68831f8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

sqlcl/format.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,27 @@ var getCdPath = function (path) {
260260
}
261261
}
262262

263+
var replaceAll = function(input, pattern, replacement) {
264+
var p = javaPattern.compile(pattern);
265+
var m = p.matcher(input);
266+
var result = "";
267+
var pos = 0;
268+
while (m.find()) {
269+
result += input.substring(pos, m.start());
270+
result += replacement;
271+
pos = m.end();
272+
}
273+
if (input.length > pos) {
274+
result += input.substring(pos);
275+
}
276+
return result;
277+
}
278+
263279
var createIgnoreMatcher = function (ignorePath) {
264280
var globPattern = "glob:{"
265281
var lines = javaFiles.readAllLines(javaPaths.get(ignorePath));
266282
for (var i=0; i < lines.size(); i++) {
267-
var line = lines[i].trim();
283+
var line = replaceAll(lines[i].trim(), "(\\\\)", "/");
268284
if (line.length > 0 && line.indexOf('#') === -1) {
269285
if (globPattern.length > 6) {
270286
globPattern += ",";

standalone/src/test/java/com/trivadis/plsql/formatter/sqlcl/tests/TvdFormatIgnoreTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,20 @@ public void ignore_two_files() throws IOException {
5252
var actual = runCommand( "tvdformat " + tempDir.toString() + " ignore=" + tempDir + File.separator + "ignore.txt");
5353
Assertions.assertTrue(actual.contains("2 of 2"));
5454
}
55+
56+
@Test
57+
public void ignore_two_files_windows_separator() throws IOException {
58+
// must run in an own test class, reason is not clear
59+
var ignoreFileContent = """
60+
# ignore package bodies (single backslash)
61+
**\\*.pkb
62+
63+
# Ignore files with syntax errors (single backslash)
64+
**\\*syntax*
65+
""";
66+
final Path ignoreFile = Paths.get(tempDir + File.separator + "ignore2.txt");
67+
Files.write(ignoreFile, ignoreFileContent.getBytes());
68+
var actual = runCommand( "tvdformat " + tempDir.toString() + " ignore=" + tempDir + File.separator + "ignore2.txt");
69+
Assertions.assertTrue(actual.contains("2 of 2"));
70+
}
5571
}

0 commit comments

Comments
 (0)