Skip to content

Commit

Permalink
check triple quotas strings endings
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Sep 30, 2024
1 parent c401728 commit 0ea3904
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
import org.intellij.erlang.psi.ErlangVisitor;
import org.jetbrains.annotations.NotNull;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ErlangTripleQuotasSyntaxInspection extends ErlangInspectionBase {
private static final Pattern PATTERN = Pattern.compile("\\n\\s*\"\"\"$");

@Override
protected @NotNull ErlangVisitor buildErlangVisitor(@NotNull ProblemsHolder holder,
@NotNull LocalInspectionToolSession session) {
Expand All @@ -33,7 +38,15 @@ public void visitStringLiteral(@NotNull ErlangStringLiteral o) {
if (text.startsWith("\"\"\"") && !text.startsWith("\"\"\"\n")) {
holder.registerProblem(o, "Not white space after start of triple-quoted string");
}
if (text.endsWith("\"\"\"") && !endsWithPattern(text)) {
holder.registerProblem(o, "Bad indentation in triple-quoted string");
}
}
};
}

private static boolean endsWithPattern(String tripleQuotedString) {
Matcher matcher = PATTERN.matcher(tripleQuotedString);
return matcher.find();
}
}
6 changes: 5 additions & 1 deletion testData/highlighting/Erlang27SyntaxNoError.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-export([quotes/0, single_line/0]).
-export([quotes/0, single_line/0, bad_indent/0]).

quotes() ->
"""
Expand All @@ -9,3 +9,7 @@ quotes() ->
single_line() ->
<error>"""main"""</error>,
ok.

bad_indent() ->
<error>"""
main"""</error>.

0 comments on commit 0ea3904

Please sign in to comment.