Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion sqlcl/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,27 @@ var getCdPath = function (path) {
}
}

var replaceAll = function(input, pattern, replacement) {
var p = javaPattern.compile(pattern);
var m = p.matcher(input);
var result = "";
var pos = 0;
while (m.find()) {
result += input.substring(pos, m.start());
result += replacement;
pos = m.end();
}
if (input.length > pos) {
result += input.substring(pos);
}
return result;
}

var createIgnoreMatcher = function (ignorePath) {
var globPattern = "glob:{"
var lines = javaFiles.readAllLines(javaPaths.get(ignorePath));
for (var i=0; i < lines.size(); i++) {
var line = lines[i].trim();
var line = replaceAll(lines[i].trim(), "(\\\\)", "/");
if (line.length > 0 && line.indexOf('#') === -1) {
if (globPattern.length > 6) {
globPattern += ",";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,20 @@ public void ignore_two_files() throws IOException {
var actual = runCommand( "tvdformat " + tempDir.toString() + " ignore=" + tempDir + File.separator + "ignore.txt");
Assertions.assertTrue(actual.contains("2 of 2"));
}

@Test
public void ignore_two_files_windows_separator() throws IOException {
// must run in an own test class, reason is not clear
var ignoreFileContent = """
# ignore package bodies (single backslash)
**\\*.pkb

# Ignore files with syntax errors (single backslash)
**\\*syntax*
""";
final Path ignoreFile = Paths.get(tempDir + File.separator + "ignore2.txt");
Files.write(ignoreFile, ignoreFileContent.getBytes());
var actual = runCommand( "tvdformat " + tempDir.toString() + " ignore=" + tempDir + File.separator + "ignore2.txt");
Assertions.assertTrue(actual.contains("2 of 2"));
}
}