PY-23970 False positive: "Title length must match the underline" for rst

This commit is contained in:
Ekaterina Tuzova
2017-07-10 13:40:47 +03:00
parent 4df5c1e27f
commit 56ac8e3d15
3 changed files with 19 additions and 3 deletions
@@ -9,7 +9,7 @@ QFIX.ignore.role=Ignore undefined role ''{0}''
### Annotators ###
ANN.unknown.target=Unknown target name ''{0}''
ANN.duplicate.target=Duplicate explicit target name ''{0}''
ANN.title.length=Title length must match the underline
ANN.title.length=Overline length must match the underline
ANN.unusable.anonymous.target=Anonymous hyperlink target has no reference
ANN.inline.block=Blank line is required after a literal block
@@ -66,6 +66,22 @@ public class RestTitle extends RestElement {
return text.substring(start, finish).trim();
}
@Nullable
public String getOverline() {
final String text = getNode().getText().trim();
final Pair<Character, Character> adornments = getAdornments();
final Character overlineChar = adornments.getFirst();
if (overlineChar == null) return null;
int end = 0;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) != overlineChar) {
end = i;
break;
}
}
return text.substring(0, end);
}
@Nullable
public String getUnderline() {
final String text = getNode().getText().trim();
@@ -23,9 +23,9 @@ public class RestTitleAnnotator extends RestAnnotator {
public void visitTitle(final RestTitle node) {
final String name = node.getName();
if (name == null) return;
int nameLen = name.length();
final String underline = node.getUnderline();
if (underline != null && nameLen != underline.length()) {
final String overline = node.getOverline();
if (underline != null && overline != null && overline.length() != underline.length()) {
getHolder().createWarningAnnotation(node, RestBundle.message("ANN.title.length"));
}
}