Skip to content

Commit

Permalink
Fix error message (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
takahi-i authored Oct 11, 2017
1 parent 85c0282 commit 66a2726
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cc.redpen.RedPenException;
import cc.redpen.model.Paragraph;
import cc.redpen.model.Section;
import cc.redpen.model.Sentence;
import cc.redpen.validator.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -31,19 +32,17 @@ public class EmptySectionValidator extends Validator {

@Override
public void validate(Section section) {
if (section.getLevel() >= sectionLevelLimit) {
if (0 == section.getLevel() || section.getLevel() >= sectionLevelLimit) {
return;
}

if (section.getLevel() == 0) {
return; // hot fix for auto generated level 0 sections.
}
Sentence header = section.getJoinedHeaderContents();
if (section.getNumberOfParagraphs() == 0) {
addLocalizedError(section.getJoinedHeaderContents());
addLocalizedError(header, header.getContent());
} else {
for (Paragraph p : section.getParagraphs()) {
if (p.getNumberOfSentences() == 0) {
addLocalizedError(section.getJoinedHeaderContents());
addLocalizedError(header, header.getContent());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import cc.redpen.RedPenException;
import cc.redpen.model.Paragraph;
import cc.redpen.model.Section;
import cc.redpen.model.Sentence;
import cc.redpen.validator.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -36,19 +37,17 @@ final public class VoidSectionValidator extends Validator {

@Override
public void validate(Section section) {
if (section.getLevel() >= sectionLevelLimit) {
if (0 == section.getLevel() || section.getLevel() >= sectionLevelLimit) {
return;
}

if (section.getLevel() == 0) {
return; // hot fix for auto generated level 0 sections.
}
Sentence header = section.getJoinedHeaderContents();
if (section.getNumberOfParagraphs() == 0) {
addLocalizedError(section.getJoinedHeaderContents());
addLocalizedError(header, header.getContent());
} else {
for (Paragraph p : section.getParagraphs()) {
if (p.getNumberOfSentences() == 0) {
addLocalizedError(section.getJoinedHeaderContents());
addLocalizedError(header, header.getContent());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ void testInvalid() {
List<ValidationError> errors = new ArrayList<>();
validator.setErrorList(errors);
validator.validate(document.getSection(0));

assertEquals(1, errors.size());
}

Expand Down

0 comments on commit 66a2726

Please sign in to comment.